Xavax C++ Library | Class Index FAQ Overview |
operator[]
and the get
and
set
methods.
Constructor Summary |
Bitmap(size_t n)
Create a new bitmap of the specified size. |
Operator Summary | |
Bit
|
operator[](size_t p)
Returns a reference to the bit at position p .
|
Method Summary | |
bool
|
findFirst(bool state,
size_t& position)
Find the first bit in the specified state. |
bool
|
get(size_t position)
Returns the value of the specified bit. |
void
|
reset()
Reset all bits in the bitmap to false .
|
void
|
set(size_t position, bool value)
Set the value of the specified bit. |
Related Classes | |
Bit |
Constructor Detail |
Bitmap(size_t n)
n
.n
- the number of bits in the bitmap.
Operator Detail |
Bit operator[](size_t p)
p
.
Bit::operator bool
and
Bit::operator=
can be used to get and set the bit.
p
- the position of the bit to be referenced.p
.
p
is greater than
or equal to the bitmap size.
Method Detail |
bool findFirst(bool state, size_t& position)
state
- the state of the bit to find.position
- the position of the bit found.bool get(size_t position)
position
- the position of the bit to be retrieved.p
is greater than
or equal to the bitmap size.
void reset()
false
.
void set(size_t position, bool value)
p
to value
.
position
- the position of the bit to be set.value
- the new boolean value of the bit.position
is greater than
or equal to the bitmap size.
Example Code |
#include <iostream.h> #include "Bitmap.h" int main(int argc, char** argv) { // // Create a bitmap and set each bit with a position // that is a multiple of 3 (except 0). // Bitmap b(40); b[21] = b[24] = b[27] = b[30] = b[33] = b[36] = b[39] = true; b[3] = b[6] = b[9] = b[12] = b[15] = b[18] = b[21]; // // While any bit is set, find the first one bit // and print the bit position, then clear the bit. // size_t position; while ( b.findFirst(true, position) ) { cout << "first one = " << position << endl; b.set(position, false); } // // Reset the bitmap to all ones, then clear each bit // with a position that is a multiple of 3 (except 0). // cout << "Resetting bitmap to all ones..." << endl; b.reset(true); cout << "Clearing some bits..." << endl; b[21] = b[24] = b[27] = b[30] = b[33] = b[36] = b[39] = false; b[3] = b[6] = b[9] = b[12] = b[15] = b[18] = b[21]; // // While any bit is clear, find the first zero bit // and print the bit position, then set the bit. // while ( b.findFirst(false, position) ) { cout << "first zero = " << position << endl; b.set(position, true); } }
Copyright © 2003 Xavax Inc. -- All Rights Reserved