deno.land / x / pg_mem@2.8.1 / transforms / not-in-filter.ts

not-in-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
import { _ISelection, IValue, _IIndex, _ITable, getId, _Transaction, _Explainer, _SelectExplanation, IndexKey, Stats } from '../interfaces-private.ts';import { FilterBase } from './transform-base.ts';import { DataType, CastError, QueryError } from '../interfaces.ts';import { nullIsh } from '../utils.ts';
export class NotInFilter<T = any> extends FilterBase<T> {
private index: _IIndex; private keys: IndexKey[];
entropy(t: _Transaction) { return this.onValue.index!.entropy({ type: 'nin', keys: this.keys, t, }); }
hasItem(item: T, t: _Transaction): boolean { const val = this.onValue.get(item, t); return !nullIsh(val) && !this.elts.some(x => this.onValue.type.equals(x, val)); }
constructor(private onValue: IValue<T> , private elts: any[]) { super(onValue.origin!); this.index = onValue.index!; if (this.index.expressions.length !== 1) { throw new Error('Only supports IN with signle expressions index'); } if (!Array.isArray(elts)) { throw new QueryError('Cannot iterate element list'); } this.keys = elts.map(x => [x]); }

stats(t: _Transaction): Stats | null { const all = this.base.stats(t); if (!all) { return null; } const elts = this.elts.map(x => this.index.stats(t, [x])); if (elts.some(x => !x)) { return null; } // compute based on 'all' for (const i of elts) { all.count -= i!.count; } return all; }
*enumerate(t: _Transaction): Iterable<T> { yield* this.index.enumerate({ type: 'nin', keys: this.keys, t, }); }

explain(e: _Explainer): _SelectExplanation { return { id: e.idFor(this), _: 'neq', entropy: this.entropy(e.transaction), on: this.onValue.index!.explain(e), }; }}
pg_mem

Version Info

Tagged at
4 months ago