C# 클래스 Nez.BitSet

This class can be thought of in two ways. You can see it as a vector of bits or as a set of non-negative integers. The name BitSet is a bit misleading. It is implemented by a bit vector, but its equally possible to see it as set of non-negative integer; each integer in the set is represented by a set bit at the corresponding index. The size of this structure is determined by the highest integer in the set. You can union, intersect and build (symmetric) remainders, by invoking the logical operations and, or, andNot, resp. xor. This implementation is NOT synchronized against concurrent access from multiple threads. Specifically, if one thread is reading from a bitset while another thread is simultaneously modifying it, the results are undefined. author Jochen Hoenicke author Tom Tromey ([email protected]) author Eric Blake ([email protected]) status updated to 1.4
파일 보기 프로젝트 열기: prime31/Nez 1 사용 예제들

공개 메소드들

메소드 설명
BitSet ( ) : System

Create a new empty bit set. All bits are initially false.

BitSet ( int nbits ) : System

Create a new empty bit set, with a given size. This constructor reserves enough space to represent the integers from 0 to nbits-1.

Equals ( object obj ) : bool

Returns true if the obj is a bit set that contains exactly the same elements as this bit set, otherwise false.

GetHashCode ( ) : int

Returns a hash code value for this bit set. The hash code of two bit sets containing the same integers is identical. The algorithm used to compute it is as follows: Suppose the bits in the BitSet were to be stored in an array of long integers called bits, in such a manner that bit k is set in the BitSet (for non-negative values of k) if and only if ((k/64) < bits.length) && ((bits[k/64] & (1L << (bit % 64))) != 0) Then the following definition of the GetHashCode method would be a correct implementation of the actual algorithm:

public override int GetHashCode() { long h = 1234; for (int i = bits.length-1; i >= 0; i--) { h ^= bits[i] * (i + 1); } return (int)((h >> 32) ^ h); }
Note that the hash code values changes, if the set is changed.

ToString ( ) : string

Returns the string representation of this bit set. This consists of a comma separated list of the integers in this set surrounded by curly braces. There is a space after each comma. A sample string is thus "{1, 3, 53}".

and ( BitSet bs ) : void

Performs the logical AND operation on this bit set and the given set. This means it builds the intersection of the two sets. The result is stored into this bit set.

andNot ( BitSet bs ) : void

Performs the logical AND operation on this bit set and the complement of the given bs. This means it selects every element in the first set, that isn't in the second set. The result is stored into this bit set and is effectively the set difference of the two.

cardinality ( ) : int

Returns the number of bits set to true.

clear ( ) : void

Sets all bits in the set to false.

clear ( int pos ) : void

Removes the integer pos from this set. That is the corresponding bit is cleared. If the index is not in the set, this method does nothing.

clear ( int from, int to ) : void

Sets the bits between from (inclusive) and to (exclusive) to false.

clone ( ) : object

Create a clone of this bit set, that is an instance of the same class and contains the same elements. But it doesn't change when this bit set changes.

containsAll ( BitSet other ) : bool
flip ( int index ) : void

Sets the bit at the index to the opposite value.

flip ( int from, int to ) : void

Sets a range of bits to the opposite value.

get ( int from, int to ) : BitSet

Returns a new BitSet composed of a range of bits from this one.

get ( int pos ) : System.Boolean

Returns true if the integer bitIndex is in this bit set, otherwise false.

intersects ( BitSet set ) : bool

Returns true if the specified BitSet and this one share at least one common true bit.

isEmpty ( ) : bool

Returns true if this set contains no true bits.

nextClearBit ( int from ) : int

Returns the index of the next false bit, from the specified bit (inclusive).

nextSetBit ( int from ) : int

Returns the index of the next true bit, from the specified bit (inclusive). If there is none, -1 is returned. You can iterate over all true bits with this loop:

