Package org.neo4j.gds.core.utils
Class ArrayLayout
- java.lang.Object
-
- org.neo4j.gds.core.utils.ArrayLayout
-
public final class ArrayLayout extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ArrayLayout.LayoutAndSecondary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long[]
constructEytzinger(long[] input)
Constructs a new binary search tree using the Eytzinger layout.static ArrayLayout.LayoutAndSecondary
constructEytzinger(long[] input, int[] secondary)
Constructs a new binary search tree using the Eytzinger layout.static long[]
constructEytzinger(long[] input, int offset, int length)
Constructs a new binary search tree using the Eytzinger layout.static int
searchEytzinger(long[] haystack, long needle)
Searches for the needle in the haystack, returning an index pointing at the needle.
-
-
-
Method Detail
-
constructEytzinger
public static long[] constructEytzinger(long[] input)
Constructs a new binary search tree using the Eytzinger layout. Input must be sorted.- Parameters:
input
- the sorted input data
-
constructEytzinger
public static long[] constructEytzinger(long[] input, int offset, int length)
Constructs a new binary search tree using the Eytzinger layout. Input must be sorted.- Parameters:
input
- the sorted input dataoffset
- where to start at in the inputlength
- how many elements to use from the input
-
constructEytzinger
public static ArrayLayout.LayoutAndSecondary constructEytzinger(long[] input, int[] secondary)
Constructs a new binary search tree using the Eytzinger layout. Input must be sorted. A secondary array is permuted in the same fashion as the input array.- Parameters:
input
- the sorted input datasecondary
- secondary values that are permuted as well
-
searchEytzinger
public static int searchEytzinger(long[] haystack, long needle)
Searches for the needle in the haystack, returning an index pointing at the needle. The array must be one constructed fromconstructEytzinger(long[])
or related. Any other order of the array (e.g. sorted for binary search) will produce undefined results. UnlikeArrays.binarySearch(long[], long)
, this method returns the index of the value that is either equal to the needle or the next smallest one. There are no different results to signal whether a value was found or not. If you need to know whether the value is contained in the array, you need to compare the value against the array at the position of the returned index. The index returned is the last index where the value is not larger than the needle. This is also different from the j.u.Arrays method. That one returns "the index of the first element greater than the key", that is the upper bound of the search. Starting from that index upto the end of the array, all values are either equal to or greater than the needle. In contrast, this method returns the lower bound. Starting from 0 up to, and including, the returned index, all values are either less than or equal to the needle.- Parameters:
haystack
- the input array sorted and constructed byconstructEytzinger(long[])
needle
- the needle to search for- Returns:
- the lower bound for the needle. Either the index of the needle if it was in the array
or the index preceding the place where the needle would be. Note that, unlike the sibling method
Arrays.binarySearch(long[], long)
, the index returned *cannot* be used to change the contents of the search array.
-
-