-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
seq-scan.ts
46 lines (37 loc) · 1.21 KB
/
seq-scan.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { IValue, _ISelection, _Transaction, _Explainer, _SelectExplanation, Stats } from '../interfaces-private.ts';
import { FilterBase } from './transform-base.ts';
import { Types } from '../datatypes/index.ts';
export class SeqScanFilter<T = any> extends FilterBase<T> {
get index() {
return null;
}
entropy(t: _Transaction) {
// boost source entropy (in case an index has the same items count)
return this.selection.entropy(t) * 1.5;
}
hasItem(raw: T, t: _Transaction): boolean {
return !!this.getter.get(raw, t);
}
constructor(private selection: _ISelection<T>, private getter: IValue<T>) {
super(selection);
this.getter = getter.cast(Types.bool);
}
stats(t: _Transaction): Stats | null {
return null;
}
*enumerate(t: _Transaction): Iterable<T> {
for (const raw of this.selection.enumerate(t)) {
const cond = this.getter.get(raw, t);
if (cond) {
yield raw;
}
}
}
explain(e: _Explainer): _SelectExplanation {
return {
id: e.idFor(this),
_: 'seqFilter',
filtered: this.selection.explain(e),
};
}
}