uka.util
Class IntOpenHashSet

java.lang.Object
  extended byuka.util.IntOpenHashSet
All Implemented Interfaces:
java.lang.Cloneable, Printable, java.io.Serializable

public class IntOpenHashSet
extends java.lang.Object
implements Printable, java.lang.Cloneable, java.io.Serializable

This class represents open addressing hash table based sets of int values. Unlike the Java Collections HashSet instances of this class are not backed up by a map. It is implemented using a simple open addressing hash table where the keys are stored directly as entries.

Since:
1.0
Version:
1.3 22-08-2003 20:19
Author:
Søren Bak
See Also:
IntOpenHashSet, HashSet, Serialized Form

Field Summary
private  int[] data
          The hash table backing up this set.
static int DEFAULT_CAPACITY
          The default capacity of this set.
static int DEFAULT_GROWTH_CHUNK
          The default chunk size with which to increase the capacity of this set.
static double DEFAULT_GROWTH_FACTOR
          The default factor with which to increase the capacity of this set.
private static int DEFAULT_GROWTH_POLICY
          The default growth policy of this set.
static double DEFAULT_LOAD_FACTOR
          The default load factor of this set.
private static byte EMPTY
           
private  int expandAt
          The next size at which to expand the keys[].
private static int GROWTH_POLICY_ABSOLUTE
          Constant indicating absolute growth policy.
private static int GROWTH_POLICY_RELATIVE
          Constant indicating relative growth policy.
private  int growthChunk
          The growth chunk size of this set, if the growth policy is absolute.
private  double growthFactor
          The growth factor of this set, if the growth policy is relative.
private  int growthPolicy
          The growth policy of this set (0 is relative growth, 1 is absolute growth).
private  IntHashFunction keyhash
          The hash function used to hash keys in this set.
private  double loadFactor
          The load factor of this set.
private static byte OCCUPIED
           
private static byte REMOVED
           
private  int size
          The size of this set.
private  byte[] states
          The states of each cell in the keys[].
private  int used
          The number of entries in use (removed or occupied).
 
Constructor Summary
  IntOpenHashSet()
          Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.
  IntOpenHashSet(double loadFactor)
          Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.
  IntOpenHashSet(int capacity)
          Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.
  IntOpenHashSet(int[] a)
          Creates a new hash set with the same elements as the specified array.
  IntOpenHashSet(int capacity, double loadFactor)
          Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.
  IntOpenHashSet(int capacity, double loadFactor, double growthFactor)
          Creates a new hash set with a specified capacity, load factor, and relative growth factor.
  IntOpenHashSet(int capacity, double loadFactor, int growthChunk)
          Creates a new hash set with a specified capacity, load factor, and absolute growth factor.
  IntOpenHashSet(IntHashFunction keyhash)
          Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.
  IntOpenHashSet(IntHashFunction keyhash, double loadFactor)
          Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.
  IntOpenHashSet(IntHashFunction keyhash, int capacity)
          Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.
  IntOpenHashSet(IntHashFunction keyhash, int capacity, double loadFactor)
          Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.
  IntOpenHashSet(IntHashFunction keyhash, int capacity, double loadFactor, double growthFactor)
          Creates a new hash set with a specified capacity, load factor, and relative growth factor.
  IntOpenHashSet(IntHashFunction keyhash, int capacity, double loadFactor, int growthChunk)
          Creates a new hash set with a specified capacity, load factor, and absolute growth factor.
private IntOpenHashSet(IntHashFunction keyhash, int capacity, int growthPolicy, double growthFactor, int growthChunk, double loadFactor)
           
private IntOpenHashSet(int capacity, int growthPolicy, double growthFactor, int growthChunk, double loadFactor)
           
 
Method Summary
 boolean add(int v)
           
 void appendTo(ToString s)
          This method should append the contents of each instance variable of the current object to the given ToString object.
 void applyPermutation(Permutation permutation)
           
 void clear()
           
 java.lang.Object clone()
          Returns a clone of this hash set.
 boolean contains(int v)
           
private  void ensureCapacity()
           
 boolean isEmpty()
           
 IntIterator iterator()
           
private  void readObject(java.io.ObjectInputStream s)
           
 boolean remove(int v)
           
 int size()
           
 EnlargingIntArray toArray(EnlargingIntArray a)
           
 int[] toArray(int[] a)
           
 java.lang.String toString()
          Returns a string representation of this collection.
private  java.lang.String toStringState(int state)
           
 void trimToSize()
           
