BitVector (struct)¶
The BitVector is a memory-efficient Boolean array, where each element uses a single bit.
注釈
Setting different bits in parallel might lead to unexpected results, in which case methods such as BitVector.atomicSet should be used.
/*
** Example: BitVector
*/
require Containers;
operator entry() {
BitVector b;
b.resize(4);
b.set(0, true);
b.set(1, false);
b.set(2, false);
b.set(3, true);
report(b.getString());
}
/*
** Output:
[1,0,0,1]
*/
Methods¶
BitVector ( in BitVector other ) | |
BitVector () | |
atomicClear ! ( in UInt32 index ) | |
atomicSet ! ( in UInt32 index ) | |
atomicSet ! ( in UInt32 index, in Boolean value ) | |
BitVectorIterator | begin ? () |
clear ! ( in UInt32 index ) | |
clearAll ! () | |
BitVector | clone ? () |
copy ! ( in BitVector src ) | |
Boolean | get ? ( in UInt32 index ) |
Boolean | getNext ? ( io BitVectorIterator iter ) |
String | getString ? () |
Boolean | getThenClear ! ( in UInt32 index ) |
Boolean | getThenSet ! ( in UInt32 index ) |
Boolean | getThenSet ! ( in UInt32 index, in Boolean value ) |
resize ! ( in UInt32 size ) | |
set ! ( in UInt32 index ) | |
set ! ( in UInt32 index, in Boolean value ) | |
setAll ! () | |
UInt32 | size ? () |
Methods in detail¶
BitVector ( in BitVector other )
copy constructor
BitVector ()
default constructor
BitVector.atomicClear! ( in UInt32 index )
performs an atomic clear of a bit.
注釈
atomic calls are threadsafe but slower since they cause cache synchronization across CPUs.
BitVector.atomicSet! ( in UInt32 index )
performs an atomic set with true.
注釈
atomic calls are threadsafe but slower since they cause cache synchronization across CPUs.
BitVector.atomicSet! ( in UInt32 index, in Boolean value )
performs an atomic set with a known value.
注釈
atomic calls are threadsafe but slower since they cause cache synchronization across CPUs.
BitVectorIterator BitVector.begin? ()
returns an iterator at the start of the vector. This method is particularly efficient for traversing sparse bits, where only a small portion are set to true.
/*
** Example: begin
*/
require Containers;
operator entry() {
BitVector v;
v.resize(4);
v.set(0, true);
v.set(1, true);
v.set(2, false);
v.set(3, true);
BitVectorIterator it = v.begin();
while(v.getNext(it)) {
report(it.index + ' : ' + v.get(it.index));
}
}
/*
** Output:
0 : true
1 : true
3 : true
*/
BitVector.clear! ( in UInt32 index )
clears a bit
BitVector.clearAll! ()
clears all bits in this vector
clone method
BitVector.copy! ( in BitVector src )
copy constructor.
Boolean BitVector.get? ( in UInt32 index )
returns true if the bit is set
Boolean BitVector.getNext? ( io BitVectorIterator iter )
returns the next BitVectorIterator on this vector based on the previous one This method is particularly efficient for traversing sparse bits, where only a small portion are set to true.
String BitVector.getString? ()
returns a description of the bit values
Boolean BitVector.getThenClear! ( in UInt32 index )
clears the bit and returns the previous value
Boolean BitVector.getThenSet! ( in UInt32 index )
performs a set with true for a known value and returns the previous value
Boolean BitVector.getThenSet! ( in UInt32 index, in Boolean value )
sets the bit to a known value and returns the previous value
BitVector.resize! ( in UInt32 size )
resizes the BitVector for a given number of bits
BitVector.set! ( in UInt32 index )
sets a single bit to true
BitVector.set! ( in UInt32 index, in Boolean value )
sets a single bit from the Boolean value
BitVector.setAll! ()
sets all bits in this vector to true
returns the number bit array size