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

startswith-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
import { _ISelection, IValue, _IIndex, _ITable, getId, _Transaction, _Explainer, _SelectExplanation, Stats } from '../interfaces-private.ts';import { FilterBase } from './transform-base.ts';import { nullIsh } from '../utils.ts';
export class StartsWithFilter<T = any> extends FilterBase<T> {
get index() { return null; }
entropy(t: _Transaction) { return this.onValue.index!.entropy({ type: 'ge', key: [this.startWith], t, }); }
hasItem(item: T, t: _Transaction) { const get = this.onValue.get(item, t); return typeof get === 'string' && get.startsWith(this.startWith); }
constructor(private onValue: IValue<T> , private startWith: string) { super(onValue.origin!); if (onValue.index!.expressions[0].hash !== this.onValue.hash) { throw new Error('Startwith must be the first component of the index'); } }

stats(t: _Transaction): Stats | null { return null; }
*enumerate(t: _Transaction): Iterable<T> { const index = this.onValue.index!; for (const item of index.enumerate({ type: 'ge', key: [this.startWith], t, })) { const got: string = this.onValue.get(item, t); if (nullIsh(got) || !got.startsWith(this.startWith)) { break; } yield item; } }
explain(e: _Explainer): _SelectExplanation { return { id: e.idFor(this), _: 'ineq', entropy: this.entropy(e.transaction), on: this.onValue.index!.explain(e), }; }}
pg_mem

Version Info

Tagged at
4 months ago