private  void writeObject(java.io.ObjectOutputStream s)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GROWTH_POLICY_RELATIVE

private static final int GROWTH_POLICY_RELATIVE
Constant indicating relative growth policy.

See Also:
Constant Field Values

GROWTH_POLICY_ABSOLUTE

private static final int GROWTH_POLICY_ABSOLUTE
Constant indicating absolute growth policy.

See Also:
Constant Field Values

DEFAULT_GROWTH_POLICY

private static final int DEFAULT_GROWTH_POLICY
The default growth policy of this set.

See Also:
GROWTH_POLICY_RELATIVE, GROWTH_POLICY_ABSOLUTE, Constant Field Values

DEFAULT_GROWTH_FACTOR

public static final double DEFAULT_GROWTH_FACTOR
The default factor with which to increase the capacity of this set.

See Also:
Constant Field Values

DEFAULT_GROWTH_CHUNK

public static final int DEFAULT_GROWTH_CHUNK
The default chunk size with which to increase the capacity of this set.

See Also:
Constant Field Values

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
The default capacity of this set.

See Also:
Constant Field Values

DEFAULT_LOAD_FACTOR

public static final double DEFAULT_LOAD_FACTOR
The default load factor of this set.

See Also:
Constant Field Values

keyhash

private IntHashFunction keyhash
The hash function used to hash keys in this set.


size

private int size
The size of this set.


data

private transient int[] data
The hash table backing up this set. Contains set values directly. Due to the use of a secondary hash function, the length of this array must be a prime.


states

private transient byte[] states
The states of each cell in the keys[].


EMPTY

private static final byte EMPTY
See Also:
Constant Field Values

OCCUPIED

private static final byte OCCUPIED
See Also:
Constant Field Values

REMOVED

private static final byte REMOVED
See Also:
Constant Field Values

used

private transient int used
The number of entries in use (removed or occupied).


growthPolicy

private int growthPolicy
The growth policy of this set (0 is relative growth, 1 is absolute growth).


growthFactor

private double growthFactor
The growth factor of this set, if the growth policy is relative.


growthChunk

private int growthChunk
The growth chunk size of this set, if the growth policy is absolute.


loadFactor

private double loadFactor
The load factor of this set.


expandAt

private int expandAt
The next size at which to expand the keys[].

Constructor Detail

IntOpenHashSet

private IntOpenHashSet(IntHashFunction keyhash,
                       int capacity,
                       int growthPolicy,
                       double growthFactor,
                       int growthChunk,
                       double loadFactor)

IntOpenHashSet

private IntOpenHashSet(int capacity,
                       int growthPolicy,
                       double growthFactor,
                       int growthChunk,
                       double loadFactor)

IntOpenHashSet

public IntOpenHashSet()
Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.


IntOpenHashSet

public IntOpenHashSet(int[] a)
Creates a new hash set with the same elements as the specified array.

Parameters:
a - the array whose elements to add to the new set.
Throws:
java.lang.NullPointerException - if a is null.
Since:
1.1

IntOpenHashSet

public IntOpenHashSet(int capacity)
Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.

Parameters:
capacity - the initial capacity of the set.
Throws:
java.lang.IllegalArgumentException - if capacity is negative.

IntOpenHashSet

public IntOpenHashSet(double loadFactor)
Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.

Parameters:
loadFactor - the load factor of the set.
Throws:
java.lang.IllegalArgumentException - if loadFactor is negative or zero.

IntOpenHashSet

public IntOpenHashSet(int capacity,
                      double loadFactor)
Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.

Parameters:
capacity - the initial capacity of the set.
loadFactor - the load factor of the set.
Throws:
java.lang.IllegalArgumentException - if capacity is negative; if loadFactor is not positive.

IntOpenHashSet

public IntOpenHashSet(int capacity,
                      double loadFactor,
                      double growthFactor)
Creates a new hash set with a specified capacity, load factor, and relative growth factor.

The set capacity increases to capacity()*(1+growthFactor). This strategy is good for avoiding many capacity increases, but the amount of wasted memory is approximately the size of the set.

Parameters:
capacity - the initial capacity of the set.
loadFactor - the load factor of the set.
growthFactor - the relative amount with which to increase the the capacity when a capacity increase is needed.
Throws:
java.lang.IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthFactor is not positive.

IntOpenHashSet

public IntOpenHashSet(int capacity,
                      double loadFactor,
                      int growthChunk)
Creates a new hash set with a specified capacity, load factor, and absolute growth factor.

