Package com.graphhopper.util
Class ArrayUtil
java.lang.Object
com.graphhopper.util.ArrayUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int[]applyOrder(int[] arr, int[] order) Creates a copy of the given array such that it is ordered by the given order.static int[]calcSortOrder(int[] arr1, int[] arr2, int length) This method calculates the sort order of the first element-pairs given by two arrays.static int[]calcSortOrder(com.carrotsearch.hppc.IntArrayList arr1, com.carrotsearch.hppc.IntArrayList arr2) static com.carrotsearch.hppc.IntArrayListconstant(int size, int value) Creates an IntArrayList of a given size where each element is set to the given valuestatic int[]invert(int[] arr) Creates a new array where each element represents the index position of this element in the given array or is set to -1 if this element does not appear in the input array.static com.carrotsearch.hppc.IntArrayListinvert(com.carrotsearch.hppc.IntArrayList list) static com.carrotsearch.hppc.IntArrayListiota(int size) Creates an IntArrayList filled with the integers 0,1,2,3,...,size-1static booleanisPermutation(com.carrotsearch.hppc.IntArrayList arr) static int[]merge(int[] a, int[] b) static com.carrotsearch.hppc.IntArrayListpermutation(int size, Random rnd) Creates an IntArrayList filled with a permutation of the numbers 0,1,2,...,size-1static com.carrotsearch.hppc.IntArrayListrange(int startIncl, int endExcl) Creates an IntArrayList filled with the integers [startIncl,endExcl[static com.carrotsearch.hppc.IntArrayListrangeClosed(int startIncl, int endIncl) Creates an IntArrayList filled with the integers [startIncl,endIncl]static intremoveConsecutiveDuplicates(int[] arr, int end) Removes all duplicate elements of the given array in the range [0, end[ in placestatic com.carrotsearch.hppc.IntArrayListreverse(com.carrotsearch.hppc.IntArrayList list) Reverses the order of the given list's elements in place and returns itstatic com.carrotsearch.hppc.IntArrayListShuffles the elements of the given list in place and returns itstatic voidtransform(com.carrotsearch.hppc.IntIndexedContainer arr, com.carrotsearch.hppc.IntIndexedContainer map) Maps one array using another, i.e.static com.carrotsearch.hppc.IntIndexedContainerwithoutConsecutiveDuplicates(com.carrotsearch.hppc.IntIndexedContainer arr) Creates a copy of the given list where all consecutive duplicates are removedstatic com.carrotsearch.hppc.IntArrayListzero(int size) Creates an IntArrayList filled with zeros
-
Constructor Details
-
ArrayUtil
public ArrayUtil()
-
-
Method Details
-
constant
public static com.carrotsearch.hppc.IntArrayList constant(int size, int value) Creates an IntArrayList of a given size where each element is set to the given value -
zero
public static com.carrotsearch.hppc.IntArrayList zero(int size) Creates an IntArrayList filled with zeros -
iota
public static com.carrotsearch.hppc.IntArrayList iota(int size) Creates an IntArrayList filled with the integers 0,1,2,3,...,size-1 -
range
public static com.carrotsearch.hppc.IntArrayList range(int startIncl, int endExcl) Creates an IntArrayList filled with the integers [startIncl,endExcl[ -
rangeClosed
public static com.carrotsearch.hppc.IntArrayList rangeClosed(int startIncl, int endIncl) Creates an IntArrayList filled with the integers [startIncl,endIncl] -
permutation
Creates an IntArrayList filled with a permutation of the numbers 0,1,2,...,size-1 -
isPermutation
public static boolean isPermutation(com.carrotsearch.hppc.IntArrayList arr) -
reverse
public static com.carrotsearch.hppc.IntArrayList reverse(com.carrotsearch.hppc.IntArrayList list) Reverses the order of the given list's elements in place and returns it -
shuffle
public static com.carrotsearch.hppc.IntArrayList shuffle(com.carrotsearch.hppc.IntArrayList list, Random random) Shuffles the elements of the given list in place and returns it -
removeConsecutiveDuplicates
public static int removeConsecutiveDuplicates(int[] arr, int end) Removes all duplicate elements of the given array in the range [0, end[ in place- Returns:
- the size of the new range that contains no duplicates (smaller or equal to end).
-
withoutConsecutiveDuplicates
public static com.carrotsearch.hppc.IntIndexedContainer withoutConsecutiveDuplicates(com.carrotsearch.hppc.IntIndexedContainer arr) Creates a copy of the given list where all consecutive duplicates are removed -
transform
public static void transform(com.carrotsearch.hppc.IntIndexedContainer arr, com.carrotsearch.hppc.IntIndexedContainer map) Maps one array using another, i.e. every element arr[x] is replaced by map[arr[x]] -
calcSortOrder
public static int[] calcSortOrder(com.carrotsearch.hppc.IntArrayList arr1, com.carrotsearch.hppc.IntArrayList arr2) -
calcSortOrder
public static int[] calcSortOrder(int[] arr1, int[] arr2, int length) This method calculates the sort order of the first element-pairs given by two arrays. The order is chosen such that it sorts the element-pairs first by the first and second by the second array. The input arrays are not manipulated by this method.- Parameters:
length- must not be larger than either of the two input array lengths.- Returns:
- an array x of length . e.g. if this method returns x = {2, 0, 1} it means that that the element-pair with index 2 comes first in the order and so on
-
applyOrder
public static int[] applyOrder(int[] arr, int[] order) Creates a copy of the given array such that it is ordered by the given order. The order can be shorter or equal, but not longer than the array. -
invert
public static int[] invert(int[] arr) Creates a new array where each element represents the index position of this element in the given array or is set to -1 if this element does not appear in the input array. None of the elements of the input array may be equal or larger than the arrays length. -
invert
public static com.carrotsearch.hppc.IntArrayList invert(com.carrotsearch.hppc.IntArrayList list) -
merge
public static int[] merge(int[] a, int[] b) - Parameters:
a- sorted arrayb- sorted array- Returns:
- sorted array consisting of the elements of a and b, duplicates get removed
-