FreeNOS
|
Represents an array of bits. More...
#include <BitArray.h>
Public Types | |
enum | Result { Success, InvalidArgument, OutOfMemory } |
Result codes. More... | |
Public Member Functions | |
BitArray (const Size bitCount, u8 *array=ZERO) | |
Class constructor. More... | |
virtual | ~BitArray () |
Class destructor. More... | |
Size | size () const |
Returns the maximum size of this Container. More... | |
Size | count (const bool on) const |
Get the number of bits in the map which have the given value. More... | |
void | set (const Size bit, const bool value=true) |
Sets the given bit to the given value. More... | |
void | setRange (const Size from, const Size to) |
Set a range of bits inside the map to 1. More... | |
Result | setNext (Size *bit, const Size count=1, const Size offset=0, const Size boundary=1) |
Sets the next unset bit(s). More... | |
void | unset (const Size bit) |
Sets the given bit to zero. More... | |
void | clear () |
Set all bits to zero. More... | |
bool | isSet (const Size bit) const |
Verify if a given bit is set. More... | |
u8 * | array () const |
Retrieve a pointer to the internal BitArray. More... | |
void | setArray (u8 *array, const Size bitCount=ZERO) |
Use the given pointer as the BitArray buffer. More... | |
bool | operator[] (const Size bit) const |
Retrieve the value of the given bit. More... | |
bool | operator[] (const int bit) const |
Retrieve the value of the given bit. More... | |
Private Member Functions | |
Size | calculateBitmapSize (const Size bitCount) const |
Calculate required size of bitmap array in bytes. More... | |
Private Attributes | |
Size | m_bitCount |
Total number of bits in the array. More... | |
Size | m_set |
Set bits in the array. More... | |
u8 * | m_array |
Array containing the bits. More... | |
bool | m_allocated |
True if m_array was allocated interally. More... | |
Represents an array of bits.
Definition at line 36 of file BitArray.h.
enum BitArray::Result |
Result codes.
Enumerator | |
---|---|
Success | |
InvalidArgument | |
OutOfMemory |
Definition at line 43 of file BitArray.h.
Class constructor.
bitCount | Number of bits to manage. |
array | Optional pointer to pre-allocated bits array to manage. |
Definition at line 22 of file BitArray.cpp.
References array(), calculateBitmapSize(), clear(), m_allocated, m_array, m_bitCount, m_set, and ZERO.
|
virtual |
u8 * BitArray::array | ( | ) | const |
Retrieve a pointer to the internal BitArray.
Definition at line 165 of file BitArray.cpp.
References m_array.
Referenced by BitArray().
Calculate required size of bitmap array in bytes.
bitCount | Minimum number of bits needed to store. |
Definition at line 218 of file BitArray.cpp.
Referenced by BitArray(), and clear().
void BitArray::clear | ( | ) |
Set all bits to zero.
Definition at line 199 of file BitArray.cpp.
References calculateBitmapSize(), m_array, m_bitCount, m_set, and MemoryBlock::set().
Referenced by BitArray().
Size BitArray::count | ( | const bool | on | ) | const |
Get the number of bits in the map which have the given value.
on | True to get the number of 1-bits, false for 0-bits. |
Definition at line 45 of file BitArray.cpp.
References m_bitCount, and m_set.
Referenced by BitAllocator::available(), and setNext().
bool BitArray::isSet | ( | const Size | bit | ) | const |
Verify if a given bit is set.
bit | Bit number to check. |
Definition at line 82 of file BitArray.cpp.
References assert, m_array, and m_bitCount.
Referenced by BitAllocator::isAllocated(), operator[](), setArray(), and setNext().
bool BitArray::operator[] | ( | const int | bit | ) | const |
Retrieve the value of the given bit.
bit | Bit number to find |
Definition at line 213 of file BitArray.cpp.
References isSet().
bool BitArray::operator[] | ( | const Size | bit | ) | const |
Retrieve the value of the given bit.
bit | Bit number to find |
Definition at line 208 of file BitArray.cpp.
References isSet().
void BitArray::set | ( | const Size | bit, |
const bool | value = true |
||
) |
Sets the given bit to the given value.
bit | Bit number to set. |
value | Value to set. |
Definition at line 50 of file BitArray.cpp.
References m_array, m_bitCount, and m_set.
Referenced by BitAllocator::allocateAt(), LinnCreate::create(), LinnCreate::createInode(), setRange(), and unset().
Use the given pointer as the BitArray buffer.
array | New bits array pointer. |
bitCount | New number of bits. ZERO to keep the old value. |
Definition at line 170 of file BitArray.cpp.
References isSet(), m_allocated, m_array, m_bitCount, and m_set.
Referenced by LinnCreate::create(), and LinnCreate::createInode().
BitArray::Result BitArray::setNext | ( | Size * | bit, |
const Size | count = 1 , |
||
const Size | offset = 0 , |
||
const Size | boundary = 1 |
||
) |
Sets the next unset bit(s).
bit | Start bit number on success. |
count | Number of consequetive bits required. |
offset | Start bit number to start searching at inside the BitArray. |
boundary | First bit number must be on the given alignment boundary. |
Definition at line 97 of file BitArray.cpp.
References count(), isSet(), m_array, m_bitCount, OutOfMemory, setRange(), and Success.
Referenced by BitAllocator::allocateFrom(), and LinnCreate::createInode().
Set a range of bits inside the map to 1.
from | Bit to start with. |
to | End bit (inclusive). |
Definition at line 89 of file BitArray.cpp.
References set().
Referenced by setNext().
Size BitArray::size | ( | ) | const |
Returns the maximum size of this Container.
Definition at line 40 of file BitArray.cpp.
References m_bitCount.
void BitArray::unset | ( | const Size | bit | ) |
Sets the given bit to zero.
bit | Bit number to unset. |
Definition at line 77 of file BitArray.cpp.
References set().
Referenced by BitAllocator::release().
|
private |
True if m_array was allocated interally.
Definition at line 189 of file BitArray.h.
Referenced by BitArray(), setArray(), and ~BitArray().
|
private |
Array containing the bits.
Definition at line 186 of file BitArray.h.
Referenced by array(), BitArray(), clear(), isSet(), set(), setArray(), setNext(), and ~BitArray().
|
private |
Total number of bits in the array.
Definition at line 180 of file BitArray.h.
Referenced by BitArray(), clear(), count(), isSet(), set(), setArray(), setNext(), and size().
|
private |
Set bits in the array.
Definition at line 183 of file BitArray.h.
Referenced by BitArray(), clear(), count(), set(), and setArray().