org.apache.hadoop.hbase.util
Class Hash

java.lang.Object
  extended by org.apache.hadoop.hbase.util.Hash
Direct Known Subclasses:
JenkinsHash, MurmurHash, MurmurHash3

@InterfaceAudience.Private
@InterfaceStability.Stable
public abstract class Hash
extends Object

This class represents a common API for hashing functions.


Field Summary
static int INVALID_HASH
          Constant to denote invalid hash type.
static int JENKINS_HASH
          Constant to denote JenkinsHash.
static int MURMUR_HASH
          Constant to denote MurmurHash.
static int MURMUR_HASH3
          Constant to denote MurmurHash3.
 
Constructor Summary
Hash()
           
 
Method Summary
static int getHashType(org.apache.hadoop.conf.Configuration conf)
          This utility method converts the name of the configured hash type to a symbolic constant.
static Hash getInstance(org.apache.hadoop.conf.Configuration conf)
          Get a singleton instance of hash function of a type defined in the configuration.
static Hash getInstance(int type)
          Get a singleton instance of hash function of a given type.
 int hash(byte[] bytes)
          Calculate a hash using all bytes from the input argument, and a seed of -1.
 int hash(byte[] bytes, int initval)
          Calculate a hash using all bytes from the input argument, and a provided seed value.
 int hash(byte[] bytes, int length, int initval)
          Calculate a hash using bytes from 0 to length, and the provided seed value
abstract  int hash(byte[] bytes, int offset, int length, int initval)
          Calculate a hash using bytes from offset to offset + length, and the provided seed value.
static int parseHashType(String name)
          This utility method converts String representation of hash function name to a symbolic constant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALID_HASH

public static final int INVALID_HASH
Constant to denote invalid hash type.

See Also:
Constant Field Values

JENKINS_HASH

public static final int JENKINS_HASH
Constant to denote JenkinsHash.

See Also:
Constant Field Values

MURMUR_HASH

public static final int MURMUR_HASH
Constant to denote MurmurHash.

See Also:
Constant Field Values

MURMUR_HASH3

public static final int MURMUR_HASH3
Constant to denote MurmurHash3.

See Also:
Constant Field Values
Constructor Detail

Hash

public Hash()
Method Detail

parseHashType

public static int parseHashType(String name)
This utility method converts String representation of hash function name to a symbolic constant. Currently three function types are supported, "jenkins", "murmur" and "murmur3".

Parameters:
name - hash function name
Returns:
one of the predefined constants

getHashType

public static int getHashType(org.apache.hadoop.conf.Configuration conf)
This utility method converts the name of the configured hash type to a symbolic constant.

Parameters:
conf - configuration
Returns:
one of the predefined constants

getInstance

public static Hash getInstance(int type)
Get a singleton instance of hash function of a given type.

Parameters:
type - predefined hash type
Returns:
hash function instance, or null if type is invalid

getInstance

public static Hash getInstance(org.apache.hadoop.conf.Configuration conf)
Get a singleton instance of hash function of a type defined in the configuration.

Parameters:
conf - current configuration
Returns:
defined hash type, or null if type is invalid

hash

public int hash(byte[] bytes)
Calculate a hash using all bytes from the input argument, and a seed of -1.

Parameters:
bytes - input bytes
Returns:
hash value

hash

public int hash(byte[] bytes,
                int initval)
Calculate a hash using all bytes from the input argument, and a provided seed value.

Parameters:
bytes - input bytes
initval - seed value
Returns:
hash value

hash

public int hash(byte[] bytes,
                int length,
                int initval)
Calculate a hash using bytes from 0 to length, and the provided seed value

Parameters:
bytes - input bytes
length - length of the valid bytes after offset to consider
initval - seed value
Returns:
hash value

hash

public abstract int hash(byte[] bytes,
                         int offset,
                         int length,
                         int initval)
Calculate a hash using bytes from offset to offset + length, and the provided seed value.

Parameters:
bytes - input bytes
offset - the offset into the array to start consideration
length - length of the valid bytes after offset to consider
initval - seed value
Returns:
hash value


Copyright © 2015 The Apache Software Foundation. All Rights Reserved.