deno.land / x / pg_mem@2.8.1 / schema / custom-index.ts

custom-index.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { _IIndex, IValue, _ITable, _IDb, _Transaction, _Explainer, _IndexExplanation, IndexOp, IndexKey, Stats } from '../interfaces-private.ts';import { PermissionDeniedError, NotSupported } from '../interfaces.ts';
interface IndexSubject<T> { readonly size: number; readonly column: IValue; byColumnValue(columnValue: string, t: _Transaction): T[];}
export class CustomIndex<T> implements _IIndex<T> { readonly expressions: IValue<any>[];

explain(e: _Explainer): _IndexExplanation { throw new Error('not implemented'); }
constructor(readonly onTable: _ITable<T>, private subject: IndexSubject<T>) { this.expressions = [this.subject.column]; }
get indexName(): string { return null as any; }
entropy(): number { return this.subject.size; }
stats(t: _Transaction, key?: IndexKey): Stats | null { return null; }
iterateKeys() { return null; }
add(raw: any): void { throw new PermissionDeniedError(); }
eqFirst([key]: any, t: _Transaction) { for (const its of this.subject.byColumnValue(key, t)) { return its; } return null; }

enumerate(op: IndexOp): Iterable<T> { switch (op.type) { case 'eq': return this.eq(op.key, op.t); case 'neq': return this.neq(op.key, op.t); case 'ge': return this.ge(op.key, op.t); case 'le': return this.le(op.key, op.t); case 'gt': return this.gt(op.key, op.t); case 'lt': return this.lt(op.key, op.t); case 'outside': return this.outside(op.lo, op.hi, op.t); case 'inside': return this.inside(op.lo, op.hi, op.t); case 'nin': return this.nin(op.keys, op.t); default: throw NotSupported.never(op['type']); } }
* eq([rawKey]: any, t: _Transaction): Iterable<any> { for (const its of this.subject.byColumnValue(rawKey, t)) { yield its; } }
* nin(keys: any[][], t: _Transaction) { const raws = keys.map(x => x[0]) as any[]; for (const i of this.onTable.selection.enumerate(t)) { const val = this.subject.column.get(i, t); if (raws.includes(val)) { continue; } yield i; } }
* neq([rawKey]: any, t: _Transaction) { for (const i of this.onTable.selection.enumerate(t)) { const val = this.subject.column.get(i, t); if (val !== rawKey) { yield i; } } } * gt(rawKey: any, t: _Transaction): Iterable<any> { for (const i of this.onTable.selection.enumerate(t)) { const val = this.subject.column.get(i, t); if (val > rawKey) { yield i; } } } * lt(rawKey: any, t: _Transaction): Iterable<any> { for (const i of this.onTable.selection.enumerate(t)) { const val = this.subject.column.get(i, t); if (val < rawKey) { yield i; } } } * ge(rawKey: any, t: _Transaction): Iterable<any> { for (const i of this.onTable.selection.enumerate(t)) { const val = this.subject.column.get(i, t); if (val >= rawKey) { yield i; } } } * le(rawKey: any, t: _Transaction): Iterable<any> { for (const i of this.onTable.selection.enumerate(t)) { const val = this.subject.column.get(i, t); if (val <= rawKey) { yield i; } } }
*outside(lo: IndexKey, hi: IndexKey, t: _Transaction): Iterable<T> { yield* this.lt(lo, t); yield* this.gt(hi, t); }
*inside(lo: IndexKey, hi: IndexKey, t: _Transaction): Iterable<T> { throw new Error('Not implemented'); }}
pg_mem

Version Info

Tagged at
4 months ago