Commit 3843340c authored by Dong-hee Na's avatar Dong-hee Na

bitset micro-optimize

parent cb0fd07e
...@@ -153,19 +153,18 @@ template <int N> struct BitSet { ...@@ -153,19 +153,18 @@ template <int N> struct BitSet {
bool operator==(const iterator& rhs) { return cur == rhs.cur; } bool operator==(const iterator& rhs) { return cur == rhs.cur; }
bool operator!=(const iterator& rhs) { return !(*this == rhs); } bool operator!=(const iterator& rhs) { return !(*this == rhs); }
iterator& operator++() { iterator& operator++() {
// TODO: this function (and begin()) could be optimized using __builtin_ctz
assert(cur >= 0 && cur < N); assert(cur >= 0 && cur < N);
uint16_t tmp = set.bits; uint16_t tmp = set.bits;
tmp >>= cur + 1; tmp >>= cur + 1;
cur++; cur++;
if (tmp > 0) {
while (cur < N) { int offset = __builtin_ctz(tmp);
if (tmp & 1) if (cur + offset < N) {
cur += offset;
return *this; return *this;
cur++;
tmp >>= 1;
} }
}
cur = N;
assert(cur == N); assert(cur == N);
return *this; return *this;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment