structure
Class BitSet

java.lang.Object
  extended by structure.BitSet

public class BitSet
extends java.lang.Object

Implementation of a set of numbered bits. This class's interface differs from the Set, java.util.Bitset, and Set interfaces, so care must be taken to invoke the proper methods.

See Also:
CharSet, BitSet

Constructor Summary
BitSet()
          Constructs an empty bitset.
BitSet(int count)
          Constructs an empty bitset with potential to hold values between 0..count-1.
 
Method Summary
 void add(int i)
          Adds a bit to the bitset, if not already there.
 void clear()
          Remove all bits from the set.
 void clear(int count)
          Remove bits from set; set size to count.
 java.lang.Object clone()
          Returns a copy of the set.
 boolean contains(int i)
          Determine if a bit is a member of the set.
 java.lang.Object difference(BitSet other)
          Computes the difference between this set and the other.
 boolean equals(java.lang.Object o)
          Return true iff this set and o contain the same elements.
 java.lang.Object intersection(BitSet other)
          Return the intersection of this set and the other.
 boolean isEmpty()
          Determine if a set is empty.
 void remove(int i)
          Remove bit i from the bitset.
 boolean subset(BitSet other)
          Returns true iff this set is a subset of the other.
 java.lang.String toString()
          Constructs string representing set.
 java.lang.Object union(BitSet other)
          Compute a new set that is the union of this set and other.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitSet

public BitSet()
Constructs an empty bitset.

Post:
constructs an empty set of small integers

BitSet

public BitSet(int count)
Constructs an empty bitset with potential to hold values between 0..count-1.

Parameters:
count - The number of distinct values possibly in set.
Post:
constructs an empty set with count potential elements
Method Detail

add

public void add(int i)
Adds a bit to the bitset, if not already there. Set is potentially extended.

Parameters:
i - The number of the bit to be added.
Pre:
i >= 0
Post:
i is added to the set

remove

public void remove(int i)
Remove bit i from the bitset.

Parameters:
i - The index of the bit to be removed.
Pre:
i >= 0
Post:
removes i from set if present

contains

public boolean contains(int i)
Determine if a bit is a member of the set.

Parameters:
i - The bit index of potential bit.
Returns:
True iff bit i is in the set.
Pre:
i >= 0
Post:
returns true iff i in set

clear

public void clear()
Remove all bits from the set.

Post:
removes all values from set

clear

public void clear(int count)
Remove bits from set; set size to count.

Parameters:
count - The new capacity of the newly empty set.
Post:
removes all values from set, sets set size to count

clone

public java.lang.Object clone()
Returns a copy of the set.

Overrides:
clone in class java.lang.Object
Returns:
A new BitSet with the same values as this.
Post:
constructs a copy of the set

union

public java.lang.Object union(BitSet other)
Compute a new set that is the union of this set and other. Elements of the new set appear in at least one of the two sets.

Parameters:
other - The set to be unioned with this.
Returns:
The union of the two sets.
Pre:
other is non-null
Post:
constructs set w/elements from this and other

intersection

public java.lang.Object intersection(BitSet other)
Return the intersection of this set and the other. A bit is in the result if it is in this set and other.

Parameters:
other - The other set to be intersected with this.
Pre:
other is not null
Post:
constructs set w/elements in this and other

difference

public java.lang.Object difference(BitSet other)
Computes the difference between this set and the other. An element is in the difference if it is in this, but not in other.

Parameters:
other - The difference between this set and other.
Pre:
other is not null
Post:
constructs set w/elements from this but not other

subset

public boolean subset(BitSet other)
Returns true iff this set is a subset of the other. A set is a subset of another if its elements are elements of the other.

Parameters:
other - The potential superset.
Returns:
The difference between this and other.
Pre:
other is not null
Post:
returns true iff elements of this are all in other

isEmpty

public boolean isEmpty()
Determine if a set is empty.

Returns:
True iff this set is empty.
Post:
returns true iff this set is empty

equals

public boolean equals(java.lang.Object o)
Return true iff this set and o contain the same elements.

Overrides:
equals in class java.lang.Object
Parameters:
o - Another non-null bitset.
Returns:
True iff this set has the same elements as o.
Pre:
o is not null
Post:
returns true iff this and o have same elements

toString

public java.lang.String toString()
Constructs string representing set.

Overrides:
toString in class java.lang.Object
Returns:
String representing bitset.
Post:
returns string representation of set