Class RangeHashTable<T>
- java.lang.Object
-
- org.hibernate.search.util.common.data.impl.HashTable<T>
-
- org.hibernate.search.util.common.data.impl.RangeHashTable<T>
-
- Type Parameters:
T- The type of elements stored in each bucket.
- All Implemented Interfaces:
Iterable<T>
public final class RangeHashTable<T> extends HashTable<T>
A hash table that derives an index from hashes using a partition of the hashing space based on contiguous ranges.This makes this table particularly suitable in situations where the hash must be computed before the number of buckets is known, then stored, then queried efficiently (e.g. retrieve all entries for a given bucket by querying
WHERE hash BETWEEN bucketLowerBound AND bucketUpperBound). This wouldn't be as efficient with a modulo-based hash table such asModuloHashTable, since the modulo operation would have to be applied to all entries at query time (it cannot be indexed since the number of buckets is not known when hashing).
-
-
Constructor Summary
Constructors Constructor Description RangeHashTable(RangeCompatibleHashFunction hashFunction, int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcomputeIndex(CharSequence key)Hashes akeyand computes an array index based on that hash.intcomputeIndexForHash(int hash)Range<Integer>rangeForBucket(int index)-
Methods inherited from class org.hibernate.search.util.common.data.impl.HashTable
get, get, iterator, set, size
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
RangeHashTable
public RangeHashTable(RangeCompatibleHashFunction hashFunction, int size)
-
-
Method Detail
-
computeIndex
public int computeIndex(CharSequence key)
Description copied from class:HashTableHashes akeyand computes an array index based on that hash.The maximum index is defined by constructor parameters passed to the hash function.
- Specified by:
computeIndexin classHashTable<T>- Parameters:
key- A key to hash in order to compute an index.- Returns:
- The index to use for the given
keyin a hash table of sizesize.
-
computeIndexForHash
public int computeIndexForHash(int hash)
-
rangeForBucket
public Range<Integer> rangeForBucket(int index)
- Parameters:
index- An index between0andHashTable.size()(exclusive).- Returns:
- The range of
hashesassociated to the bucket for that index.
-
-