Package org.apache.datasketches.tuple
Class Util
java.lang.Object
org.apache.datasketches.tuple.Util
Common utility functions for Tuples
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic final void
checkSeedHashes
(short seedHashA, short seedHashB) Checks the two given seed hashes.static short
computeSeedHash
(long seed) Computes and checks the 16-bit seed hash from the given long seed.static <S extends Summary>
S[]copySummaryArray
(S[] summaryArr) Will copy compact summary arrays as well as hashed summary tables (with nulls).static final long[]
doubleToLongArray
(double value) Converts a double to a long[].static int
getStartingCapacity
(int nomEntries, int lgResizeFactor) Gets the starting capacity of a new sketch given the Nominal Entries and the log Resize Factor.static <S extends Summary>
S[]newSummaryArray
(S[] summaryArr, int length) Creates a new Summary Array with the specified lengthstatic long
stringArrHash
(String[] strArray) static String
stringConcat
(String[] strArr) Concatenate array of Strings to a single String.static long
stringHash
(String s) static final byte[]
stringToByteArray
(String value) Converts a String to a UTF_8 byte array.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
doubleToLongArray
public static final long[] doubleToLongArray(double value) Converts a double to a long[].- Parameters:
value
- the given double value- Returns:
- the long array
-
stringToByteArray
Converts a String to a UTF_8 byte array. If the given value is either null or empty this method returns null.- Parameters:
value
- the given String value- Returns:
- the UTF_8 byte array
-
computeSeedHash
public static short computeSeedHash(long seed) Computes and checks the 16-bit seed hash from the given long seed. The seed hash may not be zero in order to maintain compatibility with older serialized versions that did not have this concept.- Parameters:
seed
- See Update Hash Seed- Returns:
- the seed hash.
-
checkSeedHashes
public static final void checkSeedHashes(short seedHashA, short seedHashB) Checks the two given seed hashes. If they are not equal, this method throws an Exception.- Parameters:
seedHashA
- given seed hash AseedHashB
- given seed hash B
-
getStartingCapacity
public static int getStartingCapacity(int nomEntries, int lgResizeFactor) Gets the starting capacity of a new sketch given the Nominal Entries and the log Resize Factor.- Parameters:
nomEntries
- the given Nominal EntrieslgResizeFactor
- the given log Resize Factor- Returns:
- the starting capacity
-
stringConcat
Concatenate array of Strings to a single String.- Parameters:
strArr
- the given String array- Returns:
- the concatenated String
-
stringHash
- Parameters:
s
- the string to hash- Returns:
- the hash of the string
-
stringArrHash
- Parameters:
strArray
- array of Strings- Returns:
- long hash of concatenated strings.
-
copySummaryArray
Will copy compact summary arrays as well as hashed summary tables (with nulls).- Type Parameters:
S
- type of summary- Parameters:
summaryArr
- the given summary array or table- Returns:
- the copy
-
newSummaryArray
Creates a new Summary Array with the specified length- Type Parameters:
S
- the summary class type- Parameters:
summaryArr
- example array, only used to obtain the component type. It has no data.length
- the desired length of the returned array.- Returns:
- a new Summary Array with the specified length
-