Func_ra: TSL's Missing Array Manipulation Functions

Alright, any self respecting automated testers out there knows the importance of arrays. Unfortunately, Mercury only provides the basic functionality for manipulating arrays. Create and Delete. How fun. Fortunately, you can now have a fuller featured tool for manipulating arrays. From getting the length of an array, removing an element from an array, copying arrays, the limit is endless!!!

So, without further delay (I've been swamped, so sorry for the delay :-) ), here is a summary of the features:

Add an item at the end of a sequential array (so you don't have to worry about keeping track of the array size).
Appends the elements of one array to the end of another array. ** Updated to work with empty array **
Fills in the target array with the values of the source array.
Clears out the content of the array. ** Updated to use "out" as parameter type **
Compare 2 arrays, both on the key and element values.
Makes a copy of an array (same length, key, value).
Returns the first index in an array. Only works for a sequential array. This function has been updated to run faster than before (up to 90 times faster) -- but no longer supports associative array. If anyone still needs support for associative array, let me know and I'll try to support it. ** Updated on May 10, 2002 to work correctly with very small arrays (e.g. 2 elements) ** ** Updated on September 8, 2002 to fix bug that causes the function to go into an infinite loop when using a certain sized array **
Returns the last index in the array. Only works for a sequential array. This function has been updated to run faster than before (up to 90 times faster) -- as with the array_get_first_index function, this function no longer support associative arrays. Let me know if anyone would still be interested in that support.
** Updated on Oct 11, 2001. I was informed that this function was written as array_get_last_index2, which breaks some other functions that uses this function. This has been corrected. ** ** Update on February 13, 2002. I was informed by Dianne Davis (formerly with XO Communications) that this function didn't work as expected, and after some investigation, I found the error. It has since been fixed. ** ** Updated on September 9, 2002 to fix bug that causes the function to go into an infinite loop when using a certain sized array (see array_get_first_index) **
Returns both the first and last index in an array. Uses array_get_first_index and array_get_last_index, so it currently only supports sequential array.
Inserts an element to a specified position of a sequential array.
Inverses the order of a sequential array.
Determines whether an array is empty.
** Updated on Mar 15, 2004. Thanks to Andrew Bleach for reporting that this function was returning inverse return value. This has been corrected. **
Returns the length of the array. More useful if the array is sequentially indexed, of course.
Randomly pick an array element. Does not modify the array's elements at all.
Returns a randomly picked array item, and remove the element from the array. This is basically an array_pick and array_remove together.
Remove an element from the array, and move the remaining elements down so that the array is still sequential. This allows you to remove an element from the middle of an array.
Shuffles the content of an array. May not be that useful to most people, but can be useful to some people. (Corrected bug that causes it to complain about invalid number of parameters).
Copy a subset of an array to another array. Also allows the user to specify the starting index in the target array.
Swaps the element contents of the specified array index locations. E.g. to swap the element contents of the first and last element (hmm, maybe for sorting?).
Join the elements in an array into a string. Basically the reverse of the split command. You can specify any string as the concatenator string.
Compares the contents of 2 arrays, and populates 3 result arrays: matching elements, unmatched elements from the first array, and unmatched elements in the second array.
Works like the regular split, except this one accepts string as a delimiter.
An extension of split2 that appends to an array as opposed to replacing it. Very useful at times.

Can't wait to get your hands on it? Get it here:

Tech Page @