public class HopScotchHashingAlgorithm extends Object
An implementation of the hop-scotch algorithm, see http://en.wikipedia.org/wiki/Hopscotch_hashing.
It's a static set of methods that implements the essence of the algorithm, where storing and retrieving data is
abstracted into the Table interface. Also things like monitoring and choice of
HopScotchHashingAlgorithm.HashFunction gets passed in.
About hop scotching and hop bits: Each index in the table has hop bits which is a list of which nearby
indexes contain entries with a key hashing to the same index as itself - its neighborhood.
A neighbor can at most be H indexes away. This is the collision resolution method of choice
for the hop scotch algorithm. Getting and putting entries at an index first checks the index at hand.
If occupied by another entry its neighbors, dictated by the hop bits, are checked.
When putting an entry and the index and all its neighbors are occupied, the hop scotching begins, where a free
index further away is picked and iteratively moved closer and closer until it's within the neighborhood
of the intended index. The entry is then placed at that newly "freed" index.
Removing an entry will put some effort into do reverse hop scotching as well, i.e. moving a neighbor into
the newly removed index and iteratively also move neighbors of the moved neighbor, and so forth.
This behavior has the benefit of keeping entries hashing to the same index very close together,
and so will take more advantage of CPU caches and pre-fetching in general, especially for lookups.
Why are these methods (like put(Table, Monitor, HashFunction, long, Object, ResizeMonitor),
get(Table, Monitor, HashFunction, long) a.s.o. static? To reduce garbage and also reduce overhead of each
set or map object making use of hop-scotch hashing where they won't need to have a reference to an algorithm
object, merely use its static methods. Also, all essential state is managed by Table.
| Modifier and Type | Class and Description |
|---|---|
static interface |
HopScotchHashingAlgorithm.HashFunction |
static interface |
HopScotchHashingAlgorithm.Monitor
Monitor for what how a
HopScotchHashingAlgorithm changes the items in a Table. |
static interface |
HopScotchHashingAlgorithm.ResizeMonitor<VALUE> |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_H
Default number of hop bits per index, i.e.
|
static HopScotchHashingAlgorithm.HashFunction |
DEFAULT_HASHING
The default hash function is based on a pseudo-random number generator, which uses the input value as a seed
to the generator.
|
static HopScotchHashingAlgorithm.HashFunction |
JUL_HASHING
Same hash function as that used by the standard library hash collections.
|
static HopScotchHashingAlgorithm.Monitor |
NO_MONITOR |
| Constructor and Description |
|---|
HopScotchHashingAlgorithm() |
| Modifier and Type | Method and Description |
|---|---|
static <VALUE> VALUE |
get(Table<VALUE> table,
HopScotchHashingAlgorithm.Monitor monitor,
HopScotchHashingAlgorithm.HashFunction hashFunction,
long key) |
static <VALUE> VALUE |
put(Table<VALUE> table,
HopScotchHashingAlgorithm.Monitor monitor,
HopScotchHashingAlgorithm.HashFunction hashFunction,
long key,
VALUE value,
HopScotchHashingAlgorithm.ResizeMonitor<VALUE> resizeMonitor) |
static <VALUE> VALUE |
remove(Table<VALUE> table,
HopScotchHashingAlgorithm.Monitor monitor,
HopScotchHashingAlgorithm.HashFunction hashFunction,
long key) |
public static final int DEFAULT_H
public static final HopScotchHashingAlgorithm.Monitor NO_MONITOR
public static final HopScotchHashingAlgorithm.HashFunction JUL_HASHING
public static final HopScotchHashingAlgorithm.HashFunction DEFAULT_HASHING
public static <VALUE> VALUE get(Table<VALUE> table, HopScotchHashingAlgorithm.Monitor monitor, HopScotchHashingAlgorithm.HashFunction hashFunction, long key)
public static <VALUE> VALUE remove(Table<VALUE> table, HopScotchHashingAlgorithm.Monitor monitor, HopScotchHashingAlgorithm.HashFunction hashFunction, long key)
public static <VALUE> VALUE put(Table<VALUE> table, HopScotchHashingAlgorithm.Monitor monitor, HopScotchHashingAlgorithm.HashFunction hashFunction, long key, VALUE value, HopScotchHashingAlgorithm.ResizeMonitor<VALUE> resizeMonitor)
Copyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.