copied set implementations from MultiFlag JS
This commit is contained in:
26
node/src/enumeration/number.ts
Normal file
26
node/src/enumeration/number.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export class BitFlagsIterator implements Iterator<number> {
|
||||
private _value: number
|
||||
private _current: number
|
||||
|
||||
public constructor(value: number) {
|
||||
this._value = value
|
||||
this._current = 1
|
||||
}
|
||||
|
||||
public next(): IteratorResult<number, undefined> {
|
||||
if (this._value == 0) {
|
||||
return { done: true, value: undefined }
|
||||
}
|
||||
|
||||
while ((this._value & 1) == 0) {
|
||||
this._value >>= 1
|
||||
this._current <<= 1
|
||||
}
|
||||
|
||||
const result = this._current
|
||||
this._value >>= 1
|
||||
this._current <<= 1
|
||||
|
||||
return { done: false, value: result }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user