Package it.unimi.dsi.sux4j.util
Class ZFastTrie.Handle2NodeMap<U>
java.lang.Object
it.unimi.dsi.sux4j.util.ZFastTrie.Handle2NodeMap<U>
A linear-probing hash map that compares keys using signatures as a first try.
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
The number of slots in the table (always a power of two).protected int
length
− 1.protected ZFastTrie.InternalNode<U>[]
The node table.protected long[]
The signature of the handle of the corresponding entrynode
.protected int
The number of elements in the table.protected final TransformationStrategy<? super U>
The transformation strategy. -
Constructor Summary
ConstructorDescriptionHandle2NodeMap
(int size, TransformationStrategy<? super U> transform) Creates a new handle-to-node map using a given transformation strategy and expected number of elements.Handle2NodeMap
(TransformationStrategy<? super U> transform) Creates a new handle-to-node map using a given transformation strategy. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new entry to the table.void
addNew
(ZFastTrie.InternalNode<U> n, long s) Adds a new entry to the table.protected void
void
clear()
protected ZFastTrie.InternalNode<U>
Find a node with given handle using signatures.protected ZFastTrie.InternalNode<U>
Find a node with given handle using handles.Retrieves a node given its handle.protected int
hash
(long s) Generates a hash table position starting from a signature.keySet()
void
removeExisting
(ZFastTrie.InternalNode<U> n, long s) Removes an existing entry from the table.void
replaceExisting
(ZFastTrie.InternalNode<U> oldNode, ZFastTrie.InternalNode<U> newNode, long s) Replaces an entry with a given node.int
size()
toString()
values()
-
Field Details
-
transform
The transformation strategy. -
node
The node table. -
signature
protected long[] signatureThe signature of the handle of the corresponding entrynode
. -
size
protected int sizeThe number of elements in the table. -
length
protected int lengthThe number of slots in the table (always a power of two). -
mask
protected int masklength
− 1.
-
-
Constructor Details
-
Handle2NodeMap
Creates a new handle-to-node map using a given transformation strategy and expected number of elements.- Parameters:
size
- the expected number of elements.transform
- the transformation strategy used for this map.
-
Handle2NodeMap
Creates a new handle-to-node map using a given transformation strategy.- Parameters:
transform
- the transformation strategy used for this map.
-
-
Method Details
-
assertTable
protected void assertTable() -
hash
protected int hash(long s) Generates a hash table position starting from a signature.- Parameters:
s
- a signature.- Returns:
- the hash table position of
s
.
-
find
Find a node with given handle using signatures.Note that this function just compares signatures (except for duplicates, which are checked explicitly). Thus, it might return false positives when queried with keys that are not handles. Nonetheless, it will always return a correct result on a handle.
- Parameters:
v
- a bit vector.handleLength
- the length of the prefix ofv
that will be used as a handle.state
- the hash state ofv
precomputed byHashes.preprocessMurmur(BitVector, long)
.- Returns:
- a node with the specified handle signature, or
null
.
-
findExact
Find a node with given handle using handles.Note that this function compares handles. Thus, it always returns a correct value.
- Parameters:
v
- a bit vector.handleLength
- the length of the prefix ofv
that will be used as a handle.state
- the hash state ofv
precomputed byHashes.preprocessMurmur(BitVector, long)
.- Returns:
- a node with the specified handle, or
null
.
-
clear
public void clear() -
keySet
-
values
-
replaceExisting
public void replaceExisting(ZFastTrie.InternalNode<U> oldNode, ZFastTrie.InternalNode<U> newNode, long s) Replaces an entry with a given node.- Parameters:
oldNode
- a node appearing in the table.newNode
- a node with the same handle asoldNode
.s
- the signature of the handle ofoldNode
andnewNode
.
-
removeExisting
Removes an existing entry from the table.- Parameters:
n
- the node to be removed.s
- the signature of the handle ofn
.- Throws:
IllegalStateException
- ifn
is not in the table.
-
addNew
Adds a new entry to the table.- Parameters:
v
- a node.- See Also:
-
addNew
Adds a new entry to the table.Note that as long as the handle of the given node is not in the table this function will always perform correctly. Otherwise, the table will end up containing two copies of the same key (i.e., handle).
- Parameters:
n
- a node.s
- the signature of the handle ofn
.
-
size
public int size() -
get
Retrieves a node given its handle.- Parameters:
handle
- a handle.- Returns:
- the node with given handle, or
null
if there is no such node (ifexact
is false, a false positive might be returned).
-
toString
-