Packagecom.yworks.bridge.util
Classpublic class BitSet
InheritanceBitSet Inheritance YObject Inheritance Object
Implements Clonable

The BitSet class implements a bit field. Each element in a BitSet can be on(1) or off(0). A BitSet is created with a given size and grows when this size is exceeded. Growth is always rounded to a 64 bit boundary.



Public Properties
 PropertyDefined By
  empty : Boolean
[read-only] Answers true if all the bits in this bitset are set to false.
BitSet
Public Methods
 MethodDefined By
  
BitSet(init:Boolean = true)
Create a new BitSet with size equal to 64 bits
BitSet
  
and(bs:BitSet):void
Performs the logical AND of this BitSet with another BitSet.
BitSet
  
andNot(bs:BitSet):void
Clears all bits in the receiver which are also set in the parameter BitSet.
BitSet
  
Answers the number of bits that are true in this bitset.
BitSet
  
clear():void
Clears all the bits in this bitset.
BitSet
  
clearBit(pos:int):void
Clears the bit at index pos.
BitSet
  
clearBits(pos1:int, pos2:int):void
Clears the bits starting from pos1 to pos2.
BitSet
  
clone():Object
Create a copy of this BitSet
BitSet
  
equals(obj:Object):Boolean
[override] Compares the argument to this BitSet and answer if they are equal.
BitSet
  
flipBit(pos:int):void
Flips the bit at index pos.
BitSet
  
flipBits(pos1:int, pos2:int):void
Flips the bits starting from pos1 to pos2.
BitSet
  
getBit(pos:int):Boolean
Retrieve the bit at index pos.
BitSet
  
getBits(pos1:int, pos2:int):BitSet
Retrieves the bits starting from pos1 to pos2 and answers back a new bitset made of these bits.
BitSet
  
getClass():Class
[override]
BitSet
  
hashCode():int
[override] Computes the hash code for this BitSet.
BitSet
  
intersects(bs:BitSet):Boolean
Checks if these two bitsets have at least one bit set to true in the same position.
BitSet
  
length():int
Returns the number of bits up to and including the highest bit set.
BitSet
  
[static] Create a new BitSet with size equal to 64 bits
BitSet
  
newBitSet2(nbits:int):BitSet
[static] Create a new BitSet with size equal to nbits.
BitSet
  
nextClearBit(pos:int):int
Answers the position of the first bit that is false on or after pos
BitSet
  
nextSetBit(pos:int):int
Answers the position of the first bit that is true on or after pos
BitSet
  
or(bs:BitSet):void
Performs the logical OR of this BitSet with another BitSet.
BitSet
  
setBit(pos:int):void
Sets the bit at index pos to 1.
BitSet
  
setBits(pos1:int, pos2:int):void
Sets the bits starting from pos1 to pos2.
BitSet
  
setBitsValue(pos1:int, pos2:int, val:Boolean):void
Sets the bits starting from pos1 to pos2 to the given boolean value.
BitSet
  
setBitValue(pos:int, val:Boolean):void
Sets the bit at index pos to the value.
BitSet
  
size():int
Answers the number of bits this bitset has.
BitSet
  
toString():String
Answers a string containing a concise, human-readable description of the receiver.
BitSet
  
xor(bs:BitSet):void
Performs the logical XOR of this BitSet with another BitSet.
BitSet
Protected Methods
 MethodDefined By
  
cloneImpl(o:Object):void
BitSet
  
Initializes this object.
BitSet
  
initBitSet2(nbits:int):void
Initializes this object.
BitSet
Property Detail
emptyproperty
empty:Boolean  [read-only]

Answers true if all the bits in this bitset are set to false.


Implementation
    public function get empty():Boolean
Constructor Detail
BitSet()Constructor
public function BitSet(init:Boolean = true)

Create a new BitSet with size equal to 64 bits

Parameters
init:Boolean (default = true) — An internally used switch to help handle proper instance initialization in inheritance chains where classes can have multiple constructor-like factory methods. This parameter can safely be ignored/omitted when calling the constructor.

See also

Method Detail
and()method
public function and(bs:BitSet):void

Performs the logical AND of this BitSet with another BitSet.

Parameters

bs:BitSet — BitSet to AND with

See also

andNot()method 
public function andNot(bs:BitSet):void

Clears all bits in the receiver which are also set in the parameter BitSet.

Parameters

bs:BitSet — BitSet to ANDNOT with

cardinality()method 
public function cardinality():int

Answers the number of bits that are true in this bitset.

Returns
int — the number of true bits in the set
clear()method 
public function clear():void

Clears all the bits in this bitset.

See also

clearBit()method 
public function clearBit(pos:int):void

Clears the bit at index pos. Grows the BitSet if pos > size.

Parameters

pos:int — the index of the bit to clear


Throws
RangeError — when pos < 0

See also

clearBits()method 
public function clearBits(pos1:int, pos2:int):void

Clears the bits starting from pos1 to pos2. Grows the BitSet if pos2 > size.

Parameters

pos1:int — beginning position
 
pos2:int — ending position


Throws
RangeError — when pos1 or pos2 is negative, or when pos2 is not smaller than pos1

See also

clone()method 
public function clone():Object

Create a copy of this BitSet

Returns
Object — A copy of this BitSet.
cloneImpl()method 
protected function cloneImpl(o:Object):void

Parameters

