-
#include "tensorstore/util/small_bit_set.h"
-
template <size_t N>
class tensorstore::SmallBitSet; Bit set that fits in a single unsigned integer.
This is similar to
std::bitset<N>
, but supports iterators, and for simplicity is limited to a single unsigned integer.Types¶
- using value_type = bool;
Container value type.
- type BoolsView;
Mutable view of SmallBitSet bits.
- type ConstBoolsView;
Immutable view of SmallBitSet bits.
- type IndexView;
Immutable view of SmallBitSet indices.
Constructors¶
- constexpr SmallBitSet();
Constructs an all-zero vector.
- constexpr SmallBitSet(T value);
Constructs a vector with all bits set to
value
.
-
static constexpr SmallBitSet
FromIndices(const int (&positions)[NumBits]); Constructs the set containing bits at the specified indices.
- static constexpr SmallBitSet UpTo(size_t k);
Constructs the set
[0, k)
.
- static constexpr SmallBitSet FromUint(Uint bits);
Constructs from an unsigned integer as a bit vector.
- static constexpr SmallBitSet FromBools(const bool (&bits)[NumBits]);
Constructs from an array of
bool
values.
Methods¶
- static constexpr SmallBitSet FromIndexRange(Range&& range);
-
static constexpr SmallBitSet
FromIndexRange(Iterator begin, Iterator end); Constructs the set containing bits at the indices specified by the range.
- static constexpr SmallBitSet FromBoolRange(Range&& range);
-
static constexpr SmallBitSet
FromBoolRange(Iterator begin, Iterator end); Constructs the set containing bools provided by the range.
- constexpr SmallBitSet& operator=(T value);
Sets all bits to the specified value.
- constexpr bool none() const;
Returns
true
if the set is empty.
- constexpr bool any() const;
Returns
true
if the set is not empty.
- constexpr bool all() const;
Returns
true
if all bits are set.
- constexpr bool test(int pos) const noexcept;
Returns
true
if the specified bit is present in the set.
- constexpr SmallBitSet& set(int pos) noexcept;
Add the specified bit to the set.
- constexpr reference operator[](size_t offset);
- constexpr bool operator[](size_t offset) const;
Returns a reference to an individual bit.
Conversion operators¶
- explicit operator bool() const;
Returns
true
if any bit is set.
Set operations¶
- friend constexpr SmallBitSet operator~(SmallBitSet v);
Computes the complement of the set.
- friend constexpr SmallBitSet operator&(SmallBitSet a, SmallBitSet b);
-
friend constexpr SmallBitSet&
operator&=(SmallBitSet& a, SmallBitSet b); Computes the intersection of two sets.
- friend constexpr SmallBitSet operator^(SmallBitSet a, SmallBitSet b);
-
friend constexpr SmallBitSet&
operator^=(SmallBitSet& a, SmallBitSet b); Computes the exclusive OR of two sets.
- friend constexpr SmallBitSet operator|(SmallBitSet a, SmallBitSet b);
-
friend constexpr SmallBitSet&
operator|=(SmallBitSet& a, SmallBitSet b); Computes the union of two sets.
Friend functions¶
- friend constexpr bool operator==(SmallBitSet a, SmallBitSet b);
- friend constexpr bool operator!=(SmallBitSet a, SmallBitSet b);
Compares two sets for equality.
- friend std::ostream& operator<<(std::ostream& os, SmallBitSet v);
Prints to an output stream.
Related Types¶
- class tensorstore::BitRef<T>;
Mutable or constant reference to a single bit of a packed bit sequence.
- class tensorstore::BitIterator<T>;
Iterator within a packed bit sequence.