@zengrid/shared 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/README.md +44 -0
- package/dist/index.cjs.default.js +1 -0
- package/dist/index.cjs.js +6250 -0
- package/dist/index.cjs.mjs +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +6207 -0
- package/dist/package.json +54 -0
- package/dist/src/algorithms/filter/bloom-filter.d.ts +120 -0
- package/dist/src/algorithms/filter/bloom-filter.d.ts.map +1 -0
- package/dist/src/algorithms/filter/index.d.ts +7 -0
- package/dist/src/algorithms/filter/index.d.ts.map +1 -0
- package/dist/src/algorithms/graph/bfs.d.ts +71 -0
- package/dist/src/algorithms/graph/bfs.d.ts.map +1 -0
- package/dist/src/algorithms/graph/dfs.d.ts +62 -0
- package/dist/src/algorithms/graph/dfs.d.ts.map +1 -0
- package/dist/src/algorithms/graph/graph.interface.d.ts +63 -0
- package/dist/src/algorithms/graph/graph.interface.d.ts.map +1 -0
- package/dist/src/algorithms/graph/index.d.ts +9 -0
- package/dist/src/algorithms/graph/index.d.ts.map +1 -0
- package/dist/src/algorithms/index.d.ts +11 -0
- package/dist/src/algorithms/index.d.ts.map +1 -0
- package/dist/src/algorithms/pattern/index.d.ts +8 -0
- package/dist/src/algorithms/pattern/index.d.ts.map +1 -0
- package/dist/src/algorithms/pattern/sequence-detector.d.ts +62 -0
- package/dist/src/algorithms/pattern/sequence-detector.d.ts.map +1 -0
- package/dist/src/algorithms/search/binary-search.d.ts +86 -0
- package/dist/src/algorithms/search/binary-search.d.ts.map +1 -0
- package/dist/src/algorithms/search/index.d.ts +6 -0
- package/dist/src/algorithms/search/index.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/comparators.d.ts +126 -0
- package/dist/src/algorithms/sorting/comparators.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/index.d.ts +9 -0
- package/dist/src/algorithms/sorting/index.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/sorting.interface.d.ts +38 -0
- package/dist/src/algorithms/sorting/sorting.interface.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/timsort.d.ts +55 -0
- package/dist/src/algorithms/sorting/timsort.d.ts.map +1 -0
- package/dist/src/data-structures/column-store/column-store.d.ts +52 -0
- package/dist/src/data-structures/column-store/column-store.d.ts.map +1 -0
- package/dist/src/data-structures/column-store/column-store.interface.d.ts +155 -0
- package/dist/src/data-structures/column-store/column-store.interface.d.ts.map +1 -0
- package/dist/src/data-structures/column-store/index.d.ts +6 -0
- package/dist/src/data-structures/column-store/index.d.ts.map +1 -0
- package/dist/src/data-structures/command-stack/command-stack.d.ts +61 -0
- package/dist/src/data-structures/command-stack/command-stack.d.ts.map +1 -0
- package/dist/src/data-structures/command-stack/command-stack.interface.d.ts +80 -0
- package/dist/src/data-structures/command-stack/command-stack.interface.d.ts.map +1 -0
- package/dist/src/data-structures/command-stack/index.d.ts +3 -0
- package/dist/src/data-structures/command-stack/index.d.ts.map +1 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.d.ts +147 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.d.ts.map +1 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.interface.d.ts +161 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.interface.d.ts.map +1 -0
- package/dist/src/data-structures/dependency-graph/index.d.ts +8 -0
- package/dist/src/data-structures/dependency-graph/index.d.ts.map +1 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.d.ts +84 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.d.ts.map +1 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.interface.d.ts +185 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.interface.d.ts.map +1 -0
- package/dist/src/data-structures/disjoint-set/index.d.ts +7 -0
- package/dist/src/data-structures/disjoint-set/index.d.ts.map +1 -0
- package/dist/src/data-structures/index-map/index-map.d.ts +150 -0
- package/dist/src/data-structures/index-map/index-map.d.ts.map +1 -0
- package/dist/src/data-structures/index-map/index-map.interface.d.ts +186 -0
- package/dist/src/data-structures/index-map/index-map.interface.d.ts.map +1 -0
- package/dist/src/data-structures/index-map/index.d.ts +6 -0
- package/dist/src/data-structures/index-map/index.d.ts.map +1 -0
- package/dist/src/data-structures/index.d.ts +36 -0
- package/dist/src/data-structures/index.d.ts.map +1 -0
- package/dist/src/data-structures/interval-tree/index.d.ts +7 -0
- package/dist/src/data-structures/interval-tree/index.d.ts.map +1 -0
- package/dist/src/data-structures/interval-tree/interval-tree.d.ts +141 -0
- package/dist/src/data-structures/interval-tree/interval-tree.d.ts.map +1 -0
- package/dist/src/data-structures/interval-tree/interval-tree.interface.d.ts +212 -0
- package/dist/src/data-structures/interval-tree/interval-tree.interface.d.ts.map +1 -0
- package/dist/src/data-structures/lru-cache/index.d.ts +3 -0
- package/dist/src/data-structures/lru-cache/index.d.ts.map +1 -0
- package/dist/src/data-structures/lru-cache/lru-cache.d.ts +134 -0
- package/dist/src/data-structures/lru-cache/lru-cache.d.ts.map +1 -0
- package/dist/src/data-structures/lru-cache/lru-cache.interface.d.ts +173 -0
- package/dist/src/data-structures/lru-cache/lru-cache.interface.d.ts.map +1 -0
- package/dist/src/data-structures/prefix-sum-array/index.d.ts +6 -0
- package/dist/src/data-structures/prefix-sum-array/index.d.ts.map +1 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.d.ts +63 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.d.ts.map +1 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.interface.d.ts +80 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.interface.d.ts.map +1 -0
- package/dist/src/data-structures/rtree/index.d.ts +8 -0
- package/dist/src/data-structures/rtree/index.d.ts.map +1 -0
- package/dist/src/data-structures/rtree/rtree.d.ts +81 -0
- package/dist/src/data-structures/rtree/rtree.d.ts.map +1 -0
- package/dist/src/data-structures/rtree/rtree.interface.d.ts +143 -0
- package/dist/src/data-structures/rtree/rtree.interface.d.ts.map +1 -0
- package/dist/src/data-structures/segment-tree/index.d.ts +4 -0
- package/dist/src/data-structures/segment-tree/index.d.ts.map +1 -0
- package/dist/src/data-structures/segment-tree/segment-tree.d.ts +134 -0
- package/dist/src/data-structures/segment-tree/segment-tree.d.ts.map +1 -0
- package/dist/src/data-structures/segment-tree/segment-tree.interface.d.ts +202 -0
- package/dist/src/data-structures/segment-tree/segment-tree.interface.d.ts.map +1 -0
- package/dist/src/data-structures/skip-list/index.d.ts +4 -0
- package/dist/src/data-structures/skip-list/index.d.ts.map +1 -0
- package/dist/src/data-structures/skip-list/skip-list.d.ts +137 -0
- package/dist/src/data-structures/skip-list/skip-list.d.ts.map +1 -0
- package/dist/src/data-structures/skip-list/skip-list.interface.d.ts +223 -0
- package/dist/src/data-structures/skip-list/skip-list.interface.d.ts.map +1 -0
- package/dist/src/data-structures/sparse-matrix/index.d.ts +6 -0
- package/dist/src/data-structures/sparse-matrix/index.d.ts.map +1 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.d.ts +44 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.d.ts.map +1 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.interface.d.ts +105 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.interface.d.ts.map +1 -0
- package/dist/src/data-structures/suffix-array/index.d.ts +3 -0
- package/dist/src/data-structures/suffix-array/index.d.ts.map +1 -0
- package/dist/src/data-structures/suffix-array/suffix-array.d.ts +102 -0
- package/dist/src/data-structures/suffix-array/suffix-array.d.ts.map +1 -0
- package/dist/src/data-structures/suffix-array/suffix-array.interface.d.ts +117 -0
- package/dist/src/data-structures/suffix-array/suffix-array.interface.d.ts.map +1 -0
- package/dist/src/data-structures/trie/index.d.ts +8 -0
- package/dist/src/data-structures/trie/index.d.ts.map +1 -0
- package/dist/src/data-structures/trie/trie.d.ts +205 -0
- package/dist/src/data-structures/trie/trie.d.ts.map +1 -0
- package/dist/src/data-structures/trie/trie.interface.d.ts +117 -0
- package/dist/src/data-structures/trie/trie.interface.d.ts.map +1 -0
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/patterns/coordinator.d.ts +90 -0
- package/dist/src/patterns/coordinator.d.ts.map +1 -0
- package/dist/src/patterns/event-emitter.d.ts +106 -0
- package/dist/src/patterns/event-emitter.d.ts.map +1 -0
- package/dist/src/patterns/factory.d.ts +120 -0
- package/dist/src/patterns/factory.d.ts.map +1 -0
- package/dist/src/patterns/index.d.ts +21 -0
- package/dist/src/patterns/index.d.ts.map +1 -0
- package/dist/src/patterns/mediator.d.ts +116 -0
- package/dist/src/patterns/mediator.d.ts.map +1 -0
- package/dist/src/patterns/object-pool.d.ts +178 -0
- package/dist/src/patterns/object-pool.d.ts.map +1 -0
- package/dist/src/patterns/observer.d.ts +89 -0
- package/dist/src/patterns/observer.d.ts.map +1 -0
- package/dist/src/patterns/operation-mode.d.ts +75 -0
- package/dist/src/patterns/operation-mode.d.ts.map +1 -0
- package/dist/src/patterns/state-machine.d.ts +122 -0
- package/dist/src/patterns/state-machine.d.ts.map +1 -0
- package/dist/src/types/common.d.ts +56 -0
- package/dist/src/types/common.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +5 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/utils/index.d.ts +7 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/timing.d.ts +104 -0
- package/dist/src/utils/timing.d.ts.map +1 -0
- package/dist/src/utils/timing.interface.d.ts +96 -0
- package/dist/src/utils/timing.interface.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/skip-list/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skip List implementation
|
|
3
|
+
* Probabilistic sorted data structure
|
|
4
|
+
*/
|
|
5
|
+
import type { ISkipList, SkipListOptions, RangeResult, SkipListStats } from './skip-list.interface';
|
|
6
|
+
/**
|
|
7
|
+
* Skip List - Probabilistic sorted data structure
|
|
8
|
+
*
|
|
9
|
+
* Implementation:
|
|
10
|
+
* - Multiple levels of linked lists
|
|
11
|
+
* - Each level is a subset of the level below
|
|
12
|
+
* - Levels are determined probabilistically
|
|
13
|
+
* - Search starts at highest level and descends
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const skipList = new SkipList<number, string>();
|
|
18
|
+
* skipList.set(10, 'ten');
|
|
19
|
+
* skipList.set(5, 'five');
|
|
20
|
+
* skipList.set(20, 'twenty');
|
|
21
|
+
*
|
|
22
|
+
* skipList.get(10); // 'ten'
|
|
23
|
+
* skipList.range(5, 15); // [{key: 5, value: 'five'}, {key: 10, value: 'ten'}]
|
|
24
|
+
* skipList.keys(); // [5, 10, 20]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class SkipList<K, V> implements ISkipList<K, V> {
|
|
28
|
+
private head;
|
|
29
|
+
private maxLevel;
|
|
30
|
+
private probability;
|
|
31
|
+
private compare;
|
|
32
|
+
private currentLevel;
|
|
33
|
+
private count;
|
|
34
|
+
constructor(options?: SkipListOptions<K>);
|
|
35
|
+
/**
|
|
36
|
+
* Create a new node with random level
|
|
37
|
+
*/
|
|
38
|
+
private createNode;
|
|
39
|
+
/**
|
|
40
|
+
* Generate random level for new node
|
|
41
|
+
*/
|
|
42
|
+
private randomLevel;
|
|
43
|
+
/**
|
|
44
|
+
* Find the position where key should be or is located
|
|
45
|
+
* Returns update array with predecessors at each level
|
|
46
|
+
*/
|
|
47
|
+
private findUpdatePath;
|
|
48
|
+
/**
|
|
49
|
+
* Insert or update a key-value pair
|
|
50
|
+
*/
|
|
51
|
+
set(key: K, value: V): V | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Get value by key
|
|
54
|
+
*/
|
|
55
|
+
get(key: K): V | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Check if key exists
|
|
58
|
+
*/
|
|
59
|
+
has(key: K): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Delete a key
|
|
62
|
+
*/
|
|
63
|
+
delete(key: K): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Get all entries in sorted order
|
|
66
|
+
*/
|
|
67
|
+
entries(): Array<[K, V]>;
|
|
68
|
+
/**
|
|
69
|
+
* Get all keys in sorted order
|
|
70
|
+
*/
|
|
71
|
+
keys(): K[];
|
|
72
|
+
/**
|
|
73
|
+
* Get all values in sorted order by key
|
|
74
|
+
*/
|
|
75
|
+
values(): V[];
|
|
76
|
+
/**
|
|
77
|
+
* Get range of entries
|
|
78
|
+
*/
|
|
79
|
+
range(startKey: K, endKey: K): RangeResult<K, V>[];
|
|
80
|
+
/**
|
|
81
|
+
* Get minimum entry
|
|
82
|
+
*/
|
|
83
|
+
min(): RangeResult<K, V> | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Get maximum entry
|
|
86
|
+
*/
|
|
87
|
+
max(): RangeResult<K, V> | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Get kth smallest entry (0-indexed)
|
|
90
|
+
*/
|
|
91
|
+
getKth(k: number): RangeResult<K, V> | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Count entries in range
|
|
94
|
+
*/
|
|
95
|
+
countRange(startKey: K, endKey: K): number;
|
|
96
|
+
/**
|
|
97
|
+
* Find floor (largest key <= given key)
|
|
98
|
+
*/
|
|
99
|
+
floor(key: K): RangeResult<K, V> | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Find ceiling (smallest key >= given key)
|
|
102
|
+
*/
|
|
103
|
+
ceiling(key: K): RangeResult<K, V> | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Iterate over all entries
|
|
106
|
+
*/
|
|
107
|
+
forEach(callback: (value: V, key: K) => void): void;
|
|
108
|
+
/**
|
|
109
|
+
* Clear all entries
|
|
110
|
+
*/
|
|
111
|
+
clear(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Get statistics
|
|
114
|
+
*/
|
|
115
|
+
getStats(): SkipListStats;
|
|
116
|
+
/**
|
|
117
|
+
* Get size
|
|
118
|
+
*/
|
|
119
|
+
get size(): number;
|
|
120
|
+
/**
|
|
121
|
+
* Check if empty
|
|
122
|
+
*/
|
|
123
|
+
get isEmpty(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Create skip list from entries
|
|
126
|
+
*/
|
|
127
|
+
static from<K, V>(entries: Array<[K, V]>, options?: SkipListOptions<K>): SkipList<K, V>;
|
|
128
|
+
/**
|
|
129
|
+
* Debug: Print structure
|
|
130
|
+
*/
|
|
131
|
+
toString(): string;
|
|
132
|
+
/**
|
|
133
|
+
* Debug: Validate structure
|
|
134
|
+
*/
|
|
135
|
+
validate(): boolean;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=skip-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-list.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/skip-list/skip-list.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,SAAS,EAET,eAAe,EACf,WAAW,EACX,aAAa,EACd,MAAM,uBAAuB,CAAC;AAI/B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,KAAK,CAAS;gBAEV,OAAO,GAAE,eAAe,CAAC,CAAC,CAAM;IAW5C;;OAEG;IACH,OAAO,CAAC,UAAU;IAQlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAkBtB;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAmCpC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAuB1B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIpB;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IA6BvB;;OAEG;IACH,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAYxB;;OAEG;IACH,IAAI,IAAI,CAAC,EAAE;IAYX;;OAEG;IACH,MAAM,IAAI,CAAC,EAAE;IAYb;;OAEG;IACH,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;IA0BlD;;OAEG;IACH,GAAG,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;IAQpC;;OAEG;IACH,GAAG,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;IAsBpC;;OAEG;IACH,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;IAoBhD;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM;IAI1C;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;IAqB5C;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;IAqB9C;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI;IASnD;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,QAAQ,IAAI,aAAa;IA0BzB;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EACd,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAC3B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAQjB;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,QAAQ,IAAI,OAAO;CAyBpB"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skip List interfaces for ZenGrid
|
|
3
|
+
* Probabilistic data structure for efficient sorted data management
|
|
4
|
+
*/
|
|
5
|
+
import type { Comparator } from '../../types';
|
|
6
|
+
/**
|
|
7
|
+
* Skip List Node representing a key-value pair at a specific level
|
|
8
|
+
*/
|
|
9
|
+
export interface SkipListNode<K, V> {
|
|
10
|
+
key: K;
|
|
11
|
+
value: V;
|
|
12
|
+
forward: Array<SkipListNode<K, V> | null>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Range query result
|
|
16
|
+
*/
|
|
17
|
+
export interface RangeResult<K, V> {
|
|
18
|
+
key: K;
|
|
19
|
+
value: V;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Skip List statistics
|
|
23
|
+
*/
|
|
24
|
+
export interface SkipListStats {
|
|
25
|
+
/** Total number of entries */
|
|
26
|
+
size: number;
|
|
27
|
+
/** Current maximum level */
|
|
28
|
+
level: number;
|
|
29
|
+
/** Maximum allowed levels */
|
|
30
|
+
maxLevel: number;
|
|
31
|
+
/** Average level of nodes */
|
|
32
|
+
averageLevel: number;
|
|
33
|
+
/** Memory usage estimate in bytes */
|
|
34
|
+
memoryBytes: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Skip List interface
|
|
38
|
+
*
|
|
39
|
+
* A probabilistic alternative to balanced trees that maintains sorted data.
|
|
40
|
+
* Uses multiple levels of linked lists with exponentially decreasing probability.
|
|
41
|
+
*
|
|
42
|
+
* Use cases:
|
|
43
|
+
* - Sorted column data in grids
|
|
44
|
+
* - Maintaining sorted indices
|
|
45
|
+
* - Range queries on sorted data
|
|
46
|
+
* - Finding kth smallest/largest element
|
|
47
|
+
* - Ordered iteration
|
|
48
|
+
* - Implementing sorted maps/sets
|
|
49
|
+
*
|
|
50
|
+
* Performance:
|
|
51
|
+
* - Search: O(log n) average, O(n) worst case
|
|
52
|
+
* - Insert: O(log n) average, O(n) worst case
|
|
53
|
+
* - Delete: O(log n) average, O(n) worst case
|
|
54
|
+
* - Range query: O(log n + k) where k = results
|
|
55
|
+
* - Space: O(n log n) average
|
|
56
|
+
*
|
|
57
|
+
* Advantages over balanced trees:
|
|
58
|
+
* - Simpler implementation (no rotations)
|
|
59
|
+
* - Better cache locality
|
|
60
|
+
* - Lock-free concurrent implementation possible
|
|
61
|
+
* - Predictable performance (no worst-case rebalancing)
|
|
62
|
+
*/
|
|
63
|
+
export interface ISkipList<K, V> {
|
|
64
|
+
/**
|
|
65
|
+
* Insert or update a key-value pair
|
|
66
|
+
* @param key - The key to insert
|
|
67
|
+
* @param value - The value to associate with the key
|
|
68
|
+
* @returns The previous value if key existed, undefined otherwise
|
|
69
|
+
* @complexity O(log n) average
|
|
70
|
+
*/
|
|
71
|
+
set(key: K, value: V): V | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Get the value associated with a key
|
|
74
|
+
* @param key - The key to search for
|
|
75
|
+
* @returns The value if found, undefined otherwise
|
|
76
|
+
* @complexity O(log n) average
|
|
77
|
+
*/
|
|
78
|
+
get(key: K): V | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a key exists in the skip list
|
|
81
|
+
* @param key - The key to check
|
|
82
|
+
* @complexity O(log n) average
|
|
83
|
+
*/
|
|
84
|
+
has(key: K): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Delete a key-value pair
|
|
87
|
+
* @param key - The key to delete
|
|
88
|
+
* @returns true if the key was found and deleted
|
|
89
|
+
* @complexity O(log n) average
|
|
90
|
+
*/
|
|
91
|
+
delete(key: K): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Get all entries in sorted order
|
|
94
|
+
* @returns Array of [key, value] tuples
|
|
95
|
+
* @complexity O(n)
|
|
96
|
+
*/
|
|
97
|
+
entries(): Array<[K, V]>;
|
|
98
|
+
/**
|
|
99
|
+
* Get all keys in sorted order
|
|
100
|
+
* @returns Array of keys
|
|
101
|
+
* @complexity O(n)
|
|
102
|
+
*/
|
|
103
|
+
keys(): K[];
|
|
104
|
+
/**
|
|
105
|
+
* Get all values in sorted order by key
|
|
106
|
+
* @returns Array of values
|
|
107
|
+
* @complexity O(n)
|
|
108
|
+
*/
|
|
109
|
+
values(): V[];
|
|
110
|
+
/**
|
|
111
|
+
* Get range of entries between two keys (inclusive)
|
|
112
|
+
* @param startKey - Start of range (inclusive)
|
|
113
|
+
* @param endKey - End of range (inclusive)
|
|
114
|
+
* @returns Array of entries in range
|
|
115
|
+
* @complexity O(log n + k) where k = results
|
|
116
|
+
*/
|
|
117
|
+
range(startKey: K, endKey: K): RangeResult<K, V>[];
|
|
118
|
+
/**
|
|
119
|
+
* Get the minimum (first) entry
|
|
120
|
+
* @returns The minimum entry or undefined if empty
|
|
121
|
+
* @complexity O(1)
|
|
122
|
+
*/
|
|
123
|
+
min(): RangeResult<K, V> | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Get the maximum (last) entry
|
|
126
|
+
* @returns The maximum entry or undefined if empty
|
|
127
|
+
* @complexity O(log n)
|
|
128
|
+
*/
|
|
129
|
+
max(): RangeResult<K, V> | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Get the kth smallest entry (0-indexed)
|
|
132
|
+
* @param k - Index (0 = smallest)
|
|
133
|
+
* @returns The kth entry or undefined if k >= size
|
|
134
|
+
* @complexity O(k) - could be improved to O(log n) with span tracking
|
|
135
|
+
*/
|
|
136
|
+
getKth(k: number): RangeResult<K, V> | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Count entries in a range
|
|
139
|
+
* @param startKey - Start of range (inclusive)
|
|
140
|
+
* @param endKey - End of range (inclusive)
|
|
141
|
+
* @complexity O(log n + k) where k = count
|
|
142
|
+
*/
|
|
143
|
+
countRange(startKey: K, endKey: K): number;
|
|
144
|
+
/**
|
|
145
|
+
* Find the closest key less than or equal to the given key
|
|
146
|
+
* @param key - The key to search for
|
|
147
|
+
* @returns The floor entry or undefined if no such key exists
|
|
148
|
+
* @complexity O(log n)
|
|
149
|
+
*/
|
|
150
|
+
floor(key: K): RangeResult<K, V> | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Find the closest key greater than or equal to the given key
|
|
153
|
+
* @param key - The key to search for
|
|
154
|
+
* @returns The ceiling entry or undefined if no such key exists
|
|
155
|
+
* @complexity O(log n)
|
|
156
|
+
*/
|
|
157
|
+
ceiling(key: K): RangeResult<K, V> | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Iterate over all entries in sorted order
|
|
160
|
+
* @param callback - Function to call for each entry
|
|
161
|
+
* @complexity O(n)
|
|
162
|
+
*/
|
|
163
|
+
forEach(callback: (value: V, key: K) => void): void;
|
|
164
|
+
/**
|
|
165
|
+
* Clear all entries
|
|
166
|
+
* @complexity O(1)
|
|
167
|
+
*/
|
|
168
|
+
clear(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Get statistics about the skip list
|
|
171
|
+
*/
|
|
172
|
+
getStats(): SkipListStats;
|
|
173
|
+
/**
|
|
174
|
+
* Number of entries in the skip list
|
|
175
|
+
*/
|
|
176
|
+
readonly size: number;
|
|
177
|
+
/**
|
|
178
|
+
* Whether the skip list is empty
|
|
179
|
+
*/
|
|
180
|
+
readonly isEmpty: boolean;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Options for creating a Skip List
|
|
184
|
+
*/
|
|
185
|
+
export interface SkipListOptions<K> {
|
|
186
|
+
/**
|
|
187
|
+
* Custom comparator function
|
|
188
|
+
* Defaults to natural ordering for numbers/strings
|
|
189
|
+
*/
|
|
190
|
+
comparator?: Comparator<K>;
|
|
191
|
+
/**
|
|
192
|
+
* Maximum number of levels
|
|
193
|
+
* @default 32 (supports ~4 billion elements efficiently)
|
|
194
|
+
*/
|
|
195
|
+
maxLevel?: number;
|
|
196
|
+
/**
|
|
197
|
+
* Probability for level increase
|
|
198
|
+
* @default 0.5 (standard Skip List probability)
|
|
199
|
+
*/
|
|
200
|
+
probability?: number;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Default comparator for common types
|
|
204
|
+
*/
|
|
205
|
+
export declare function defaultComparator<K>(a: K, b: K): number;
|
|
206
|
+
/**
|
|
207
|
+
* Utility functions for Skip List
|
|
208
|
+
*/
|
|
209
|
+
export declare const SkipListUtils: {
|
|
210
|
+
/**
|
|
211
|
+
* Calculate expected maximum level for n elements
|
|
212
|
+
*/
|
|
213
|
+
expectedMaxLevel(n: number, probability?: number): number;
|
|
214
|
+
/**
|
|
215
|
+
* Calculate expected number of nodes at level i
|
|
216
|
+
*/
|
|
217
|
+
expectedNodesAtLevel(n: number, level: number, probability?: number): number;
|
|
218
|
+
/**
|
|
219
|
+
* Calculate expected memory usage
|
|
220
|
+
*/
|
|
221
|
+
estimateMemory(n: number, _maxLevel: number, probability?: number): number;
|
|
222
|
+
};
|
|
223
|
+
//# sourceMappingURL=skip-list.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-list.interface.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/skip-list/skip-list.interface.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sparse Matrix - Memory-efficient 2D grid storage
|
|
3
|
+
*/
|
|
4
|
+
export { SparseMatrix } from './sparse-matrix';
|
|
5
|
+
export type { ReadonlySparseMatrix, SparseMatrix as ISparseMatrix, SparseMatrixOptions, } from './sparse-matrix.interface';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/sparse-matrix/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,oBAAoB,EACpB,YAAY,IAAI,aAAa,EAC7B,mBAAmB,GACpB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { SparseMatrix as ISparseMatrix, SparseMatrixOptions } from './sparse-matrix.interface';
|
|
2
|
+
/**
|
|
3
|
+
* SparseMatrix implementation using Map of Maps
|
|
4
|
+
*
|
|
5
|
+
* Memory-efficient storage for large grids where most cells are empty.
|
|
6
|
+
* Uses nested Maps with numeric keys for optimal performance.
|
|
7
|
+
*
|
|
8
|
+
* Structure: Map<row, Map<col, value>>
|
|
9
|
+
* - Row operations are O(1) - direct map lookup
|
|
10
|
+
* - Column operations are O(r) where r = rows with data (not total cells)
|
|
11
|
+
* - Memory efficient: only allocates maps for rows that have data
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const matrix = new SparseMatrix<string>();
|
|
16
|
+
* matrix.set(0, 0, 'A1');
|
|
17
|
+
* matrix.set(1000, 1000, 'B1000');
|
|
18
|
+
* console.log(matrix.get(0, 0)); // 'A1'
|
|
19
|
+
* console.log(matrix.size); // 2 (only stores non-empty cells)
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class SparseMatrix<T> implements ISparseMatrix<T> {
|
|
23
|
+
private rows;
|
|
24
|
+
private cellCount;
|
|
25
|
+
constructor(_options?: SparseMatrixOptions);
|
|
26
|
+
get(row: number, col: number): T | undefined;
|
|
27
|
+
has(row: number, col: number): boolean;
|
|
28
|
+
set(row: number, col: number, value: T): void;
|
|
29
|
+
delete(row: number, col: number): boolean;
|
|
30
|
+
clear(): void;
|
|
31
|
+
getRow(row: number): ReadonlyMap<number, T>;
|
|
32
|
+
getColumn(col: number): ReadonlyMap<number, T>;
|
|
33
|
+
setRow(row: number, values: Map<number, T>): void;
|
|
34
|
+
deleteRow(row: number): number;
|
|
35
|
+
deleteColumn(col: number): number;
|
|
36
|
+
get size(): number;
|
|
37
|
+
[Symbol.iterator](): IterableIterator<[number, number, T]>;
|
|
38
|
+
/**
|
|
39
|
+
* Convert to dense 2D array (for debugging/testing)
|
|
40
|
+
* WARNING: Can be memory-intensive for large sparse matrices
|
|
41
|
+
*/
|
|
42
|
+
toDenseArray(maxRow: number, maxCol: number, defaultValue: T): T[][];
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=sparse-matrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparse-matrix.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/sparse-matrix/sparse-matrix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,IAAI,aAAa,EAC7B,mBAAmB,EACpB,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IACtD,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,SAAS,CAAS;gBAEd,QAAQ,GAAE,mBAAwB;IAO9C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAK5C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAKtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAuB7C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAmBzC,KAAK,IAAI,IAAI;IAKb,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;IAM3C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;IAc9C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI;IAMjD,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAc9B,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAyBjC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAEA,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAQ3D;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE;CAarE"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sparse Matrix interfaces for ZenGrid
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Read-only view of a sparse matrix
|
|
6
|
+
*/
|
|
7
|
+
export interface ReadonlySparseMatrix<T> {
|
|
8
|
+
/**
|
|
9
|
+
* Get value at position (row, col)
|
|
10
|
+
* @param row - Row index
|
|
11
|
+
* @param col - Column index
|
|
12
|
+
* @returns Value at position or undefined if not set
|
|
13
|
+
* @complexity O(1)
|
|
14
|
+
*/
|
|
15
|
+
get(row: number, col: number): T | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a value exists at position (row, col)
|
|
18
|
+
* @param row - Row index
|
|
19
|
+
* @param col - Column index
|
|
20
|
+
* @returns true if value exists
|
|
21
|
+
* @complexity O(1)
|
|
22
|
+
*/
|
|
23
|
+
has(row: number, col: number): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get all values in a row
|
|
26
|
+
* @param row - Row index
|
|
27
|
+
* @returns Map of column index to value
|
|
28
|
+
* @complexity O(1) - direct map lookup
|
|
29
|
+
*/
|
|
30
|
+
getRow(row: number): ReadonlyMap<number, T>;
|
|
31
|
+
/**
|
|
32
|
+
* Get all values in a column
|
|
33
|
+
* @param col - Column index
|
|
34
|
+
* @returns Map of row index to value
|
|
35
|
+
* @complexity O(r) where r = number of rows with data (not total cells)
|
|
36
|
+
*/
|
|
37
|
+
getColumn(col: number): ReadonlyMap<number, T>;
|
|
38
|
+
/**
|
|
39
|
+
* Number of non-empty cells
|
|
40
|
+
*/
|
|
41
|
+
readonly size: number;
|
|
42
|
+
/**
|
|
43
|
+
* Iterate over all (row, col, value) tuples
|
|
44
|
+
*/
|
|
45
|
+
[Symbol.iterator](): IterableIterator<[number, number, T]>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Mutable sparse matrix interface
|
|
49
|
+
*/
|
|
50
|
+
export interface SparseMatrix<T> extends ReadonlySparseMatrix<T> {
|
|
51
|
+
/**
|
|
52
|
+
* Set value at position (row, col)
|
|
53
|
+
* @param row - Row index
|
|
54
|
+
* @param col - Column index
|
|
55
|
+
* @param value - Value to set
|
|
56
|
+
* @complexity O(1)
|
|
57
|
+
*/
|
|
58
|
+
set(row: number, col: number, value: T): void;
|
|
59
|
+
/**
|
|
60
|
+
* Delete value at position (row, col)
|
|
61
|
+
* @param row - Row index
|
|
62
|
+
* @param col - Column index
|
|
63
|
+
* @returns true if value was deleted
|
|
64
|
+
* @complexity O(1)
|
|
65
|
+
*/
|
|
66
|
+
delete(row: number, col: number): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Clear all values
|
|
69
|
+
* @complexity O(1)
|
|
70
|
+
*/
|
|
71
|
+
clear(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Set multiple values in a row
|
|
74
|
+
* @param row - Row index
|
|
75
|
+
* @param values - Map of column index to value
|
|
76
|
+
* @complexity O(k) where k = values.size
|
|
77
|
+
*/
|
|
78
|
+
setRow(row: number, values: Map<number, T>): void;
|
|
79
|
+
/**
|
|
80
|
+
* Delete entire row
|
|
81
|
+
* @param row - Row index
|
|
82
|
+
* @returns Number of cells deleted
|
|
83
|
+
* @complexity O(1) - direct map deletion
|
|
84
|
+
*/
|
|
85
|
+
deleteRow(row: number): number;
|
|
86
|
+
/**
|
|
87
|
+
* Delete entire column
|
|
88
|
+
* @param col - Column index
|
|
89
|
+
* @returns Number of cells deleted
|
|
90
|
+
* @complexity O(r) where r = number of rows with data
|
|
91
|
+
*/
|
|
92
|
+
deleteColumn(col: number): number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Options for creating a sparse matrix
|
|
96
|
+
*/
|
|
97
|
+
export interface SparseMatrixOptions {
|
|
98
|
+
/**
|
|
99
|
+
* Initial capacity (number of expected rows with data)
|
|
100
|
+
* Hint for Map pre-allocation to reduce resizing
|
|
101
|
+
* @default 16
|
|
102
|
+
*/
|
|
103
|
+
initialCapacity?: number;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=sparse-matrix.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparse-matrix.interface.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/sparse-matrix/sparse-matrix.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAE7C;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAEvC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAE5C;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAE/C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;CAC5D;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,CAAC;IAC9D;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAE9C;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAE1C;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IAElD;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAE/B;;;;;OAKG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/suffix-array/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { ISuffixArray, SuffixArrayOptions, SuffixSearchResult, SuffixArrayStats } from './suffix-array.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Suffix Array - Efficient substring search data structure
|
|
4
|
+
*
|
|
5
|
+
* A suffix array is a sorted array of all suffixes of a string.
|
|
6
|
+
* It enables fast substring search in O(m log n) time.
|
|
7
|
+
*
|
|
8
|
+
* **Time Complexity:**
|
|
9
|
+
* - Construction: O(n log² n) where n = text length
|
|
10
|
+
* - Search: O(m log n) where m = pattern length
|
|
11
|
+
* - Count: O(m log n)
|
|
12
|
+
* - Contains: O(m log n)
|
|
13
|
+
*
|
|
14
|
+
* **Space Complexity:** O(n)
|
|
15
|
+
*
|
|
16
|
+
* **Use Cases in Grid:**
|
|
17
|
+
* - Substring search: Find cells containing "phone" (matches "iPhone")
|
|
18
|
+
* - Filter by contains: Show rows where column contains pattern
|
|
19
|
+
* - Autocomplete: Find all values containing typed text
|
|
20
|
+
* - Fuzzy search: Find similar values
|
|
21
|
+
*
|
|
22
|
+
* @example Basic Usage
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const sa = new SuffixArray("banana");
|
|
25
|
+
*
|
|
26
|
+
* // Search for pattern
|
|
27
|
+
* const positions = sa.search("ana");
|
|
28
|
+
* console.log(positions); // [1, 3] - "banana" has "ana" at positions 1 and 3
|
|
29
|
+
*
|
|
30
|
+
* // Check if contains
|
|
31
|
+
* console.log(sa.contains("nan")); // true
|
|
32
|
+
* console.log(sa.contains("xyz")); // false
|
|
33
|
+
*
|
|
34
|
+
* // Count occurrences
|
|
35
|
+
* console.log(sa.count("ana")); // 2
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example Grid Integration
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Index a column for substring search
|
|
41
|
+
* const columnData = grid.getColumn(0); // ["Apple iPhone", "Samsung Galaxy", ...]
|
|
42
|
+
* const combinedText = columnData.join("\0"); // Use null separator
|
|
43
|
+
* const sa = new SuffixArray(combinedText);
|
|
44
|
+
*
|
|
45
|
+
* // Find all cells containing "phone"
|
|
46
|
+
* const positions = sa.search("phone");
|
|
47
|
+
* // Convert positions back to row indices
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare class SuffixArray implements ISuffixArray {
|
|
51
|
+
private text;
|
|
52
|
+
private suffixArray;
|
|
53
|
+
private lcp;
|
|
54
|
+
private options;
|
|
55
|
+
constructor(text: string, options?: SuffixArrayOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Search for a pattern in the text
|
|
58
|
+
*/
|
|
59
|
+
search(pattern: string): number[];
|
|
60
|
+
/**
|
|
61
|
+
* Search with context
|
|
62
|
+
*/
|
|
63
|
+
searchWithContext(pattern: string, contextLength?: number): SuffixSearchResult[];
|
|
64
|
+
/**
|
|
65
|
+
* Count occurrences of a pattern
|
|
66
|
+
*/
|
|
67
|
+
count(pattern: string): number;
|
|
68
|
+
/**
|
|
69
|
+
* Check if pattern exists
|
|
70
|
+
*/
|
|
71
|
+
contains(pattern: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Find the longest repeated substring using LCP array
|
|
74
|
+
*/
|
|
75
|
+
longestRepeatedSubstring(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Get all unique substrings of a given length
|
|
78
|
+
*/
|
|
79
|
+
uniqueSubstrings(length: number): string[];
|
|
80
|
+
/**
|
|
81
|
+
* Get statistics
|
|
82
|
+
*/
|
|
83
|
+
getStats(): SuffixArrayStats;
|
|
84
|
+
/**
|
|
85
|
+
* Clear the suffix array
|
|
86
|
+
*/
|
|
87
|
+
clear(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Build suffix array using simple O(n log² n) algorithm
|
|
90
|
+
*/
|
|
91
|
+
private buildSuffixArray;
|
|
92
|
+
/**
|
|
93
|
+
* Build LCP (Longest Common Prefix) array using Kasai's algorithm
|
|
94
|
+
* Time: O(n)
|
|
95
|
+
*/
|
|
96
|
+
private buildLCPArray;
|
|
97
|
+
/**
|
|
98
|
+
* Binary search to find range of suffixes that start with pattern
|
|
99
|
+
*/
|
|
100
|
+
private findRange;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=suffix-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suffix-array.d.ts","sourceRoot":"","sources":["../../../../../../packages/shared/src/data-structures/suffix-array/suffix-array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,qBAAa,WAAY,YAAW,YAAY;IAC9C,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,GAAG,CAAyB;IACpC,OAAO,CAAC,OAAO,CAA+B;gBAElC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB;IAkB1D;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAgBjC;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,GAAE,MAAW,GAAG,kBAAkB,EAAE;IAmBpF;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAW9B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOlC;;OAEG;IACH,wBAAwB,IAAI,MAAM;IAkBlC;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAY1C;;OAEG;IACH,QAAQ,IAAI,gBAAgB;IAa5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAQb;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAiBxB;;;OAGG;IACH,OAAO,CAAC,aAAa;IA6BrB;;OAEG;IACH,OAAO,CAAC,SAAS;CA0ClB"}
|