public abstract class HashTable
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
CONSTANT_INTERVAL
Constant value used in determining the interval for double hashing
it MUST be a prime number to minimize collision
|
Constructor and Description |
---|
HashTable() |
Modifier and Type | Method and Description |
---|---|
static int |
getCoPrime(int bucketSize)
Returns the nearest co-prime value for the size of the bucket(s), this
is due to a fact of number theory where the number of collisions is
minimized only if both the constant interval and the bucket size are
both prime.
|
static java.math.BigInteger |
getInterval(java.math.BigInteger key) |
static int |
getInterval(int key)
Returns the interval for incrementing the probe
|
static java.math.BigInteger |
getProbe(java.math.BigInteger key,
int bucketSize) |
static int |
getProbe(int key,
int bucketSize)
Returns the initial probe value for generating the hash table given the
key
NOTE: The size of the bucket being probed should be a prime number
to ensure that the modulus for the probe and constant interval
are co-prime
|
private static final int CONSTANT_INTERVAL
public static int getProbe(int key, int bucketSize)
key
- The key to be hashedbucketSize
- The size of the bucket(s) being probed, should
be prime number to ensure maximum efficiencypublic static java.math.BigInteger getProbe(java.math.BigInteger key, int bucketSize)
public static int getInterval(int key)
public static java.math.BigInteger getInterval(java.math.BigInteger key)
public static int getCoPrime(int bucketSize)
bucketSize
- The size of the bucket(s)http://stackoverflow.com/questions/1145217/why-should-hash-functions-use-a-prime-number-modulus
,
NOTE: If the two bucket is already co-prime with the constant interval
then the size of the bucket is returned.
NOTE: By using the nearest prime value of the bucket to ensure that it
is co-prime the number of values selected is less than that of the
original bucket.