The set capacity increases to capacity()+growthChunk. This strategy is good for avoiding wasting memory. However, an overhead is potentially introduced by frequent capacity increases.

Parameters:
capacity - the initial capacity of the set.
loadFactor - the load factor of the set.
growthChunk - the absolute amount with which to increase the the capacity when a capacity increase is needed.
Throws:
java.lang.IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthChunk is not positive.

IntOpenHashSet

public IntOpenHashSet(IntHashFunction keyhash)
Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.

Parameters:
keyhash - the hash function to use when hashing keys.
Throws:
java.lang.NullPointerException - if keyhash is null.

IntOpenHashSet

public IntOpenHashSet(IntHashFunction keyhash,
                      int capacity)
Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.

Parameters:
keyhash - the hash function to use when hashing keys.
capacity - the initial capacity of the set.
Throws:
java.lang.IllegalArgumentException - if capacity is negative.
java.lang.NullPointerException - if keyhash is null.

IntOpenHashSet

public IntOpenHashSet(IntHashFunction keyhash,
                      double loadFactor)
Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.

Parameters:
keyhash - the hash function to use when hashing keys.
loadFactor - the load factor of the set.
Throws:
java.lang.IllegalArgumentException - if loadFactor is negative or zero.
java.lang.NullPointerException - if keyhash is null.

IntOpenHashSet

public IntOpenHashSet(IntHashFunction keyhash,
                      int capacity,
                      double loadFactor)
Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.

Parameters:
keyhash - the hash function to use when hashing keys.
capacity - the initial capacity of the set.
loadFactor - the load factor of the set.
Throws:
java.lang.IllegalArgumentException - if capacity is negative; if loadFactor is not positive.
java.lang.NullPointerException - if keyhash is null.

IntOpenHashSet

public IntOpenHashSet(IntHashFunction keyhash,
                      int capacity,
                      double loadFactor,
                      double growthFactor)
Creates a new hash set with a specified capacity, load factor, and relative growth factor.

The set capacity increases to capacity()*(1+growthFactor). This strategy is good for avoiding many capacity increases, but the amount of wasted memory is approximately the size of the set.

Parameters:
keyhash - the hash function to use when hashing keys.
capacity - the initial capacity of the set.
loadFactor - the load factor of the set.
growthFactor - the relative amount with which to increase the the capacity when a capacity increase is needed.
Throws:
java.lang.IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthFactor is not positive.
java.lang.NullPointerException - if keyhash is null.

IntOpenHashSet

public IntOpenHashSet(IntHashFunction keyhash,
                      int capacity,
                      double loadFactor,
                      int growthChunk)
Creates a new hash set with a specified capacity, load factor, and absolute growth factor.

Parameters:
keyhash - the hash function to use when hashing keys.

The set capacity increases to capacity()+growthChunk. This strategy is good for avoiding wasting memory. However, an overhead is potentially introduced by frequent capacity increases.

capacity - the initial capacity of the set.
loadFactor - the load factor of the set.
growthChunk - the absolute amount with which to increase the the capacity when a capacity increase is needed.
Throws:
java.lang.IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthChunk is not positive.
java.lang.NullPointerException - if keyhash is null.
Method Detail

ensureCapacity

private void ensureCapacity()

add

public boolean add(int v)

iterator

public IntIterator iterator()

applyPermutation

public void applyPermutation(Permutation permutation)

trimToSize

public void trimToSize()

clone

public java.lang.Object clone()
Returns a clone of this hash set.

Returns:
a clone of this hash set.
Since:
1.1

size

public int size()

isEmpty

public boolean isEmpty()

clear

public void clear()

contains

public boolean contains(int v)

remove

public boolean remove(int v)

toArray

public int[] toArray(int[] a)

toArray

public EnlargingIntArray toArray(EnlargingIntArray a)

writeObject

private void writeObject(java.io.ObjectOutputStream s)
                  throws java.io.IOException
Throws:
java.io.IOException
Since:
1.1

readObject

private void readObject(java.io.ObjectInputStream s)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException
Since:
1.1

toString

public java.lang.String toString()
Returns a string representation of this collection.

Returns:
a string representation of this collection.

appendTo

public void appendTo(ToString s)
Description copied from interface: Printable
This method should append the contents of each instance variable of the current object to the given ToString object. The appended data should be labeled with the name of the corresponding instance variable.

Specified by:
appendTo in interface Printable
See Also:
ToString, ToString.append(String, Object), ToString.append(String, boolean), ToString.append(String, byte), ToString.append(String, int)

toStringState

private java.lang.String toStringState(int state)