Skip to content

Commit

Permalink
use bit operations for count_true
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Li committed Apr 30, 2024
1 parent a218343 commit 2cd1dc8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Bitmask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,14 @@ auto sperr::Bitmask::count_true() const -> size_t
// Note that unused bits in the last long are not guaranteed to be all 0's.
for (size_t i = 0; i < m_buf.size() - 1; i++) {
const auto val = m_buf[i];
#if __cplusplus >= 201907L
counter += std::popcount(val);
#else
if (val != 0) {
for (size_t j = 0; j < 64; j++)
counter += ((val >> j) & uint64_t{1});
}
#endif
}
const auto val = m_buf.back();
if (val != 0) {
Expand Down

0 comments on commit 2cd1dc8

Please sign in to comment.