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​(int id, int[] ids)
      Find the index where (ids[idx] <= id) && (ids[idx + 1] > id).
      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 binarySearchIndex​(int[] arr, int length, int key)  
      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)
      • 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.
      • binaryLookup

        public static int binaryLookup​(int id,
                                       int[] 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.