o:Object

equals()method 
override public function equals(obj:Object):Boolean

Compares the argument to this BitSet and answer if they are equal. The object must be an instance of BitSet with the same bits set.

Parameters

obj:Object — the BitSet object to compare

Returns
Boolean — A boolean indicating whether or not this BitSet and obj are equal

See also

flipBit()method 
public function flipBit(pos:int):void

Flips the bit at index pos. Grows the BitSet if pos > size.

Parameters

pos:int — the index of the bit to flip


Throws
RangeError — when pos < 0

See also

flipBits()method 
public function flipBits(pos1:int, pos2:int):void

Flips the bits starting from pos1 to pos2. Grows the BitSet if pos2 > size.

Parameters

pos1:int — beginning position
 
pos2:int — ending position


Throws
RangeError — when pos1 or pos2 is negative, or when pos2 is not smaller than pos1

See also

getBit()method 
public function getBit(pos:int):Boolean

Retrieve the bit at index pos. Grows the BitSet if pos > size.

Parameters

pos:int — the index of the bit to be retrieved

Returns
Booleantrue if the bit at pos is set, false otherwise

Throws
RangeError — when pos < 0

See also

getBits()method 
public function getBits(pos1:int, pos2:int):BitSet

Retrieves the bits starting from pos1 to pos2 and answers back a new bitset made of these bits. Grows the BitSet if pos2 > size.

Parameters

pos1:int — beginning position
 
pos2:int — ending position

Returns
BitSet — new bitset

Throws
RangeError — when pos1 or pos2 is negative, or when pos2 is not smaller than pos1

See also

getClass()method 
override public function getClass():Class

Returns
Class
hashCode()method 
override public function hashCode():int

Computes the hash code for this BitSet.

Returns
int — The int representing the hash code for this bit set.

See also

initBitSet1()method 
protected final function initBitSet1():void

Initializes this object. See the documentation of the corresponding factory method newBitSet1() for details.

See also

initBitSet2()method 
protected final function initBitSet2(nbits:int):void

Initializes this object. See the documentation of the corresponding factory method newBitSet2() for details.

Parameters

nbits:int

See also

intersects()method 
public function intersects(bs:BitSet):Boolean

Checks if these two bitsets have at least one bit set to true in the same position.

Parameters

bs:BitSet — BitSet used to calculate intersect

Returns
Booleantrue if bs intersects with this BitSet, false otherwise
length()method 
public function length():int

Returns the number of bits up to and including the highest bit set.

Returns
int — the length of the BitSet
newBitSet1()method 
public static function newBitSet1():BitSet

Create a new BitSet with size equal to 64 bits

Returns
BitSet

See also

newBitSet2()method 
public static function newBitSet2(nbits:int):BitSet

Create a new BitSet with size equal to nbits. If nbits is not a multiple of 64, then create a BitSet with size nbits rounded to the next closest multiple of 64.

Parameters

nbits:int — the size of the bit set

Returns
BitSet

Throws
RangeError — if nbits < 0.

See also

nextClearBit()method 
public function nextClearBit(pos:int):int

Answers the position of the first bit that is false on or after pos

Parameters

pos:int — the starting position (inclusive)

Returns
int — the position of the next bit set to false, even if it is further than this bitset's size.
nextSetBit()method 
public function nextSetBit(pos:int):int

Answers the position of the first bit that is true on or after pos

Parameters

pos:int — the starting position (inclusive)

Returns
int — -1 if there is no bits that are set to true on or after pos.
or()method 
public function or(bs:BitSet):void

Performs the logical OR of this BitSet with another BitSet.

Parameters

bs:BitSet — BitSet to OR with

See also

setBit()method 
public function setBit(pos:int):void

Sets the bit at index pos to 1. Grows the BitSet if pos > size.

Parameters

pos:int — the index of the bit to set


Throws
RangeError — when pos < 0

See also

setBits()method 
public function setBits(pos1:int, pos2:int):void

Sets the bits starting from pos1 to pos2. Grows the BitSet if pos2 > size.

Parameters

pos1:int — beginning position
 
pos2:int — ending position


Throws
RangeError — when pos1 or pos2 is negative, or when pos2 is not smaller than pos1

See also

setBitsValue()method 
public function setBitsValue(pos1:int, pos2:int, val:Boolean):void

Sets the bits starting from pos1 to pos2 to the given boolean value. Grows the BitSet if pos2 > size.

Parameters

pos1:int — beginning position
 
pos2:int — ending position
 
val:Boolean — value to set these bits


Throws
RangeError — when pos1 or pos2 is negative, or when pos2 is not smaller than pos1

See also

setBitValue()method 
public function setBitValue(pos:int, val:Boolean):void

Sets the bit at index pos to the value. Grows the BitSet if pos > size.

Parameters

pos:int — the index of the bit to set
 
val:Boolean — value to set the bit


Throws
RangeError — when pos < 0

See also

size()method 
public function size():int

Answers the number of bits this bitset has.

Returns
int — The number of bits contained in this BitSet.

See also

toString()method 
public function toString():String

Answers a string containing a concise, human-readable description of the receiver.

Returns
String — A comma delimited list of the indices of all bits that are set.
xor()method 
public function xor(bs:BitSet):void

Performs the logical XOR of this BitSet with another BitSet.

Parameters

bs:BitSet — BitSet to XOR with

See also