Skip to content

Engine → Core → bit_vector.h

bit_vector

Syntax

class CONJURE_API bit_vector

Constructors

AccessSignatureDescription
publicbit_vector() = default;
publicexplicit bit_vector( usize size, bool value = false);Creates size bits, all set to value.
publicbit_vector( const bit_vector &) = default;
publicbit_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

AccessSignatureDescription
public~bit_vector() = default;

Variables

AccessNameTypeDefaultDescription
privatemSizeusize0
privatemWordsstd::vector<u64>{}
publicNPOSstatic constexpr usizestatic_cast<usize>(-1)Returned by the find_* functions when no matching bit exists.
publicWORD_BITSstatic constexpr usize64Bits per storage word.

Functions

Public

all

[[nodiscard]] bool all() const noexcept;

True when every bit is set (always true for an empty vector).

any

[[nodiscard]] bool any() const noexcept;

True when at least one bit is set.

capacity

[[nodiscard]] usize capacity() const noexcept;

Number of bits that fit without reallocating.

clear

void clear() noexcept;

Removes every bit (size becomes 0). Storage is kept.

count

[[nodiscard]] usize count() const noexcept;

Number of set bits.

empty

[[nodiscard]] bool empty() const noexcept;

True when there are no bits at all.

find_first_clear

[[nodiscard]] usize find_first_clear(
    usize from = 0) const noexcept;

Index of the first clear bit at or after from, or NPOS.

find_first_set

[[nodiscard]] usize find_first_set(
    usize from = 0) const noexcept;

Index of the first set bit at or after from, or NPOS.

find_last_set

[[nodiscard]] usize find_last_set() const noexcept;

Index of the last set bit, or NPOS.

flip

void flip(
    usize index) noexcept;

Inverts the bit at index. Asserts on an out-of-range index and does nothing.

flip_all

void flip_all() noexcept;

Inverts every bit.

intersects

[[nodiscard]] bool intersects(
    const bit_vector &other) const noexcept;

True when the two vectors share at least one set bit.

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

[[nodiscard]] bool none() const noexcept;

True when no bit is set (always true for an empty vector).

push_back

void push_back(
    bool value);

Appends one bit.

remove

bit_vector &remove(
    const bit_vector &other) noexcept;

Clears every bit that is set in other (this & ~other).

reserve

void reserve(
    usize bits);

Ensures room for bits bits without changing size().

reset

void reset(
    usize index) noexcept;

Clears the bit at index. Asserts on an out-of-range index and does nothing.

reset_all

void reset_all() noexcept;

Clears every bit (size is unchanged).

resize

void resize(
    usize size,
    bool value = false);

Changes the number of bits. New bits take value; removed bits are discarded.

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_all

void set_all() noexcept;

Sets every bit.

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.

size

[[nodiscard]] usize size() const noexcept;

Number of bits.

test

[[nodiscard]] bool test(
    usize index) const noexcept;

The bit at index. Asserts on an out-of-range index and returns false.

word_count

[[nodiscard]] usize word_count() const noexcept;

Number of 64-bit words backing the bits.

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

void clear_trailing_bits() noexcept;

Operator Overloads

Public

operator&=

bit_vector &operator&=(
    const bit_vector &other) noexcept;

operator=

bit_vector &operator=(
    const bit_vector &) = default;
bit_vector &operator=(
    bit_vector &&other) noexcept;

operator==

[[nodiscard]] bool operator==(
    const bit_vector &other) const noexcept;

operator[]

[[nodiscard]] bool operator[](
    usize index) const noexcept;

operator^=

bit_vector &operator^=(
    const bit_vector &other) noexcept;

operator|=

bit_vector &operator|=(
    const bit_vector &other) noexcept;