deno.land / x / pg_mem@2.8.1 / transforms / eq-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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { _ISelection, IValue, _IIndex, _ITable, _Transaction, _Explainer, _SelectExplanation, IndexKey, IndexOp, Stats } from '../interfaces-private.ts';import { FilterBase } from './transform-base.ts';import { nullIsh } from '../utils.ts';
export class EqFilter<T = any> extends FilterBase<T> {
private index: _IIndex; private opDef: IndexOp;
entropy(t: _Transaction): number { return this.index.entropy({ ...this.opDef, t }); }

stats(t: _Transaction): Stats | null { const stats = this.index.stats(t, [this.equalsCst]); if (this.op === 'eq' || !stats) { return stats; } // if neq, then compute from eq and all const all = this.index.stats(t); if (!all) { return null; } return { count: all.count - stats.count, }; }
hasItem(item: T, t: _Transaction) { const val = this.onValue.get(item, t); if (nullIsh(val)) { return false; } const eq = this.onValue.type.equals(val, this.equalsCst); if (nullIsh(eq)) { return false; } return this.op === 'eq' ? !!eq : !eq; }
constructor(private onValue: IValue<T> , private equalsCst: any , private op: 'eq' | 'neq' , private matchNull: boolean) { super(onValue.origin!); if (onValue.index!.expressions.length !== 1) { throw new Error('Unexpected index equality expressions count mismatch'); }
this.index = this.onValue.index!; this.opDef = { type: op, key: [equalsCst], t: null as any, matchNull: this.matchNull, } }
*enumerate(t: _Transaction): Iterable<T> { for (const item of this.index.enumerate({ ...this.opDef, t })) { yield item; } }
explain(e: _Explainer): _SelectExplanation { return { id: e.idFor(this), _: this.op, entropy: this.entropy(e.transaction), on: this.onValue.index!.explain(e), }; }}
pg_mem

Version Info

Tagged at
4 months ago