public class Utility
extends Object
Library utilities.
-
Constructor Summary
Constructors
-
Method Summary
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.
-
-
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.