public interface Table<VALUE> extends AutoCloseable
HopScotchHashingAlgorithm.
A table is responsible for storing and retrieving:
HopScotchHashingAlgorithm contains all hashing logic and a Table is a dump, straight
forward data keeper. Optimizations for special keys or key/value combinations can be captured in
implementations of this. The only restriction is that keys must be decimal type numbers, f.ex. short,
int or long. Where the key "carrier" between the algorithm and the table is always going to be
long since it can carry all the others.
versioning is added to the table interface, but implementations can disable versioning
by always returning the same and constant number in both version() and version(int).
Versioning helps iterating over a constant set of entries at the same time as modifying the table.| Modifier and Type | Method and Description |
|---|---|
int |
capacity() |
void |
clear()
Removes all entries from this table.
|
void |
close()
Free any resources
|
Table<VALUE> |
grow()
Grows the table to double that of the current size.
|
int |
h() |
long |
hopBits(int index)
A short summary of the hop bits format: It's a bit map represented as an int, where each set bit represents
an offset where there's a neighbor for this index.
|
boolean |
isEmpty() |
long |
key(int index) |
int |
mask() |
long |
move(int fromIndex,
int toIndex)
Moves the key/value from one index to another, any hop bits stay.
|
void |
moveHopBit(int index,
int hd,
int delta)
Moves one hop bit
delta steps. |
long |
nullKey() |
void |
put(int index,
long key,
VALUE value)
Puts (key/value) at the given
index. |
void |
putHopBit(int index,
int hd)
Adds one hop bit to the set of hop bits at the given index.
|
VALUE |
putValue(int index,
VALUE value)
Puts, actually overwrites, the value at the given
index. |
VALUE |
remove(int index)
Removes the currently assigned key/value from the given
index. |
void |
removeHopBit(int index,
int hd)
Removes one hop bit from the set of hop bits at the given index.
|
int |
size() |
VALUE |
value(int index)
OPTIONAL operation.
|
int |
version() |
int |
version(int index) |
int h()
H as defined by the hop-scotch algorithm, i.e. how many entries can share the same
table index, i.e. how many conflicts there can be at most for any given table index.int capacity()
int size()
int mask()
long key(int index)
index - the table index to get the key for.nullKey() will be returned.VALUE value(int index)
null if unsupported.index - null will be returned.void put(int index,
long key,
VALUE value)
index. This index must contractually be free at the point where the
algorithm calls this method.index - the index to put this key/value in.key - the key to put.value - the value to put.VALUE putValue(int index, VALUE value)
index. This index will contractually be occupied
at the point where the algorithm calls this method. This new value
replaces the existing value at this index.index - the index to put this value in.value - the value to put at this index.long move(int fromIndex,
int toIndex)
fromIndex followed by a put at toIndex. After this method has been called there will no longer
be any key/value assigned at fromIndex.fromIndex - the index to move the key/value from.toIndex - the index to move the key/value to.VALUE remove(int index)
index.index - the index to remove key/value from.long hopBits(int index)
....[0000,0001][0000,0100]In the above example, if we assume the index carrying these hop bits is 5, then index 5 has two neighbors: index 8 and index 14. (the least significant bit represents an offset of 1). Maximum number of hop bits is controlled by
h().
Interesting to note is that hop bits for an index and key/value are not really associated, where a key/value
can be moved to a new location, but the hop bits stay behind. The location of Hop bits
is tied to table index, whereas the location of key/value is tied to table index AND hop bits.index - the index to get the hop bits for.void putHopBit(int index,
int hd)
index - the index to add the hop bit at.hd - h-delta, i.e. which hop bit to set, zero-based.hopBits(int)void moveHopBit(int index,
int hd,
int delta)
delta steps. If delta is positive it will be moved towards msb,
if negative towards lsb.index - the index to move the hop bit for.hd - the hop bit to move.delta - how far (and based on sign) which direction to move it in.void removeHopBit(int index,
int hd)
index - the index to remove the hop bit from.hd - h-delta, i.e. which hop bit to remove, zero-based.hopBits(int)long nullKey()
h() for example, which although is final per table instance,
changes from table to table.Table<VALUE> grow()
nullKey()
after this method has been called.
The size() should be reset here as well since after it has grown then it will be re-populated
immediately with the existing data.boolean isEmpty()
true if there are no entries in this table, otherwise false.void clear()
int version()
int version(int index)
index - the index of the entry to get.index in this table.void close()
close in interface AutoCloseableCopyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.