PCJ API
Version 1.2

bak.pcj.set
Class IntBitSet

java.lang.Object
  extended bybak.pcj.AbstractIntCollection
      extended bybak.pcj.set.AbstractIntSet
          extended bybak.pcj.set.IntBitSet
All Implemented Interfaces:
Cloneable, IntCollection, IntSet, IntSortedSet, Serializable

public class IntBitSet
extends AbstractIntSet
implements IntSortedSet, Cloneable, Serializable

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

Constructor Detail

IntBitSet

public IntBitSet(int 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.

IntBitSet

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


IntBitSet

public IntBitSet(IntCollection 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.

IntBitSet

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

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

iterator

public IntIterator iterator()
Description copied from interface: IntCollection
Returns an iterator over this collection.

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

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

Specified by:
clear in interface IntCollection
Overrides:
clear in class AbstractIntCollection

contains

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

Specified by:
contains in interface IntCollection
Overrides:
contains in class AbstractIntCollection

isEmpty

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

Specified by:
isEmpty in interface IntCollection
Overrides:
isEmpty in class AbstractIntCollection

remove

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

Specified by:
remove in interface IntCollection
Overrides:
remove in class AbstractIntCollection

size

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

Specified by:
size in interface IntCollection
Overrides:
size in class AbstractIntCollection

first

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

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

last

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

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

headSet

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

tailSet

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

subSet

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