Skip to content

Commit

Permalink
fix: Fix early termination for filtered table scans. (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed Sep 21, 2021
1 parent 7ce363b commit e2e0d3e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export default class Table extends Transformable {
}
} else if (filter) {
let c = n - i + 1;
for (i = filter.nth(i); --c; i = filter.next(i + 1)) {
for (i = filter.nth(i); --c && i > -1; i = filter.next(i + 1)) {
fn(i, data, stop);
}
} else {
Expand Down
27 changes: 27 additions & 0 deletions test/table/column-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ tape('ColumnTable scan supports filtering and ordering', t => {
t.end();
});

tape('ColumnTable scan supports early termination', t => {
const table = new ColumnTable({
a: ['a', 'a', 'a', 'b', 'b'],
b: [2, 1, 4, 5, 3]
});

let count;
const visitor = (row, data, stop) => { if (++count > 1) stop(); };

count = 0;
table.scan(visitor, true);
t.equal(count, 2, 'standard scan');

count = 0;
const filter = new BitSet(5);
[1, 2, 4].forEach(i => filter.set(i));
table.create({ filter }).scan(visitor, true);
t.equal(count, 2, 'filtered scan');

count = 0;
const order = (u, v, { b }) => b.get(u) - b.get(v);
table.create({ order }).scan(visitor, true);
t.equal(count, 2, 'ordered scan');

t.end();
});

tape('ColumnTable memoizes indices', t => {
const ut = new ColumnTable({ v: [1, 3, 2] });
const ui = ut.indices(false);
Expand Down

0 comments on commit e2e0d3e

Please sign in to comment.