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
FieldsModifier and TypeFieldDescriptionprotected intThe number of slots in the table (always a power of two).protected intlength− 1.protected ZFastTrie.InternalNode<U>[]The node table.protected long[]The signature of the handle of the corresponding entrynode.protected intThe number of elements in the table.protected final it.unimi.dsi.bits.TransformationStrategy<? super U> The transformation strategy. -
Constructor Summary
ConstructorsConstructorDescriptionHandle2NodeMap(int size, it.unimi.dsi.bits.TransformationStrategy<? super U> transform) Creates a new handle-to-node map using a given transformation strategy and expected number of elements.Handle2NodeMap(it.unimi.dsi.bits.TransformationStrategy<? super U> transform) Creates a new handle-to-node map using a given transformation strategy. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new entry to the table.voidaddNew(ZFastTrie.InternalNode<U> n, long s) Adds a new entry to the table.protected voidvoidclear()protected ZFastTrie.InternalNode<U> find(it.unimi.dsi.bits.BitVector v, long handleLength, long[] state) Find a node with given handle using signatures.protected ZFastTrie.InternalNode<U> findExact(it.unimi.dsi.bits.BitVector v, long handleLength, long[] state) Find a node with given handle using handles.get(it.unimi.dsi.bits.BitVector handle) Retrieves a node given its handle.protected inthash(long s) Generates a hash table position starting from a signature.it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.bits.LongArrayBitVector> keySet()voidremoveExisting(ZFastTrie.InternalNode<U> n, long s) Removes an existing entry from the table.voidreplaceExisting(ZFastTrie.InternalNode<U> oldNode, ZFastTrie.InternalNode<U> newNode, long s) Replaces an entry with a given node.intsize()toString()it.unimi.dsi.fastutil.objects.ObjectSet<ZFastTrie.Node<U>> 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
protected ZFastTrie.InternalNode<U> find(it.unimi.dsi.bits.BitVector v, long handleLength, long[] state) 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 ofvthat will be used as a handle.state- the hash state ofvprecomputed byHashes.preprocessMurmur(BitVector, long).- Returns:
- a node with the specified handle signature, or
null.
-
findExact
protected ZFastTrie.InternalNode<U> findExact(it.unimi.dsi.bits.BitVector v, long handleLength, long[] state) 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 ofvthat will be used as a handle.state- the hash state ofvprecomputed byHashes.preprocessMurmur(BitVector, long).- Returns:
- a node with the specified handle, or
null.
-
clear
public void clear() -
keySet
public it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.bits.LongArrayBitVector> 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 ofoldNodeandnewNode.
-
removeExisting
Removes an existing entry from the table.- Parameters:
n- the node to be removed.s- the signature of the handle ofn.- Throws:
IllegalStateException- ifnis 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
nullif there is no such node (ifexactis false, a false positive might be returned).
-
toString
-