FastLED 3.9.15
Loading...
Searching...
No Matches

◆ resize()

void fl::bitset_dynamic::resize ( uint32_t new_size)
inline

Definition at line 94 of file bitset_dynamic.h.

94 {
95 if (new_size == _size)
96 return;
97
98 uint32_t new_block_count = calc_block_count(new_size);
99
100 if (new_block_count != _block_count) {
101 block_type *new_blocks = nullptr;
102
103 if (new_block_count > 0) {
104 new_blocks = new block_type[new_block_count]();
105
106 // Copy existing data if any
107 if (_blocks && _block_count > 0) {
108 memcpy(new_blocks, _blocks,
109 MIN(_block_count, new_block_count) *
110 sizeof(block_type));
111 }
112 }
113
114 delete[] _blocks;
115 _blocks = new_blocks;
116 _block_count = new_block_count;
117 }
118
119 _size = new_size;
120
121 // Clear any bits beyond the new size
122 if (_block_count > 0) {
123 uint32_t last_block_idx = (_size - 1) / bits_per_block;
124 uint32_t last_bit_pos = (_size - 1) % bits_per_block;
125
126 // Create a mask for valid bits in the last block
127 block_type mask =
128 (static_cast<block_type>(1) << (last_bit_pos + 1)) - 1;
129
130 if (last_block_idx < _block_count) {
131 _blocks[last_block_idx] &= mask;
132
133 // Clear any remaining blocks
134 for (uint32_t i = last_block_idx + 1; i < _block_count; ++i) {
135 _blocks[i] = 0;
136 }
137 }
138 }
139 }
static uint32_t calc_block_count(uint32_t bit_count)
static constexpr uint32_t bits_per_block
block_type * _blocks
#define MIN(a, b)
Definition math_macros.h:15

References _block_count, _blocks, _size, bits_per_block, calc_block_count(), and MIN.

Referenced by bitset_dynamic(), bitset_dynamic(), assign(), and operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: