-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
between-filter.ts
60 lines (50 loc) · 1.68 KB
/
between-filter.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { _ISelection, IValue, _IIndex, _ITable, _Transaction, _Explainer, _SelectExplanation, IndexOp, Stats } from '../interfaces-private.ts';
import { FilterBase } from './transform-base.ts';
import { nullIsh } from '../utils.ts';
export class BetweenFilter<T = any> extends FilterBase<T> {
private opDef: IndexOp;
entropy(t: _Transaction) {
return this.onValue.index!.entropy({ ...this.opDef, t });
}
constructor(private onValue: IValue<T>
, private lo: any
, private hi: any
, private op: 'inside' | 'outside') {
super(onValue.origin!);
if (onValue.index!.expressions[0]?.hash !== onValue.hash) {
throw new Error('Between index misuse');
}
this.opDef = {
type: op,
hi: [hi],
lo: [lo],
t: null as any,
}
}
hasItem(value: T, t: _Transaction): boolean {
const v = this.onValue.get(value, t);
if (nullIsh(v)) {
return false;
}
if (this.op === 'inside') {
return !!this.onValue.type.ge(v, this.lo)
&& !!this.onValue.type.le(v, this.hi);
}
return !!this.onValue.type.lt(v, this.lo)
|| !!this.onValue.type.gt(v, this.lo);
}
enumerate(t: _Transaction): Iterable<T> {
return this.onValue.index!.enumerate({ ...this.opDef, t });
}
stats(t: _Transaction): Stats | null {
return null;
}
explain(e: _Explainer): _SelectExplanation {
return {
id: e.idFor(this),
_: this.op,
entropy: this.entropy(e.transaction),
on: this.onValue.index!.explain(e),
};
}
}