Skip to content

Commit 524426e

Browse files
committed
New version.
1 parent 4df6cec commit 524426e

File tree

3 files changed

+1781
-883
lines changed

3 files changed

+1781
-883
lines changed

FastBitSet.js

+26-9
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,33 @@ FastBitSet.prototype.forEach = function (fnc) {
194194
};
195195

196196
// Returns an iterator of set bit locations (values)
197-
FastBitSet.prototype[Symbol.iterator] = function* () {
197+
FastBitSet.prototype[Symbol.iterator] = function () {
198198
const c = this.words.length;
199-
for (let k = 0; k < c; ++k) {
200-
let w = this.words[k];
201-
while (w != 0) {
202-
const t = w & -w;
203-
yield (k << 5) + this.hammingWeight((t - 1) | 0);
204-
w ^= t;
205-
}
206-
}
199+
let k = 0;
200+
let w = this.words[k];
201+
let hw = this.hammingWeight
202+
let words = this.words
203+
return {
204+
[Symbol.iterator]() {
205+
return this;
206+
},
207+
next() {
208+
while (k < c) {
209+
if (w !== 0) {
210+
const t = w & -w;
211+
const value = (k << 5) + hw((t - 1) | 0);
212+
w ^= t;
213+
return { done: false, value };
214+
} else {
215+
k++;
216+
if (k < c) {
217+
w = words[k];
218+
}
219+
}
220+
}
221+
return { done: true, value: undefined };
222+
},
223+
};
207224
};
208225

209226
// Creates a copy of this bitmap

0 commit comments

Comments
 (0)