7template<
class Indexer,
class Key>
12 reference(uint64_t& word, uint64_t pos)
19 word_ |= uint64_t(1) << pos_;
21 word_ &= ~(uint64_t(1) << pos_);
24 operator bool()
const {
return word_ & (uint64_t(1) << pos_); }
27 uint64_t word()
const {
return word_; }
43 , bits_(other.bits_) {}
45 : indexer_(std::move(other.indexer_))
46 , bits_(std::move(other.bits_)) {}
49 const Indexer&
indexer()
const {
return indexer_; }
51 size_t next(
size_t pos = 0) {
52 for (
size_t i = pos, e =
capacity(); i != e; ++i)
53 if (bits_[i])
return i;
58 assert(i !=
size_t(-1));
59 return reference(bits_[i / 64u], i % 64u);
66 auto ref = (*this)[key];
67 auto old = ref.word();
69 return old != ref.word();
73 bool contains(Key key)
const {
return (*
this)[key]; }
74 void clear() { std::ranges::fill(bits_, 0u); }
78 assert(this->size() == other.size());
79 for (
size_t i = 0, e =
capacity(); i != e; ++i)
80 this->bits_[i] = op(this->bits_[i], other.bits_[i]);
88 assert(&set1.indexer() == &set2.indexer());
89 swap(set1.bits_, set2.bits_);
93 const Indexer& indexer_;
99template<
class Indexer,
class Key>
101 return !set.insert(key);
104template<
class Indexer,
class Key>
106 assert(!set.contains(key));
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 is a drop-in replacement for std::vecto...
bool visit(IndexSet< Indexer, Key > &set, const Key &key)
void visit_first(IndexSet< Indexer, Key > &set, const Key &key)