Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Optimize bitset.all() #540

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion core/utils/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,19 @@ class dynamic_bitset {

bool none() const noexcept { return !any(); }

bool all() const noexcept { return count() == bits_; }
bool all() const noexcept {
if (words_ == 0) {
return true;
}
auto* begin = data_.get();
for (auto* end = begin + words_ - 1; begin != end; ++begin) {
static_assert(std::is_unsigned_v<word_t>);
if (*begin != std::numeric_limits<word_t>::max()) {
return false;
}
}
return std::popcount(*begin) == bits_ - (words_ - 1) * bits_required<word_t>();
}

void clear() noexcept { clear_offset(0); }

Expand Down