33 inline void Initialize(
size_t new_b_size) {
39 u32size = b_size >> 5;
88 index_u32 = index >> 5;
89 index_mask = 1 << (index & 31);
94 inline operator bool ()
const {
95 return (bf->data[index_u32] & index_mask);
100 bf->data[index_u32] |= index_mask;
105 bf->data[index_u32] &= ~index_mask;
141 index_u32 = index >> 5;
142 index_mask = 1 << (index & 31);
147 inline operator bool ()
const {
148 return (bf->data[index_u32] & index_mask);
194 inline size_t size()
const {
return b_size; }
196 inline size_t reserved()
const {
return (data.reserved() << 5); }
205 inline void ZeroRange(
const size_t start,
const size_t end) {
207 size_t start_u32_border;
209 size_t end_u32_border;
212 start_u32 = (start + 31) >> 5;
213 start_u32_border = start_u32 << 5;
215 if (start_u32_border >= end) {
216 for (b=start; b<end; b++) {
222 end_u32 = (end + 1) >> 5;
223 end_u32_border = end_u32 << 5;
225 if (end_u32 > start_u32) {
226 data.ZeroRange(start_u32, end_u32-1);
229 for (b=start; b<start_u32_border; b++) {
233 for (b=end_u32_border; b<=end; b++) {
250 inline void Reserve(
const size_t reserve_size) {
253 u32size = reserve_size >> 5;
254 if (reserve_size & 31) {
258 data.Resize(u32size);
265 inline void Resize(
const size_t resize_size) {
267 b_size = resize_size;
297 (*this)[last] = new_bit;
306 for (i=0; i<other.b_size; i++) {
318 (*this)[pos] = new_bit;
341 inline bool Check(
const size_t x)
const {
342 if ( ! (x < b_size) ) {
352 inline void Assert(
const size_t x)
const {
367 for (i=0; i<data.size(); i++) {
369 if ((i == data.size()-1) && (b_size & 31)) {
370 word &= (
u64(1) << (b_size & 31)) - 1;
373 word = word - ((word >>1) & 0x55555555);
374 word = (word & 0x33333333) + ((word >> 2) & 0x33333333);
375 count += (((word + (word >> 4)) & 0xF0F0F0F) * 0x01010101) >> 24;
390 swap(a.data, b.data);
407 for (i=0; i<b.
size(); i++) {
Provides a one-dimensional vector-like structure.
Provides informative exception handling.
#define Throw_RC_Type(Type, err)
Use this to throw an RC:ErrorMsg subtype exception.
Definition: Errors.h:282
uint64_t u64
64-bit unsigned integer.
Definition: Types.h:31
uint32_t u32
32-bit unsigned integer.
Definition: Types.h:29
A bounds-safe two-dimensional structure of efficiently packed bits.
Definition: Bitfield2D.h:27
A bounds-safe three-dimensional structure of efficiently packed bits.
Definition: Bitfield3D.h:28
A temporary return-type that serves as a const interface to specific bit values.
Definition: Bitfield.h:132
A temporary return-type that serves as an interface to specific bit values.
Definition: Bitfield.h:79
BitfieldBool & operator=(const bool set)
Assign the bool value of set to this bit.
Definition: Bitfield.h:109
void Set()
Set the bit to true / 1.
Definition: Bitfield.h:99
void Clear()
Set the bit to false / 0.
Definition: Bitfield.h:104
A bounds-safe one-dimensional vector-like structure of efficiently packed bits.
Definition: Bitfield.h:27
void ZeroRange(const size_t start, const size_t end)
Set all bits to zero between index start and end, inclusive.
Definition: Bitfield.h:205
size_t CountZeroes() const
Efficiently determines the total number of false / 0 values in the Bitfield.
Definition: Bitfield.h:383
void Append(const Bitfield &other)
Append bits from another Bitfield to this Bitfield.
Definition: Bitfield.h:304
void Crop()
Reduce memory consumption to only that necessary for size() bits.
Definition: Bitfield.h:272
bool Check(const size_t x) const
True if index x is within the Bitfield.
Definition: Bitfield.h:341
BitfieldBool At(size_t x)
Const version of At()
Definition: Bitfield.h:184
BitfieldBoolConst At(size_t x) const
Identical to operator[].
Definition: Bitfield.h:188
void ExpandSet(size_t pos, const bool new_bit)
Assign new_bit to index pos, expanding if necessary to reach that index.
Definition: Bitfield.h:314
Bitfield(size_t b_size)
Constructor which sets the initial size to b_size bits.
Definition: Bitfield.h:57
friend void swap(Bitfield &a, Bitfield &b)
Swap the data in Bitfield a and b.
Definition: Bitfield.h:388
void Assert(const size_t x) const
Throws ErrorMsgBounds if index x is out of bounds for this Bitfield.
Definition: Bitfield.h:352
Bitfield & operator+=(const bool new_bit)
Appends new_bit, expanding as necessary.
Definition: Bitfield.h:325
Bitfield()
Default constructor which initializes to size 0.
Definition: Bitfield.h:50
void Reserve(const size_t reserve_size)
Reserve storage without resizing the Bitfield.
Definition: Bitfield.h:250
size_t size() const
Return the current number of bits.
Definition: Bitfield.h:194
Data1D< u32 > & Raw()
Provides raw access to the Data1D<u32> in which the bits are packed.
Definition: Bitfield.h:243
bool IsEmpty() const
True if the size is 0.
Definition: Bitfield.h:71
size_t CountOnes() const
Efficiently determines the total number of true / 1 values in the Bitfield.
Definition: Bitfield.h:361
void Zero()
Set all bits to zero.
Definition: Bitfield.h:199
void Delete()
Deletes the stored data, resets the size to 0, and releases the memory.
Definition: Bitfield.h:64
void Resize(const size_t resize_size)
Resize the array, reallocating if necessary.
Definition: Bitfield.h:265
void Clear()
Identical to Delete()
Definition: Bitfield.h:278
void Append(const bool new_bit)
Add a bit to the end, expanding if necessary.
Definition: Bitfield.h:288
BitfieldBool operator[](size_t x)
Bounds-checked access of the element at index x.
Definition: Bitfield.h:168
BitfieldBool operator()(size_t x)
Identical to operator[].
Definition: Bitfield.h:172
size_t reserved() const
Return the number of bits for which space is reserved.
Definition: Bitfield.h:196
std::ostream & operator<<(std::ostream &out, APtr< T > obj)
A convenience stream output for displaying the enclosed object.
Definition: APtr.h:120
void swap(RC::Data1D< T > &a, RC::Data1D< T > &b)
Efficiently swap all the contents of a and b.
Definition: Data1D.h:1184