Package org.basex.util.hash
Class IntSet
java.lang.Object
org.basex.util.hash.ASet
org.basex.util.hash.IntSet
This is an efficient and memory-saving hash set for storing primitive integers.
It is related to the
TokenSet class.- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanadd(int key) Stores the specified key if it has not been stored before.final booleancontains(int 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 intkey(int id) Returns the key with the specified id.protected voidrehash(int newSize) Rehashes all entries.final int[]toArray()Returns an array with all elements.toString()
-
Constructor Details
-
IntSet
public IntSet()Default constructor. -
IntSet
public IntSet(long capacity) Constructor with initial capacity.- Parameters:
capacity- array capacity (will be resized to a power of two)
-
-
Method Details
-
add
public final boolean add(int 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
-
contains
public final boolean contains(int key) Checks if the set contains the specified key.- Parameters:
key- key to be looked up- Returns:
- result of check
-
key
public final int 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
-
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. -
toArray
public final int[] toArray()Returns an array with all elements.- Returns:
- array
-
toString
-