Class ArrayUtil


  • public final class ArrayUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int binaryLookup​(long id, long[] ids)
      Find the index where (ids[idx] <= id) && (ids[idx + 1] > id).
      static boolean binarySearch​(int[] arr, int length, int key)  
      static int binarySearchFirst​(long[] a, int fromIndex, int toIndex, long key)
      Similar to Arrays.binarySearch(long[], int, int, long), but returns the index of the first occurrence of key in a if there are multiple occurrences.
      static int binarySearchIndex​(int[] arr, int length, int key)  
      static int binarySearchLast​(long[] a, int fromIndex, int toIndex, long key)
      Similar to Arrays.binarySearch(long[], int, int, long), but returns the index of the last occurrence of key in a if there are multiple occurrences.
      static double[] fill​(double value, int length)  
      static boolean linearSearch​(int[] arr, int length, int key)  
      static boolean linearSearch2​(int[] arr, int low, int high, int key)  
      static int linearSearch2index​(int[] arr, int low, int high, int key)  
      static int linearSearchIndex​(int[] arr, int length, int key)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_ARRAY_LENGTH

        public static final int MAX_ARRAY_LENGTH
    • Method Detail

      • binarySearch

        public static boolean binarySearch​(int[] arr,
                                           int length,
                                           int key)
      • binarySearchFirst

        public static int binarySearchFirst​(long[] a,
                                            int fromIndex,
                                            int toIndex,
                                            long key)
        Similar to Arrays.binarySearch(long[], int, int, long), but returns the index of the first occurrence of key in a if there are multiple occurrences.
        Returns:
        index of the first occurrence of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      • binarySearchLast

        public static int binarySearchLast​(long[] a,
                                           int fromIndex,
                                           int toIndex,
                                           long key)
        Similar to Arrays.binarySearch(long[], int, int, long), but returns the index of the last occurrence of key in a if there are multiple occurrences.
        Returns:
        index of the last occurrence of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      • binarySearchIndex

        public static int binarySearchIndex​(int[] arr,
                                            int length,
                                            int key)
      • linearSearch2

        public static boolean linearSearch2​(int[] arr,
                                            int low,
                                            int high,
                                            int key)
      • linearSearch2index

        public static int linearSearch2index​(int[] arr,
                                             int low,
                                             int high,
                                             int key)
      • linearSearch

        public static boolean linearSearch​(int[] arr,
                                           int length,
                                           int key)
      • linearSearchIndex

        public static int linearSearchIndex​(int[] arr,
                                            int length,
                                            int key)
      • binaryLookup

        public static int binaryLookup​(long id,
                                       long[] ids)
        Find the index where (ids[idx] <= id) && (ids[idx + 1] > id). The result differs from that of Arrays.binarySearch(long[], long) in that this method returns a positive index even if the array does not directly contain the searched value. It returns -1 iff the value is smaller than the smallest one in the array.
      • fill

        public static double[] fill​(double value,
                                    int length)