Package tkrzw

Class Utility

Object
Utility

public class Utility extends Object
Library utilities.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    deserializeFloat(byte[] data)
    Deserializes a big-endian binary sequence into a floating-point number.
    static long
    deserializeInt(byte[] data)
    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
    primaryHash(byte[] data, long num_buckets)
    Primary hash function for the hash database.
    static long
    secondaryHash(byte[] data, long num_shards)
    Secondaryy hash function for sharding.
    static byte[]
    serializeFloat(double num)
    Serializes a floating-point number into a big-endian binary sequence.
    static byte[]
    serializeInt(long num)
    Serializes an integer into a big-endian binary sequence.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Utility

      public Utility()
  • Method Details

    • parseParams

      public static HashMap<String,String> parseParams(String str)
      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

      public static int editDistanceLev(String a, String b)
      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.