PCJ API
Version 1.2

bak.pcj.set
Class CharBitSet

java.lang.Object
  extended bybak.pcj.AbstractCharCollection
      extended bybak.pcj.set.AbstractCharSet
          extended bybak.pcj.set.CharBitSet
All Implemented Interfaces:
CharCollection, CharSet, CharSortedSet, Cloneable, Serializable

public class CharBitSet
extends AbstractCharSet
implements CharSortedSet, Cloneable, Serializable

This class represents bit array based sets of char 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 CharSortedSet is supported from PCJ 1.2. Prior to 1.2, only CharSet 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
CharBitSet()
          Creates a new empty bit set with a capacity of 64.
CharBitSet(char maximum)
          Creates a new bit set with a specified maximum value.
CharBitSet(char[] a)
          Creates a new bit set with the same elements as the specified array.
CharBitSet(CharCollection c)
          Creates a new bit set with the same elements as the specified collection.
 
Method Summary
 boolean add(char value)
          Adds an element to this set.
 void clear()
          Clears this collection.
 Object clone()
          Returns a clone of this bit set.
 boolean contains(char 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.
 char first()
          Returns the lowest element of this set.
 CharSortedSet headSet(char to)
          Returns the subset of values lower than a specified value.
 boolean isEmpty()
          Indicates whether this collection is empty.
 CharIterator iterator()
          Returns an iterator over this collection.
 char last()
          Returns the highest element of this set.
 boolean remove(char value)
          Removes a specified element from this collection.
 int size()
          Returns the number of elements in this collection.
 CharSortedSet subSet(char from, char to)
          Returns the subset of values lower that a specified value and higher than or equal to another specified value.
 CharSortedSet tailSet(char 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.AbstractCharSet
equals, hashCode
 
Methods inherited from class bak.pcj.AbstractCharCollection
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.CharCollection
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

CharBitSet

public CharBitSet(char 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.

CharBitSet

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


CharBitSet

public CharBitSet(CharCollection 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.

CharBitSet

public CharBitSet(char[] 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(char value)
Description copied from interface: CharSortedSet
Adds an element to this set.

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

iterator

public CharIterator iterator()
Description copied from interface: CharCollection
Returns an iterator over this collection.

Specified by:
iterator in interface CharCollection
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 CharCollection
Overrides:
trimToSize in class AbstractCharCollection

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: CharCollection
Clears this collection.

Specified by:
clear in interface CharCollection
Overrides:
clear in class AbstractCharCollection

contains

public boolean contains(char value)
Description copied from interface: CharCollection
Indicates whether this collection contains a specified element.

Specified by:
contains in interface CharCollection
Overrides:
contains in class AbstractCharCollection

isEmpty

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

Specified by:
isEmpty in interface CharCollection
Overrides:
isEmpty in class AbstractCharCollection

remove

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

Specified by:
remove in interface CharCollection
Overrides:
remove in class AbstractCharCollection

size

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

Specified by:
size in interface CharCollection
Overrides:
size in class AbstractCharCollection

first

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

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

last

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

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

headSet

public CharSortedSet headSet(char to)
Description copied from interface: CharSortedSet
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 CharSortedSet
Parameters:
to - the upper bound of the returned set (not included).
Since:
1.2

tailSet

public CharSortedSet tailSet(char from)
Description copied from interface: CharSortedSet
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 CharSortedSet
Parameters:
from - the lower bound of the returned set (included).
Since:
1.2

subSet

public CharSortedSet subSet(char from,
                            char to)
Description copied from interface: CharSortedSet
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 CharSortedSet
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