class ArrayTools
package de.polygonal.ds.tools
Utility class for working with Arrays.
Static methods
staticbinarySearchCmp<T> (a:Array<T>, x:T, min:Int, max:Int, comparator:T ‑> T ‑> Int):Int
Searches the sorted array src for val in the range [min, max] using the binary search algorithm.
Returns:
the array index storing val or the bitwise complement (~) of the index where val would be inserted (guaranteed to be a negative number).
The insertion point is only valid for min = 0 and max = src.length - 1.
staticbinarySearchf (a:Array<Float>, x:Float, min:Int, max:Int):Int
Searches the sorted array src for val in the range [min, max] using the binary search algorithm.
Returns:
the array index storing val or the bitwise complement (~) of the index where val would be inserted (guaranteed to be a negative number).
The insertion point is only valid for min = 0 and max = src.length - 1.
staticbinarySearchi (a:Array<Int>, x:Int, min:Int, max:Int):Int
Searches the sorted array src for val in the range [min, max] using the binary search algorithm.
Returns:
the array index storing val or the bitwise complement (~) of the index where val would be inserted (guaranteed to be a negative number).
The insertion point is only valid for min = 0 and max = src.length - 1.
staticblit<T> (src:Array<T>, srcPos:Int, dst:Array<T>, dstPos:Int, n:Int):Void
Copies n elements from src, beginning at srcPos to dst, beginning at dstPos.
Copying takes place as if an intermediate buffer was used, allowing the destination and source to overlap.
staticequals<T> (a:Array<T>, b:Array<T>):Bool
Compares the elements of a and b by using the equality operator (==).
staticinline getFront<T> (array:Array<T>, index:Int):T
Gets the element at index index, then exchanges it with element at the
front of array (i.e. at index 0). Used to facilitate fast lookups of
array elements that are frequently used.
staticinit<T> (a:Array<T>, val:T, ?first:Int, ?n:Int):Array<T>
Sets n elements in a to val starting at index first and returns a.
If n is zero, n is set to the length of a.
staticinline iter<T> (src:Array<T>, f:T ‑> Void, ?n:Int):Void
Calls 'f on all elements in the interval [0, n) in order.
If n is omitted, n is set to src`.length.
staticinline pairwise<T> (input:Array<T>, visit:Int ‑> T ‑> T ‑> Void):Void
Visits all elements in input as a pair by calling visit.
The function signature is: visit(currentPairIndex, firstPairElement, secondPairElement)
Example:
var points = [1.1, 1.2, 2.1, 2.2]; //format: [x0, y0, x1, y1, xn, yn, ...]
ArrayTools.pairwise(points, function(i, x, y) trace('point x=$x, y=$y'));
staticquickPerm (n:Int):Array<Array<Int>>
A quick counting permutation algorithm, where n is the number of elements to permute.
staticshuffle<T> (a:Array<T>, ?rvals:Array<Float>):Void
Shuffles the elements of the array a by using the Fisher-Yates algorithm.
Parameters:
rvals | a list of random double values in the range between [0, 1) defining the new positions of the elements.
If omitted, random values are generated on-the-fly by calling |
|---|
staticsortRange (a:Array<Float>, cmp:Float ‑> Float ‑> Int, useInsertionSort:Bool, first:Int, n:Int):Void
Sorts the elements of the array a by using the quick sort algorithm.
Parameters:
cmp | a comparison function. |
|---|---|
useInsertionSort | if true, the array is sorted using the insertion sort algorithm. This is faster for nearly sorted lists. |
first | sort start index. The default value is 0. |
n | the number of elements to sort (range: [ |
staticsplit<T> (a:Array<T>, n:Int, k:Int):Array<Array<T>>
Splits the input array a storing n elements into smaller chunks, each containing k elements.