Class ArrayUtil

java.lang.Object
com.graphhopper.util.ArrayUtil

public class ArrayUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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.IntArrayList
    constant(int size, int value)
    Creates an IntArrayList of a given size where each element is set to the given value
    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.
    static com.carrotsearch.hppc.IntArrayList
    invert(com.carrotsearch.hppc.IntArrayList list)
     
    static com.carrotsearch.hppc.IntArrayList
    iota(int size)
    Creates an IntArrayList filled with the integers 0,1,2,3,...,size-1
    static boolean
    isPermutation(com.carrotsearch.hppc.IntArrayList arr)
     
    static int[]
    merge(int[] a, int[] b)
     
    static com.carrotsearch.hppc.IntArrayList
    permutation(int size, Random rnd)
    Creates an IntArrayList filled with a permutation of the numbers 0,1,2,...,size-1
    static com.carrotsearch.hppc.IntArrayList
    range(int startIncl, int endExcl)
    Creates an IntArrayList filled with the integers [startIncl,endExcl[
    static com.carrotsearch.hppc.IntArrayList
    rangeClosed(int startIncl, int endIncl)
    Creates an IntArrayList filled with the integers [startIncl,endIncl]
    static int
    removeConsecutiveDuplicates(int[] arr, int end)
    Removes all duplicate elements of the given array in the range [0, end[ in place
    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
    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
    static com.carrotsearch.hppc.IntArrayList
    subList(com.carrotsearch.hppc.IntArrayList list, int fromIndex, int toIndex)
     
    static void
    transform(com.carrotsearch.hppc.IntIndexedContainer arr, com.carrotsearch.hppc.IntIndexedContainer map)
    Maps one array using another, i.e.
    static com.carrotsearch.hppc.IntIndexedContainer
    withoutConsecutiveDuplicates(com.carrotsearch.hppc.IntIndexedContainer arr)
    Creates a copy of the given list where all consecutive duplicates are removed
    static com.carrotsearch.hppc.IntArrayList
    zero(int size)
    Creates an IntArrayList filled with zeros

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static com.carrotsearch.hppc.IntArrayList permutation(int size, Random rnd)
      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)
    • subList

      public static com.carrotsearch.hppc.IntArrayList subList(com.carrotsearch.hppc.IntArrayList list, int fromIndex, int toIndex)
    • merge

      public static int[] merge(int[] a, int[] b)
      Parameters:
      a - sorted array
      b - sorted array
      Returns:
      sorted array consisting of the elements of a and b, duplicates get removed