Package org.semanticweb.elk.util.hashing
Class HashGenerator
java.lang.Object
org.semanticweb.elk.util.hashing.HashGenerator
public class HashGenerator extends Object
Class used to generate strong hash codes for newly created objects, and for
combining multiple hash codes into new ones in various ways.
- Author:
- Yevgeny Kazakov, Markus Kroetzsch, Frantisek Simancik
-
Constructor Summary
Constructors Constructor Description HashGenerator() -
Method Summary
Modifier and Type Method Description static intcombinedHashCode(Iterable<?> objects)Compute the combined hash code of several objects using theirObject.hashCode()functions.static intcombinedHashCode(Object... objects)Compute the combined hash code of several objects using theirObject.hashCode()functions.static intcombineListHash(int... hashes)Combine many hash codes into one in a way that depends on their order.static <T> intcombineListHash(Iterator<? extends T> hashObjectIterator, Hasher<T> hasher)Combine the hash codes of a collection of objects into one in a way that depends on their order.static <T> intcombineListHash(List<? extends T> hashObjects, Hasher<T> hasher)Combine the hash codes of a collection of objects into one in a way that depends on their order.static intcombineMultisetHash(boolean finalize, int... hashes)Combine many hash codes with an associative commutative hash function.static <T> intcombineMultisetHash(boolean finalize, Iterable<? extends T> hashObjects, Hasher<T> hasher)Combine the hash codes of a collection of objects with an associative commutative hash function.static <T> intcombineMultisetHash(boolean finalize, Iterator<? extends T> hashObjectIterator, Hasher<T> hasher)Combine the hash codes of a collection of objects with an associative commutative hash function.static intgenerateNextHashCode()Generate a new "hash code" integer.
-
Constructor Details
-
HashGenerator
public HashGenerator()
-
-
Method Details
-
generateNextHashCode
public static int generateNextHashCode()Generate a new "hash code" integer. Consecutive calls to this method create a sequence of integers with near-uniform distribution. These codes may be used as hash codes for objects that are managed in such a way that no two objects of different content can occur. Different hash codes then guarantee that the objects are not equal, even if the hash code does is not based on the hashed object at all. Obviously, hash codes of this form are not stable over multiple runs of the program, and can therefore not be used for comparing objects across runs (e.g. in testing). However, they can be useful in hash-based data structures.- Returns:
- the generated hash code
-
combinedHashCode
Compute the combined hash code of several objects using theirObject.hashCode()functions. The combined hash code depends on the order in which the objects are listed. The current implementation is based on the Jenkins One-at-a-Time hash, see http://www.burtleburtle.net/bob/hash/doobs.html and also http://en.wikipedia.org/wiki/Jenkins_hash_function.- Parameters:
objects- the list of objects for which to compute the combined hash code- Returns:
- the combined hash code
-
combinedHashCode
Compute the combined hash code of several objects using theirObject.hashCode()functions. The combined hash code depends on the order in which the objects are listed. The current implementation is based on the Jenkins One-at-a-Time hash, see http://www.burtleburtle.net/bob/hash/doobs.html and also http://en.wikipedia.org/wiki/Jenkins_hash_function.- Parameters:
objects- the list of objects for which to compute the combined hash code- Returns:
- the combined hash code
-
combineMultisetHash
public static int combineMultisetHash(boolean finalize, int... hashes)Combine many hash codes with an associative commutative hash function. Associativity ensures that the result of this functions can be further combined with other hash codes for getting the same result as if all hash codes had been combined in one step. If finalize is false, then the method as such represents an associative commutative hash, i.e. the return value can be combined with other set-based hash codes in any order without making a difference. If finalize is true, then the method combines its arguments with a commutative hash, but shuffles the overall result. The method as such then is neither an associative nor a commutative operation. This mode of operation should be used whenever no further elements are to be added to the set of hashes.- Parameters:
finalize-hashes-- Returns:
- the combined hash code
-
combineMultisetHash
public static <T> int combineMultisetHash(boolean finalize, Iterable<? extends T> hashObjects, Hasher<T> hasher)Combine the hash codes of a collection of objects with an associative commutative hash function. Associativity ensures that the result of this functions can be further combined with other hash codes for getting the same result as if all hash codes had been combined in one step. If finalize is false, then the method as such represents an associative commutative hash, i.e. the return value can be combined with other set-based hash codes in any order without making a difference. If finalize is true, then the method combines its arguments with a commutative hash, but shuffles the overall result. The method as such then is neither an associative nor a commutative operation. This mode of operation should be used whenever no further elements are to be added to the set of hashes.- Parameters:
finalize-hashObjects-hasher-- Returns:
- the combined hash code
-
combineMultisetHash
public static <T> int combineMultisetHash(boolean finalize, Iterator<? extends T> hashObjectIterator, Hasher<T> hasher)Combine the hash codes of a collection of objects with an associative commutative hash function. Associativity ensures that the result of this functions can be further combined with other hash codes for getting the same result as if all hash codes had been combined in one step. If finalize is false, then the method as such represents an associative commutative hash, i.e. the return value can be combined with other set-based hash codes in any order without making a difference. If finalize is true, then the method combines its arguments with a commutative hash, but shuffles the overall result. The method as such then is neither an associative nor a commutative operation. This mode of operation should be used whenever no further elements are to be added to the set of hashes.- Type Parameters:
T-- Parameters:
finalize-hashObjectIterator-hasher-- Returns:
- the combined hash code
-
combineListHash
public static int combineListHash(int... hashes)Combine many hash codes into one in a way that depends on their order. The current implementation is based on the Jenkins One-at-a-Time hash, see http://www.burtleburtle.net/bob/hash/doobs.html and also http://en.wikipedia.org/wiki/Jenkins_hash_function.- Parameters:
hashes-- Returns:
- the combined hash code
-
combineListHash
Combine the hash codes of a collection of objects into one in a way that depends on their order. The current implementation is based on the Jenkins One-at-a-Time hash, see http://www.burtleburtle.net/bob/hash/doobs.html and also http://en.wikipedia.org/wiki/Jenkins_hash_function.- Parameters:
hashObjects-hasher-- Returns:
- the combined hash code
-
combineListHash
Combine the hash codes of a collection of objects into one in a way that depends on their order. The current implementation is based on the Jenkins One-at-a-Time hash, see http://www.burtleburtle.net/bob/hash/doobs.html and also http://en.wikipedia.org/wiki/Jenkins_hash_function.- Parameters:
hashObjectIterator-hasher-- Returns:
- the combined hash code
-