Package org.apache.hadoop.util.hash
Class Hash
java.lang.Object
org.apache.hadoop.util.hash.Hash
- Direct Known Subclasses:
JenkinsHash,MurmurHash
This class represents a common API for hashing functions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant to denote invalid hash type.static final intConstant to denoteJenkinsHash.static final intConstant to denoteMurmurHash. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetHashType(Configuration conf) This utility method converts the name of the configured hash type to a symbolic constant.static HashgetInstance(int type) Get a singleton instance of hash function of a given type.static HashgetInstance(Configuration conf) Get a singleton instance of hash function of a type defined in the configuration.inthash(byte[] bytes) Calculate a hash using all bytes from the input argument, and a seed of -1.inthash(byte[] bytes, int initval) Calculate a hash using all bytes from the input argument, and a provided seed value.abstract inthash(byte[] bytes, int length, int initval) Calculate a hash using bytes from 0 tolength, and the provided seed valuestatic intparseHashType(String name) This utility method converts String representation of hash function name to a symbolic constant.
-
Field Details
-
INVALID_HASH
public static final int INVALID_HASHConstant to denote invalid hash type.- See Also:
-
JENKINS_HASH
public static final int JENKINS_HASHConstant to denoteJenkinsHash.- See Also:
-
MURMUR_HASH
public static final int MURMUR_HASHConstant to denoteMurmurHash.- See Also:
-
-
Constructor Details
-
Hash
public Hash()
-
-
Method Details
-
parseHashType
This utility method converts String representation of hash function name to a symbolic constant. Currently two function types are supported, "jenkins" and "murmur".- Parameters:
name- hash function name- Returns:
- one of the predefined constants
-
getHashType
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
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
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 bytesinitval- seed value- Returns:
- hash value
-
hash
public abstract int hash(byte[] bytes, int length, int initval) Calculate a hash using bytes from 0 tolength, and the provided seed value- Parameters:
bytes- input byteslength- length of the valid bytes to considerinitval- seed value- Returns:
- hash value
-