montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 183 forks source link

iterate(start, end) does not behave properly if start == 0 #200

Open hhanh00 opened 6 years ago

hhanh00 commented 6 years ago
let set = new SortedSet([-10, 5])
let iterable = {
  [Symbol.iterator]: () => set.iterate(0, 4)
}
for (const a of iterable) {
  console.log(a)
}

shows -10

This is because of

function Iterator(set, start, end) {
    this.set = set;
    this.prev = null;
    this.end = end;
    if (start) { // <- it is false when start == 0
        var next = this.set.findLeastGreaterThanOrEqual(start);
        if (next) {
            this.set.splay(next.value);
            this.prev = next.getPrevious();
        }
    }
}
hthetiot commented 6 years ago

Would you willing to make a PR for fix @hhanh00 ?