PCJ API
Version 1.2

bak.pcj.set
Class ShortBitSet

java.lang.Object
  extended bybak.pcj.AbstractShortCollection
      extended bybak.pcj.set.AbstractShortSet
          extended bybak.pcj.set.ShortBitSet
All Implemented Interfaces:
Cloneable, Serializable, ShortCollection, ShortSet, ShortSortedSet

public class ShortBitSet
extends AbstractShortSet
implements ShortSortedSet, Cloneable, Serializable

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

Constructor Detail

ShortBitSet

public ShortBitSet(short 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.

ShortBitSet

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


ShortBitSet

public ShortBitSet(ShortCollection 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.

ShortBitSet

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

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

iterator

public ShortIterator iterator()
Description copied from interface: ShortCollection
Returns an iterator over this collection.

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

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

Specified by:
clear in interface ShortCollection
Overrides:
clear in class AbstractShortCollection

contains

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

Specified by:
contains in interface ShortCollection
Overrides:
contains in class AbstractShortCollection

isEmpty

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

Specified by:
isEmpty in interface ShortCollection
Overrides:
isEmpty in class AbstractShortCollection

remove

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

Specified by:
remove in interface ShortCollection
Overrides:
remove in class AbstractShortCollection

size

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

Specified by:
size in interface ShortCollection
Overrides:
size in class AbstractShortCollection

first

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

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

last

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

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

headSet

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

tailSet

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

subSet

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