for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { // operate on i here } 

or ( BitSet bs ) : void

Performs the logical OR operation on this bit set and the given set. This means it builds the union of the two sets. The result is stored into this bit set, which grows as necessary.

set ( int pos ) : void

Add the integer bitIndex to this set. That is the corresponding bit is set to true. If the index was already in the set, this method does nothing. The size of this structure is automatically increased as necessary.

set ( int index, bool value ) : void

Sets the bit at the given index to the specified value. The size of this structure is automatically increased as necessary.

set ( int from, int to ) : void

Sets the bits between from (inclusive) and to (exclusive) to true.

set ( int from, int to, bool value ) : void

Sets the bits between from (inclusive) and to (exclusive) to the specified value.

xor ( BitSet bs ) : void

Performs the logical XOR operation on this bit set and the given set. This means it builds the symmetric remainder of the two sets (the elements that are in one set, but not in the other). The result is stored into this bit set, which grows as necessary.

비공개 메소드들

메소드 설명
ensure ( int lastElt ) : void

Make sure the vector is big enough.

메소드 상세

BitSet() 공개 메소드

Create a new empty bit set. All bits are initially false.
public BitSet ( ) : System
리턴 System

BitSet() 공개 메소드

Create a new empty bit set, with a given size. This constructor reserves enough space to represent the integers from 0 to nbits-1.
public BitSet ( int nbits ) : System
nbits int nbits the initial size of the bit set
리턴 System

Equals() 공개 메소드

Returns true if the obj is a bit set that contains exactly the same elements as this bit set, otherwise false.
public Equals ( object obj ) : bool
obj object the object to compare to
리턴 bool

GetHashCode() 공개 메소드

Returns a hash code value for this bit set. The hash code of two bit sets containing the same integers is identical. The algorithm used to compute it is as follows: Suppose the bits in the BitSet were to be stored in an array of long integers called bits, in such a manner that bit k is set in the BitSet (for non-negative values of k) if and only if ((k/64) < bits.length) && ((bits[k/64] & (1L << (bit % 64))) != 0) Then the following definition of the GetHashCode method would be a correct implementation of the actual algorithm:
public override int GetHashCode() { long h = 1234; for (int i = bits.length-1; i >= 0; i--) { h ^= bits[i] * (i + 1); } return (int)((h >> 32) ^ h); }
Note that the hash code values changes, if the set is changed.
public GetHashCode ( ) : int
리턴 int

ToString() 공개 메소드

Returns the string representation of this bit set. This consists of a comma separated list of the integers in this set surrounded by curly braces. There is a space after each comma. A sample string is thus "{1, 3, 53}".
public ToString ( ) : string
리턴 string

and() 공개 메소드

Performs the logical AND operation on this bit set and the given set. This means it builds the intersection of the two sets. The result is stored into this bit set.
public and ( BitSet bs ) : void
bs BitSet the second bit set
리턴 void

andNot() 공개 메소드

Performs the logical AND operation on this bit set and the complement of the given bs. This means it selects every element in the first set, that isn't in the second set. The result is stored into this bit set and is effectively the set difference of the two.
public andNot ( BitSet bs ) : void
bs BitSet the second bit set
리턴 void

cardinality() 공개 메소드

Returns the number of bits set to true.
public cardinality ( ) : int
리턴 int

clear() 공개 메소드

Sets all bits in the set to false.
public clear ( ) : void
리턴 void

clear() 공개 메소드

Removes the integer pos from this set. That is the corresponding bit is cleared. If the index is not in the set, this method does nothing.
public clear ( int pos ) : void
pos int a non-negative integer
리턴 void

clear() 공개 메소드

Sets the bits between from (inclusive) and to (exclusive) to false.
public clear ( int from, int to ) : void
from int the start range (inclusive)
to int the end range (exclusive)
리턴 void

clone() 공개 메소드

Create a clone of this bit set, that is an instance of the same class and contains the same elements. But it doesn't change when this bit set changes.
public clone ( ) : object
리턴 object

containsAll() 공개 메소드

public containsAll ( BitSet other ) : bool
other BitSet
리턴 bool

flip() 공개 메소드

Sets the bit at the index to the opposite value.
public flip ( int index ) : void
index int the index of the bit
리턴 void

flip() 공개 메소드

Sets a range of bits to the opposite value.
public flip ( int from, int to ) : void
from int the low index (inclusive)
to int the high index (exclusive)
리턴 void

get() 공개 메소드

Returns a new BitSet composed of a range of bits from this one.
public get ( int from, int to ) : BitSet
from int the low index (inclusive)
to int the high index (exclusive)
리턴 BitSet

get() 공개 메소드

Returns true if the integer bitIndex is in this bit set, otherwise false.
public get ( int pos ) : System.Boolean
pos int a non-negative integer
리턴 System.Boolean

intersects() 공개 메소드

Returns true if the specified BitSet and this one share at least one common true bit.
public intersects ( BitSet set ) : bool
set BitSet the set to check for intersection
리턴 bool

isEmpty() 공개 메소드

Returns true if this set contains no true bits.
public isEmpty ( ) : bool
리턴 bool

nextClearBit() 공개 메소드

Returns the index of the next false bit, from the specified bit (inclusive).
public nextClearBit ( int from ) : int
from int the start location
리턴 int

nextSetBit() 공개 메소드

Returns the index of the next true bit, from the specified bit (inclusive). If there is none, -1 is returned. You can iterate over all true bits with this loop:
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { // operate on i here } 
public nextSetBit ( int from ) : int
from int the start location
리턴 int

or() 공개 메소드

Performs the logical OR operation on this bit set and the given set. This means it builds the union of the two sets. The result is stored into this bit set, which grows as necessary.
public or ( BitSet bs ) : void
bs BitSet the second bit set
리턴 void

set() 공개 메소드

Add the integer bitIndex to this set. That is the corresponding bit is set to true. If the index was already in the set, this method does nothing. The size of this structure is automatically increased as necessary.
public set ( int pos ) : void
pos int a non-negative integer.
리턴 void

set() 공개 메소드

Sets the bit at the given index to the specified value. The size of this structure is automatically increased as necessary.
public set ( int index, bool value ) : void
index int the position to set
value bool the value to set it to
리턴 void

set() 공개 메소드

Sets the bits between from (inclusive) and to (exclusive) to true.
public set ( int from, int to ) : void
from int the start range (inclusive)
to int the end range (exclusive)
리턴 void

set() 공개 메소드

Sets the bits between from (inclusive) and to (exclusive) to the specified value.
public set ( int from, int to, bool value ) : void
from int the start range (inclusive)
to int the end range (exclusive)
value bool the value to set it to
리턴 void

xor() 공개 메소드

Performs the logical XOR operation on this bit set and the given set. This means it builds the symmetric remainder of the two sets (the elements that are in one set, but not in the other). The result is stored into this bit set, which grows as necessary.
public xor ( BitSet bs ) : void
bs BitSet the second bit set
리턴 void