MCPcopy Create free account
hub / github.com/FastLED/FastLED / bitset_dynamic

Class bitset_dynamic

src/fl/stl/bitset_dynamic.h:20–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19/// A dynamic bitset implementation that can be resized at runtime
20class bitset_dynamic {
21 private:
22 static constexpr fl::u32 bits_per_block = 8 * sizeof(fl::u16);
23 using block_type = fl::u16;
24
25 fl::unique_ptr<block_type[]> _blocks;
26 fl::u32 _block_count = 0;
27 fl::u32 _size = 0;
28
29 // Helper to calculate block count from bit count
30 static fl::u32 calc_block_count(fl::u32 bit_count) FL_NOEXCEPT { // okay static in header
31 return (bit_count + bits_per_block - 1) / bits_per_block;
32 }
33
34 public:
35 // Default constructor
36 bitset_dynamic() = default;
37
38 // Constructor with initial size
39 explicit bitset_dynamic(fl::u32 size) FL_NOEXCEPT { resize(size); }
40
41 // Copy constructor
42 bitset_dynamic(const bitset_dynamic &other) FL_NOEXCEPT {
43 if (other._size > 0) {
44 resize(other._size);
45 fl::memcpy(_blocks.get(), other._blocks.get(), _block_count * sizeof(block_type));
46 }
47 }
48
49 // Move constructor
50 bitset_dynamic(bitset_dynamic &&other) FL_NOEXCEPT
51 : _blocks(fl::move(other._blocks)), _block_count(other._block_count),
52 _size(other._size) {
53 other._block_count = 0;
54 other._size = 0;
55 }
56
57 // Copy assignment
58 bitset_dynamic &operator=(const bitset_dynamic &other) FL_NOEXCEPT {
59 if (this != &other) {
60 if (other._size > 0) {
61 resize(other._size);
62 fl::memcpy(_blocks.get(), other._blocks.get(),
63 _block_count * sizeof(block_type));
64 } else {
65 clear();
66 }
67 }
68 return *this;
69 }
70
71 // Move assignment
72 bitset_dynamic &operator=(bitset_dynamic &&other) FL_NOEXCEPT {
73 if (this != &other) {
74 _blocks = fl::move(other._blocks);
75 _block_count = other._block_count;
76 _size = other._size;
77 other._block_count = 0;

Callers

nothing calls this directly

Calls 9

memsetFunction · 0.85
countFunction · 0.85
resizeFunction · 0.70
clearFunction · 0.70
setClass · 0.70
memcpyFunction · 0.50
resetFunction · 0.50
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected