PCJ API
Version 1.2

bak.pcj.set
Class ByteBitSet

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

public class ByteBitSet
extends AbstractByteSet
implements ByteSortedSet, Cloneable, Serializable

This class represents bit array based sets of byte values. When a bit in the underlying array is set, the value having the same number as the bit is contained in the array. This implies that bit sets cannot contain negative values.

Implementation of ByteSortedSet is supported from PCJ 1.2. Prior to 1.2, only ByteSet was implemented.

Note: There is no growth policy involved with bit sets. The number of bits to use depends on the value of the largest element and not the size of the set. While sizes are predictable (they grow), a new maximum element is generally not predictable making it meaningless to grow the array at a specific rate.

Since:
1.0
See Also:
Serialized Form

Constructor Summary
ByteBitSet()
          Creates a new empty bit set with a capacity of 64.
ByteBitSet(byte maximum)
          Creates a new bit set with a specified maximum value.
ByteBitSet(byte[] a)
          Creates a new bit set with the same elements as the specified array.
ByteBitSet(ByteCollection c)
          Creates a new bit set with the same elements as the specified collection.
 
Method Summary
 boolean add(byte value)
          Adds an element to this set.
 void clear()
          Clears this collection.
 Object clone()
          Returns a clone of this bit set.
 boolean contains(byte value)
          Indicates whether this collection contains a specified element.
 void ensureCapacity(int maximum)
          Ensures that this bit set can contain a specified maximum element without increasing the capacity.
 byte first()
          Returns the lowest element of this set.
 ByteSortedSet headSet(byte to)
          Returns the subset of values lower than a specified value.
 boolean isEmpty()
          Indicates whether this collection is empty.
 ByteIterator iterator()
          Returns an iterator over this collection.
 byte last()
          Returns the highest element of this set.
 boolean remove(byte value)
          Removes a specified element from this collection.
 int size()
          Returns the number of elements in this collection.
 ByteSortedSet subSet(byte from, byte to)
          Returns the subset of values lower that a specified value and higher than or equal to another specified value.
 ByteSortedSet tailSet(byte from)
          Returns the subset of values higher than or equal to a specified value.
 void trimToSize()
          Minimizes the memory used by this bit set.
 
Methods inherited from class bak.pcj.set.AbstractByteSet
equals, hashCode
 
Methods inherited from class bak.pcj.AbstractByteCollection
addAll, containsAll, removeAll, retainAll, toArray, 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, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

ByteBitSet

public ByteBitSet(byte maximum)
Creates a new bit set with a specified maximum value.

Parameters:
maximum - the maximum value representable by the new bitset.
Throws:
IllegalArgumentException - if capacity is negative.

ByteBitSet

public ByteBitSet()
Creates a new empty bit set with a capacity of 64.


ByteBitSet

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

Parameters:
c - the collection whose elements to add to the new bit set.
Throws:
NullPointerException - if c is null.
IllegalArgumentException - if any of the elements of the specified collection is negative.

ByteBitSet

public ByteBitSet(byte[] a)
Creates a new bit set with the same elements as the specified array.

Parameters:
a - the array whose elements to add to the new bit set.
Throws:
NullPointerException - if a is null.
IllegalArgumentException - if any of the elements of the specified array is negative.
Since:
1.1
Method Detail

ensureCapacity

public void ensureCapacity(int maximum)
Ensures that this bit set can contain a specified maximum element without increasing the capacity. If many elements are added, and the maximum element among those is known before they are added, this method may improve performance.

Parameters:
maximum - the maximum element that this set should be able to contain without increasing the capacity.
Throws:
IllegalArgumentException - if maximum is negative.

add

public boolean add(byte value)
Description copied from interface: ByteSortedSet
Adds an element to this set.

Specified by:
add in interface ByteSortedSet
Overrides:
add in class AbstractByteCollection
Throws:
IllegalArgumentException - if value is negative.

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()
Minimizes the memory used by this bit set. The underlying array is replaced by an array whose size corresponds to the maximum elements in this bit set. The method can be used to free up memory after many removals.

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

clone

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

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

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 value)
Description copied from interface: ByteCollection
Indicates whether this collection contains a specified element.

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

isEmpty

public boolean isEmpty()
Description copied from interface: ByteCollection
Indicates whether this collection is empty.

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

remove

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

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

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

first

public byte first()
Description copied from interface: ByteSortedSet
Returns the lowest element of this set.

Specified by:
first in interface ByteSortedSet
Returns:
the lowest element of this set.
Since:
1.2

last

public byte last()
Description copied from interface: ByteSortedSet
Returns the highest element of this set.

Specified by:
last in interface ByteSortedSet
Returns:
the highest element of this set.
Since:
1.2

headSet

public ByteSortedSet headSet(byte to)
Description copied from interface: ByteSortedSet
Returns the subset of values lower than a specified value. The returned subset is a view of this set, so changes to the subset are reflected by this set and vice versa.

Specified by:
headSet in interface ByteSortedSet
Parameters:
to - the upper bound of the returned set (not included).
Since:
1.2

tailSet

public ByteSortedSet tailSet(byte from)
Description copied from interface: ByteSortedSet
Returns the subset of values higher than or equal to a specified value. The returned subset is a view of this set, so changes to the subset are reflected by this set and vice versa.

Specified by:
tailSet in interface ByteSortedSet
Parameters:
from - the lower bound of the returned set (included).
Since:
1.2

subSet

public ByteSortedSet subSet(byte from,
                            byte to)
Description copied from interface: ByteSortedSet
Returns the subset of values lower that a specified value and higher than or equal to another specified value. The returned subset is a view of this set, so changes to the subset are reflected by this set and vice versa.

Specified by:
subSet in interface ByteSortedSet
Parameters:
from - the lower bound of the returned set (included).
to - the upper bound of the returned set (not included).
Since:
1.2

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