PCJ API
Version 1.2

bak.pcj.set
Class ByteOpenHashSet

java.lang.Object
  extended bybak.pcj.AbstractByteCollection
      extended bybak.pcj.set.AbstractByteSet
          extended bybak.pcj.set.ByteOpenHashSet
All Implemented Interfaces:
ByteCollection, ByteSet, Cloneable, Serializable

public class ByteOpenHashSet
extends AbstractByteSet
implements ByteSet, Cloneable, Serializable

This class represents open addressing hash table based sets of byte 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
See Also:
ByteOpenHashSet, HashSet, Serialized Form

Field Summary
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.
static double DEFAULT_LOAD_FACTOR
          The default load factor of this set.
 
Constructor Summary
ByteOpenHashSet()
          Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.
ByteOpenHashSet(byte[] a)
          Creates a new hash set with the same elements as the specified array.
ByteOpenHashSet(ByteCollection c)
          Creates a new hash set with the same elements as a specified collection.
ByteOpenHashSet(ByteHashFunction keyhash)
          Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.
ByteOpenHashSet(ByteHashFunction 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.
ByteOpenHashSet(ByteHashFunction 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%.
ByteOpenHashSet(ByteHashFunction 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.
ByteOpenHashSet(ByteHashFunction keyhash, int capacity, double loadFactor, double growthFactor)
          Creates a new hash set with a specified capacity, load factor, and relative growth factor.
ByteOpenHashSet(ByteHashFunction keyhash, int capacity, double loadFactor, int growthChunk)
          Creates a new hash set with a specified capacity, load factor, and absolute growth factor.
ByteOpenHashSet(double loadFactor)
          Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.
ByteOpenHashSet(int capacity)
          Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.
ByteOpenHashSet(int capacity, double loadFactor)
          Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.
ByteOpenHashSet(int capacity, double loadFactor, double growthFactor)
          Creates a new hash set with a specified capacity, load factor, and relative growth factor.
ByteOpenHashSet(int capacity, double loadFactor, int growthChunk)
          Creates a new hash set with a specified capacity, load factor, and absolute growth factor.
 
Method Summary
 boolean add(byte v)
          Adds an element to this collection.
 void clear()
          Clears this collection.
 Object clone()
          Returns a clone of this hash set.
 boolean contains(byte v)
          Indicates whether this collection contains a specified element.
 int hashCode()
          Returns a hash code value for this collection.
 ByteIterator iterator()
          Returns an iterator over this collection.
 boolean remove(byte v)
          Removes a specified element from this collection.
 int size()
          Returns the number of elements in this collection.
 byte[] toArray(byte[] a)
          Returns the elements of this collection as an array.
 void trimToSize()
          Minimizes the memory used by this collection.
 
Methods inherited from class bak.pcj.set.AbstractByteSet
equals
 
Methods inherited from class bak.pcj.AbstractByteCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface bak.pcj.ByteCollection
addAll, containsAll, equals, isEmpty, removeAll, retainAll, toArray
 

Field Detail

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
Constructor Detail

ByteOpenHashSet

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


ByteOpenHashSet

public ByteOpenHashSet(ByteCollection c)
Creates a new hash set with the same elements as a specified collection.

Parameters:
c - the collection whose elements to add to the new set.
Throws:
NullPointerException - if c is null.

ByteOpenHashSet

public ByteOpenHashSet(byte[] 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:
NullPointerException - if a is null.
Since:
1.1

ByteOpenHashSet

public ByteOpenHashSet(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:
IllegalArgumentException - if capacity is negative.

ByteOpenHashSet

public ByteOpenHashSet(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:
IllegalArgumentException - if loadFactor is negative or zero.

ByteOpenHashSet

public ByteOpenHashSet(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:
IllegalArgumentException - if capacity is negative; if loadFactor is not positive.

ByteOpenHashSet

public ByteOpenHashSet(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:
IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthFactor is not positive.

ByteOpenHashSet

public ByteOpenHashSet(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:
IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthChunk is not positive.

ByteOpenHashSet

public ByteOpenHashSet(ByteHashFunction 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:
NullPointerException - if keyhash is null.

ByteOpenHashSet

public ByteOpenHashSet(ByteHashFunction 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:
IllegalArgumentException - if capacity is negative.
NullPointerException - if keyhash is null.

ByteOpenHashSet

public ByteOpenHashSet(ByteHashFunction 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:
IllegalArgumentException - if loadFactor is negative or zero.
NullPointerException - if keyhash is null.

ByteOpenHashSet

public ByteOpenHashSet(ByteHashFunction 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:
IllegalArgumentException - if capacity is negative; if loadFactor is not positive.
NullPointerException - if keyhash is null.

ByteOpenHashSet

public ByteOpenHashSet(ByteHashFunction 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:
IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthFactor is not positive.
NullPointerException - if keyhash is null.

ByteOpenHashSet

public ByteOpenHashSet(ByteHashFunction 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:
IllegalArgumentException - if capacity is negative; if loadFactor is not positive; if growthChunk is not positive.
NullPointerException - if keyhash is null.
Method Detail

add

public boolean add(byte v)
Description copied from interface: ByteCollection
Adds an element to this collection.

Specified by:
add in interface ByteCollection
Overrides:
add in class AbstractByteCollection

iterator

public ByteIterator iterator()
Description copied from interface: ByteCollection
Returns an iterator over this collection.

Specified by:
iterator in interface ByteCollection
Returns:
an iterator over this collection.

trimToSize

public void trimToSize()
Description copied from interface: ByteCollection
Minimizes the memory used by this collection. The exact operation of this method depends on the class implementing it. Implementors may choose to ignore it completely.

Specified by:
trimToSize in interface ByteCollection
Overrides:
trimToSize in class AbstractByteCollection

clone

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

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

size

public int size()
Description copied from interface: ByteCollection
Returns the number of elements in this collection.

Specified by:
size in interface ByteCollection
Overrides:
size in class AbstractByteCollection

clear

public void clear()
Description copied from interface: ByteCollection
Clears this collection.

Specified by:
clear in interface ByteCollection
Overrides:
clear in class AbstractByteCollection

contains

public boolean contains(byte v)
Description copied from interface: ByteCollection
Indicates whether this collection contains a specified element.

Specified by:
contains in interface ByteCollection
Overrides:
contains in class AbstractByteCollection

hashCode

public int hashCode()
Description copied from interface: ByteCollection
Returns a hash code value for this collection.

Specified by:
hashCode in interface ByteCollection
Overrides:
hashCode in class AbstractByteSet

remove

public boolean remove(byte v)
Description copied from interface: ByteCollection
Removes a specified element from this collection.

Specified by:
remove in interface ByteCollection
Overrides:
remove in class AbstractByteCollection

toArray

public byte[] toArray(byte[] a)
Description copied from interface: ByteCollection
Returns the elements of this collection as an array.

Specified by:
toArray in interface ByteCollection
Overrides:
toArray in class AbstractByteCollection

PCJ API
Version 1.2

Report a bug or request a feature.
Further information on the development and latest release of PCJ can be found at the project homepage.

Primitive Collections for Java is released under the GNU Lesser General Public License.
Copyright © 2002, 2003 Søren Bak. All Rights Reserved.

Hosted by SourceForge.net
SourceForge.net Logo