public class Utility
extends Object
Library utilities.
-
Constructor Summary
Constructors
-
Method Summary
static double
Deserializes a big-endian binary sequence into a floating-point number.
static long
Deserializes a big-endian binary sequence into an integer.
static int
Gets the Levenshtein edit distance of two strings.
static long
Gets the memory capacity of the platform.
static long
Gets the current memory usage of the process.
Parses a string of parameters in "key=value,key=value" format.
static long
Primary hash function for the hash database.
static long
Secondaryy hash function for sharding.
static byte[]
Serializes a floating-point number into a big-endian binary sequence.
static byte[]
Serializes an integer into a big-endian binary sequence.
-
-
Method Details
-
parseParams
Parses a string of parameters in "key=value,key=value" format.
- Parameters:
str
- The string of parameters.
- Returns:
- A map of key-value records.
-
getMemoryCapacity
public static long getMemoryCapacity()
Gets the memory capacity of the platform.
- Returns:
- The memory capacity of the platform in bytes, or -1 on failure.
-
getMemoryUsage
public static long getMemoryUsage()
Gets the current memory usage of the process.
- Returns:
- The current memory usage of the process in bytes, or -1 on failure.
-
primaryHash
public static long primaryHash(byte[] data,
long num_buckets)
Primary hash function for the hash database.
- Parameters:
data
- The data to calculate the hash value for.
num_buckets
- The number of buckets of the hash table. If it is 0 or less, the range
of the hash value is from Long.MIN_VALUE to Long.MAX_VALUE.
- Returns:
- The hash value.
-
secondaryHash
public static long secondaryHash(byte[] data,
long num_shards)
Secondaryy hash function for sharding.
- Parameters:
data
- The data to calculate the hash value for.
num_shards
- The number of shards. If it is 0 or less, the range of the hash value is
from Long.MIN_VALUE to Long.MAX_VALUE.
- Returns:
- The hash value.
-
editDistanceLev
Gets the Levenshtein edit distance of two strings.
- Parameters:
a
- A string.
b
- The other string.
- Returns:
- The Levenshtein edit distance of the two strings.
-
serializeInt
public static byte[] serializeInt(long num)
Serializes an integer into a big-endian binary sequence.
- Parameters:
num
- an integer.
- Returns:
- The result binary sequence.
-
deserializeInt
public static long deserializeInt(byte[] data)
Deserializes a big-endian binary sequence into an integer.
- Parameters:
data
- a binary sequence.
- Returns:
- The result integer.
-
serializeFloat
public static byte[] serializeFloat(double num)
Serializes a floating-point number into a big-endian binary sequence.
- Parameters:
num
- a floating-point number.
- Returns:
- The result binary sequence.
-
deserializeFloat
public static double deserializeFloat(byte[] data)
Deserializes a big-endian binary sequence into a floating-point number.
- Parameters:
data
- a binary sequence.
- Returns:
- The result floating-point number.