Package org.basex.util.hash
Class TokenSet
java.lang.Object
org.basex.util.hash.ASet
org.basex.util.hash.TokenSet
- All Implemented Interfaces:
Iterable<byte[]>
- Direct Known Subclasses:
Names,TokenBoolMap,TokenIntMap,TokenMap,TokenObjMap
This is an efficient and memory-saving hash set for storing tokens.
The first entry of the token set (offset 0) is always empty.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanadd(byte[] key) Stores the specified key if it has not been stored before.final booleanStores the specified string as key if it has not been stored before.voidclear()Resets the data structure.final booleancontains(byte[] key) Checks if the set contains the specified key.protected inthash(int id) Returns the hash value of the element with the specified id.final intid(byte[] key) Returns the id of the specified key, or0if the key does not exist.final Iterator<byte[]>iterator()final byte[]key(int id) Returns the key with the specified id.final intput(byte[] key) Stores the specified key and returns its id.voidReads the data structure from the specified input.protected voidrehash(int newSize) Rehashes all entries.intremove(byte[] key) Removes the entry with the specified key.toString()voidwrite(DataOutput out) Writes the data structure to the specified output.Methods inherited from class org.basex.util.hash.ASet
capacity, checkSize, isEmpty, size, toString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
keys
protected byte[][] keysHashed keys.
-
-
Constructor Details
-
TokenSet
public TokenSet()Default constructor. -
TokenSet
public TokenSet(byte[]... key) Constructor, specifying initial keys.- Parameters:
key- initial keys
-
TokenSet
Constructor, specifying some initial input.- Parameters:
in- input stream- Throws:
IOException- I/O exception
-
-
Method Details
-
read
Reads the data structure from the specified input.- Parameters:
in- input stream- Throws:
IOException- I/O exception
-
write
Writes the data structure to the specified output.- Parameters:
out- output stream- Throws:
IOException- I/O exception
-
add
public final boolean add(byte[] key) Stores the specified key if it has not been stored before.- Parameters:
key- key to be added- Returns:
trueif the key did not exist yet and was stored
-
add
Stores the specified string as key if it has not been stored before.- Parameters:
key- string to be added- Returns:
trueif the key did not exist yet and was stored
-
put
public final int put(byte[] key) Stores the specified key and returns its id.- Parameters:
key- key to be added- Returns:
- unique id of stored key (larger than zero)
-
contains
public final boolean contains(byte[] key) Checks if the set contains the specified key.- Parameters:
key- key to be looked up- Returns:
- result of check
-
id
public final int id(byte[] key) Returns the id of the specified key, or0if the key does not exist.- Parameters:
key- key to be looked up- Returns:
- id, or
0if key does not exist
-
key
public final byte[] key(int id) Returns the key with the specified id. All ids starts with1instead of0.- Parameters:
id- id of the key to return- Returns:
- key
-
remove
public int remove(byte[] key) Removes the entry with the specified key. The deletion of keys will lead to empty entries. IfASet.sizeis called after deletions, the original number of entries will be returned.- Parameters:
key- key- Returns:
- id of the deleted key, or
0if the key did not exist
-
hash
protected int hash(int id) Description copied from class:ASetReturns the hash value of the element with the specified id. -
rehash
protected void rehash(int newSize) Description copied from class:ASetRehashes all entries. -
clear
public void clear()Description copied from class:ASetResets the data structure. -
iterator
-
toString
-