Engine → Core → bit_vector.h
bit_vector¶
| Type | Class |
| Namespace | conjure::core |
| Include File Path | engine/include/conjure/core/bit_vector.h |
| Source File Path | engine/src/core/strings/bit_vector.cpp |
| API ↗ | Strings and identifiers |
Syntax¶
Constructors¶
| Access | Signature | Description |
|---|---|---|
| public | bit_vector() = default; | |
| public | explicit bit_vector(
usize size,
bool value = false); | Creates size bits, all set to value. |
| public | bit_vector(
const bit_vector &) = default; | |
| public | bit_vector(
bit_vector &&other) noexcept; | Moving transfers the words without copying. The moved-from vector is empty (size 0, no words) and may be resized and used again; a self-move assignment changes nothing. |
Destructors¶
| Access | Signature | Description |
|---|---|---|
| public | ~bit_vector() = default; |
Variables¶
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mSize | usize | 0 | |
| private | mWords | std::vector<u64> | {} | |
| public | NPOS | static constexpr usize | static_ | Returned by the find_* functions when no matching bit exists. |
| public | WORD_BITS | static constexpr usize | 64 | Bits per storage word. |
Functions¶
Public¶
all¶
all¶[[nodiscard]] bool all() const noexcept;True when every bit is set (always true for an empty vector).
capacity¶
capacity¶[[nodiscard]] usize capacity() const noexcept;Number of bits that fit without reallocating.
find_first_clear¶
find_first_clear¶Index of the first clear bit at or after from, or NPOS.
find_first_set¶
find_first_set¶Index of the first set bit at or after from, or NPOS.
find_last_set¶
find_last_set¶[[nodiscard]] usize find_last_set() const noexcept;Index of the last set bit, or NPOS.
flip¶
flip¶void flip(
usize index) noexcept;Inverts the bit at index. Asserts on an out-of-range index and does nothing.
intersects¶
intersects¶[[nodiscard]] bool intersects(
const bit_vector &other) const noexcept;True when the two vectors share at least one set bit.
is_subset_of¶
is_subset_of¶[[nodiscard]] bool is_subset_of(
const bit_vector &other) const noexcept;True when every set bit of this vector is also set in other.
none¶
none¶[[nodiscard]] bool none() const noexcept;True when no bit is set (always true for an empty vector).
remove¶
remove¶bit_vector &remove(
const bit_vector &other) noexcept;Clears every bit that is set in other (this & ~other).
reset¶
reset¶void reset(
usize index) noexcept;Clears the bit at index. Asserts on an out-of-range index and does nothing.
resize¶
resize¶void resize(
usize size,
bool value = false);Changes the number of bits. New bits take value; removed bits are discarded.
set¶
set¶void set(
usize index) noexcept;Sets the bit at index to 1. Asserts on an out-of-range index and does nothing.
void set(
usize index,
bool value) noexcept;Sets the bit at index to value.
set_bits¶
set_bits¶[[nodiscard]] set_bit_range set_bits() const noexcept;Range over the indices of the set bits in ascending order. The vector must not be modified while iterating.
test¶
test¶[[nodiscard]] bool test(
usize index) const noexcept;The bit at index. Asserts on an out-of-range index and returns false.
word_count¶
word_count¶[[nodiscard]] usize word_count() const noexcept;Number of 64-bit words backing the bits.
words¶
words¶[[nodiscard]] std::span<const u64> words() const noexcept;The packed words, least significant bit first. Bits past size() are zero.
Private¶
clear_trailing_bits¶
clear_trailing_bits¶void clear_trailing_bits() noexcept;Operator Overloads¶
Public¶
operator&=¶
operator&=¶bit_vector &operator&=(
const bit_vector &other) noexcept;operator=¶
operator=¶bit_vector &operator=(
const bit_vector &) = default;bit_vector &operator=(
bit_vector &&other) noexcept;operator==¶
operator==¶[[nodiscard]] bool operator==(
const bit_vector &other) const noexcept;operator^=¶
operator^=¶bit_vector &operator^=(
const bit_vector &other) noexcept;operator|=¶
operator|=¶bit_vector &operator|=(
const bit_vector &other) noexcept;