org.basex.util.hash
Class IntSet

java.lang.Object
  extended by org.basex.util.hash.ASet
      extended by org.basex.util.hash.IntSet
Direct Known Subclasses:
IntObjMap

public class IntSet
extends ASet

This is an efficient and memory-saving hash map for storing primitive integers. It is related to the TokenSet class.

Author:
BaseX Team 2005-13, BSD License, Christian Gruen

Field Summary
protected  int[] keys
          Hashed keys.
 
Fields inherited from class org.basex.util.hash.ASet
bucket, next, size
 
Constructor Summary
IntSet()
          Default constructor.
IntSet(int capacity)
          Default constructor.
 
Method Summary
 boolean add(int key)
          Stores the specified key if it has not been stored before.
 boolean contains(int key)
          Checks if the set contains the specified key.
 int delete(int key)
          Deletes the specified key.
protected  int hash(int id)
          Returns the hash value of the element with the specified id.
 int id(int key)
          Returns the id of the specified key, or 0 if the key does not exist.
 int key(int id)
          Returns the key with the specified id.
 int put(int key)
          Stores the specified key and returns its id.
protected  void rehash(int newSize)
          Rehashes all entries.
 int[] toArray()
          Returns an array with all elements.
 
Methods inherited from class org.basex.util.hash.ASet
checkSize, clear, isEmpty, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keys

protected int[] keys
Hashed keys.

Constructor Detail

IntSet

public IntSet()
Default constructor.


IntSet

public IntSet(int capacity)
Default constructor.

Parameters:
capacity - initial array capacity
Method Detail

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:
if the key did not exist yet and was stored

put

public final int put(int 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(int 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(int key)
Returns the id of the specified key, or 0 if the key does not exist.

Parameters:
key - key to be looked up
Returns:
id, or 0 if key does not exist

key

public final int key(int id)
Returns the key with the specified id. All ids starts with 1 instead of 0.

Parameters:
id - id of the key to return
Returns:
key

delete

public int delete(int key)
Deletes the specified key. The deletion of keys will lead to empty entries. If ASet.size is called after deletions, the original number of entries will be returned.

Parameters:
key - key
Returns:
deleted key or 0

hash

protected int hash(int id)
Description copied from class: ASet
Returns the hash value of the element with the specified id.

Specified by:
hash in class ASet
Parameters:
id - id of the element
Returns:
hash value

rehash

protected void rehash(int newSize)
Description copied from class: ASet
Rehashes all entries.

Specified by:
rehash in class ASet
Parameters:
newSize - new hash size

toArray

public final int[] toArray()
Returns an array with all elements.

Returns:
array