Package org.neo4j.gds.core.utils
Class ArrayUtil
- java.lang.Object
-
- org.neo4j.gds.core.utils.ArrayUtil
-
public final class ArrayUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
LINEAR_SEARCH_LIMIT
static int
MAX_ARRAY_LENGTH
-
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 toArrays.binarySearch(long[], int, int, long)
, but returns the index of the first occurrence ofkey
ina
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 toArrays.binarySearch(long[], int, int, long)
, but returns the index of the last occurrence ofkey
ina
if there are multiple occurrences.static boolean
contains(long[] array, long value)
Finds whether an array contains a given value.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)
-
-
-
Field Detail
-
MAX_ARRAY_LENGTH
public static final int MAX_ARRAY_LENGTH
-
LINEAR_SEARCH_LIMIT
public static final int LINEAR_SEARCH_LIMIT
- See Also:
- Constant Field Values
-
-
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 toArrays.binarySearch(long[], int, int, long)
, but returns the index of the first occurrence ofkey
ina
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, ora.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 toArrays.binarySearch(long[], int, int, long)
, but returns the index of the last occurrence ofkey
ina
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, ora.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 ofArrays.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)
-
contains
public static boolean contains(long[] array, long value)
Finds whether an array contains a given value. Linear scans the array and returns true on finding any value equal to the argument.
-
-