7template<
class Indexer,
class Key>
class IndexSet {
18 word_ |= uint64_t(1) << pos_;
20 word_ &= ~(uint64_t(1) << pos_);
23 operator bool()
const {
return word_ & (uint64_t(1) << pos_); }
26 uint64_t word()
const {
return word_; }
42 , bits_(other.bits_) {}
44 : indexer_(std::move(other.indexer_))
45 , bits_(std::move(other.bits_)) {}
48 const Indexer&
indexer()
const {
return indexer_; }
50 size_t next(
size_t pos = 0) {
51 for (
size_t i = pos, e =
capacity(); i != e; ++i)
52 if (bits_[i])
return i;
57 assert(i !=
size_t(-1));
58 return reference(bits_[i / 64u], i % 64u);
63 template<
bool flag>
bool set(Key key) {
64 auto ref = (*this)[key];
65 auto old = ref.word();
67 return old != ref.word();
71 bool contains(Key key)
const {
return (*
this)[key]; }
72 void clear() { std::ranges::fill(bits_, 0u); }
75 assert(this->size() == other.size());
76 for (
size_t i = 0, e =
capacity(); i != e; ++i) this->bits_[i] = op(this->bits_[i], other.bits_[i]);
84 assert(&set1.indexer() == &set2.indexer());
85 swap(set1.bits_, set2.bits_);
89 const Indexer& indexer_;
reference operator=(bool b) noexcept
reference operator[](Key key)
IndexSet & operator=(IndexSet other) noexcept
IndexSet & operator|=(const IndexSet &other)
IndexSet & transform(const IndexSet &other, Op op)
IndexSet & operator&=(const IndexSet &other)
const Indexer & indexer() const
IndexSet(const Indexer &indexer)
bool set(Key key)
Depending on flag this method either inserts (true) or removes (false) key and returns true if succes...
bool contains(Key key) const
friend void swap(IndexSet &set1, IndexSet &set2) noexcept
IndexSet(IndexSet &&other) noexcept
IndexSet(const IndexSet &other)
size_t next(size_t pos=0)
bool erase(Key key)
Erase key and returns true if successful.
bool insert(Key key)
Inserts key and returns true if successful.
IndexSet & operator^=(const IndexSet &other)
bool operator[](Key key) const
This is a thin wrapper for absl::InlinedVector<T, N, / A> which in turn is a drop-in replacement for ...
bool visit(IndexSet< Indexer, Key > &set, const Key &key)
void visit_first(IndexSet< Indexer, Key > &set, const Key &key)