Package org.basex.util.hash
Class ASet
java.lang.Object
org.basex.util.hash.ASet
- Direct Known Subclasses:
HashItemSet,IntSet,QNmSet,TokenSet
This is the basic structure of an efficient and memory-saving hash set.
The first entry of the token set (offset 0) will always be kept empty.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final intcapacity()Returns the current array capacity.protected final voidResizes the hash table.protected voidclear()Resets the data structure.protected abstract inthash(int id) Returns the hash value of the element with the specified id.final booleanisEmpty()Tests is the set is empty.protected abstract voidrehash(int newSize) Rehashes all entries.final intsize()Returns the number of entries.Returns a string representation of the set or map.Returns a string representation of the set or map.
-
Field Details
-
buckets
protected int[] bucketsHash table buckets. -
next
protected int[] nextPointers to the next entry. -
size
protected int sizeHash entries. The actual number of entries issize - 1.
-
-
Constructor Details
-
ASet
protected ASet()Empty constructor. -
ASet
protected ASet(long capacity) Constructor with initial capacity.- Parameters:
capacity- array capacity (will be resized to a power of two)
-
-
Method Details
-
clear
protected void clear()Resets the data structure. -
size
public final int size()Returns the number of entries. The actual number of keys may be smaller if keys have been deleted.- Returns:
- number of entries
-
isEmpty
public final boolean isEmpty()Tests is the set is empty.- Returns:
- result of check
-
checkSize
protected final void checkSize()Resizes the hash table. -
capacity
protected final int capacity()Returns the current array capacity.- Returns:
- array capacity
-
hash
protected abstract int hash(int id) Returns the hash value of the element with the specified id.- Parameters:
id- id of the element- Returns:
- hash value
-
rehash
protected abstract void rehash(int newSize) Rehashes all entries.- Parameters:
newSize- new hash size
-
toString
Returns a string representation of the set or map.- Parameters:
keys- hash keys- Returns:
- string
-
toString
Returns a string representation of the set or map.- Parameters:
keys- hash keysvalues- hash values ornull- Returns:
- string
-