Class Hash


  • public class Hash
    extends Object
    A class containing different hashing functions.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Hash.HashType
      Available Hashing techniques
    • Constructor Summary

      Constructors 
      Constructor Description
      Hash()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte expHash​(int x)
      Compute exponentially distributed hash values in range 0..a.length eg: 50% == 0 , 25% == 1 12.5 % == 2 etc.
      static int hash​(double o, Hash.HashType ht)
      Hash functions for double values.
      static int hash​(Object o, Hash.HashType ht)
      Generic hashing of java objects, not ideal for specific values so use the specific methods for specific types.
      static int linearHash​(int v)
      Compute the Linear hash of an int input value.
      static int linearHash​(int v, int bits)
      Compute the Linear hash of an int input value, but only use the first bits of the linear hash.
    • Constructor Detail

      • Hash

        public Hash()
    • Method Detail

      • hash

        public static int hash​(Object o,
                               Hash.HashType ht)
        Generic hashing of java objects, not ideal for specific values so use the specific methods for specific types. To Use the locality sensitive techniques override the objects hashcode function.
        Parameters:
        o - The Object to hash.
        ht - The HashType to use.
        Returns:
        An int Hash value.
      • hash

        public static int hash​(double o,
                               Hash.HashType ht)
        Hash functions for double values.
        Parameters:
        o - The double value.
        ht - The hashing function to apply.
        Returns:
        An int Hash value.
      • linearHash

        public static int linearHash​(int v)
        Compute the Linear hash of an int input value.
        Parameters:
        v - The value to hash.
        Returns:
        The int hash.
      • linearHash

        public static int linearHash​(int v,
                                     int bits)
        Compute the Linear hash of an int input value, but only use the first bits of the linear hash.
        Parameters:
        v - The value to hash.
        bits - The number of bits to use. up to maximum of 32.
        Returns:
        The hashed value
      • expHash

        public static byte expHash​(int x)
        Compute exponentially distributed hash values in range 0..a.length eg: 50% == 0 , 25% == 1 12.5 % == 2 etc. Useful because you can estimate size of a collection by only maintaining the highest value found. from this hash.
        Parameters:
        x - value to hash
        Returns:
        a hash value byte (only in the range of 0 to a.length)