Class IndexedList.IndexGenerator
java.lang.Object
org.jlab.utils.groups.IndexedList.IndexGenerator
- Enclosing class:
IndexedList<T>
Utility class for generating and decoding a long key from a
multi-dimensional index. Default is up to 4 indices with 16 bits, but any
byte shifts can be set up to a max of 64
- Author:
- gavalian
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an IndexGenerator with generic index size.IndexGenerator(int[] byteShifts) Constructs an IndexGenerator from a given byte shifts array. -
Method Summary
Modifier and TypeMethodDescriptionint[]Get the byte shiftsintgetIndex(long hashcode, int order) Retrieves a specific index from the encoded long key.int[]Get the max value allowed for each indexgetString(long hashcode) Returns a formatted string representing all indices in the hash key.longhashCode(int... indices) Generates a long key from the given array of indices.
-
Constructor Details
-
IndexGenerator
public IndexGenerator()Constructs an IndexGenerator with generic index size. -
IndexGenerator
public IndexGenerator(int[] byteShifts) Constructs an IndexGenerator from a given byte shifts array.- Parameters:
byteShifts- the array of byte shifts to consider
-
-
Method Details
-
getByteShifts
public int[] getByteShifts()Get the byte shifts- Returns:
- the array of byte shifts
-
getMaxValues
public int[] getMaxValues()Get the max value allowed for each index- Returns:
- the array of max values
-
hashCode
public long hashCode(int... indices) Generates a long key from the given array of indices.- Parameters:
indices- the index array- Returns:
- a long key representing the hashed index
- Throws:
IllegalArgumentException- if the number of indices exceeds supported length
-
getIndex
public int getIndex(long hashcode, int order) Retrieves a specific index from the encoded long key.- Parameters:
hashcode- the encoded long keyorder- the position of the index to retrieve- Returns:
- the decoded index
-
getString
Returns a formatted string representing all indices in the hash key.- Parameters:
hashcode- the encoded long keylength- the number of indices to extract- Returns:
- a string representation of the indices
-