Array

Functions for dealing with arrays.

BitFirstSet
Returns the index of the first bit set to true in a bitarray.
BitHasSet
Returns true if any bit in a bitarray is set, otherwise false.
BitNumberSet
Returns the number of bits set to true in a bitarray.
DeleteItems
Delete items in an array that are tagged via a passed bitarray.
InsertAfter
Insert an item into an array, after a given index.
ItemFound
Check if passed item is in passed array.
GetArrayValue
Get an interpolated value from an array.
GetNormArrayValue
Get an interpolated value from an array using a normalize 0 to 1 index.
MaxValueIndex
Return the index of the largest value in the array.
MinValueIndex
Return the index of the smallest value in the array.
ReverseArray
Reverse the order of items in array.
ScaleArray
Scale an array to a new size, with interpolated values.
ScrambleArray
Scrambles the order of items in an array.
TrimDuplicates
Trims an array down so that it holds only one reference to each item.

BitFirstSet:

Returns the index of the first bit set to true in a bitarray.

Returns:

The integer index of the first bit set to true in a bitarray, or 0 if no bits are set.

Arguments:
<aBitArray>
The bitarray to check.

Back to top...


BitHasSet:

Returns true if any bit in a bitarray is set, otherwise false.

Returns:

Returns true if any bit in a bitarray is set, otherwise false.

Arguments:
<aBitArray>
A bitarray.

Back to top...


BitNumberSet:

Returns the number of bits set to true in a bitarray.

Returns:

The number of bits set to true in a bitarray.

Arguments:
<aBitArray>
The bitarray to count.

Back to top...


DeleteItems:

Delete items in an array that are tagged via a passed bitarray.
Note: the bitarray and array must be the same size.

Returns:

True on success, false on failure.

Arguments:
%<anArray>
The array to delete items from
<aBitArray>
Each index in anArray will be deleted where the corresponding index in this bitarray is true.

Back to top...


InsertAfter:

Insert an item into an array, after a given index.

Returns:

True on success, false on failure.

Arguments:
%<anArray>
The array to insert an item into
<item>
The item to insert into the array
<index>
The item will be inserted into the array after this index

Back to top...


ItemFound:

Check if passed item is in passed array.
Shortcut to/clearer than typing ((FindItem anArray anItem) != 0)

Returns:

True if item is in the array, otherwise false.

Arguments:
<anArray>
The array to search
<anItem>
The item to search the array for

Back to top...


GetArrayValue:

Get an interpolated value from an array.
i.e.
GetArrayValue #(red, green, blue) 1.5
will return
(color 127.5 127.5 0) (or halfway between red and green)
Note: the array values must support the normal compare operators, and allow addition and division with floats.

Returns:

The interpolated value from the array.

Arguments:
<anArray>
The array to get values from.
<f>
A float index.

Back to top...


GetNormArrayValue:

Get an interpolated value from an array using a normalize 0 to 1 index.
This works exactly like GetArrayValue, except the index should be normalized to 0.0 to 1.0.

Returns:

The interpolated value from the array.

Arguments:
<anArray>
The array to get values from.
<f>
A float index, between 0.0 and 1.0.

Back to top...


MaxValueIndex/MinValueIndex:

Return the index of the largest (or smallest) value in the array.

Returns:

The index of the largest (or smallest) value in the array.

Arguments:
<anArray>
The array to search.

Back to top...


ReverseArray:

Reverse the order of items in array.

Returns:

OK (updates passed value).

Arguments:
%<anArray>
The array to reverse

Back to top...


ScaleArray:

Scale an array to a new size, with new values linearly interpolated from old values.

Returns:

A new array with size of "newSize".

Arguments:
<anArray>
The array to scale
<newCount>
The size of the new array to return.

Back to top...


ScrambleArray:

Scrambles the order of items in an array.
The default call of ScrambleArray myArray will scramble the whole thing once over.

Returns:

OK (updates passed value).

Arguments:
%<anArray>
The array to scramble
[passes:1]
The number of times to scramble the array (1 should usually be enough)
[boundMin:1]
The lower index of the array to include in scrambling
[boundMax:-1]
The upper index of the array to include in scrambling. (-1 == array size).
[seedVal:1]
The seed value to use for random scramble

Back to top...


TrimDuplicates:

Trims an array down so that it holds only one reference to each item. ie:
TrimDuplicates #(1,2,3,4,3,4,5) would trim the array to #(1,2,3,4,5)
The more duplicates in the array, the faster it goes.

Returns:

OK (updates passed value).

Arguments:
%<array>
The array to trim down

Back to top...