deque-typed 2.1.0 → 2.1.2
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/cjs/index.cjs +1223 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +1219 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +11 -2
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/deque-typed.js +1232 -0
- package/dist/umd/deque-typed.js.map +1 -0
- package/dist/umd/deque-typed.min.js +9 -0
- package/dist/umd/deque-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
- package/src/data-structures/binary-tree/avl-tree.ts +6 -8
- package/src/data-structures/binary-tree/binary-tree.ts +13 -15
- package/src/data-structures/binary-tree/bst.ts +6 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
- package/src/data-structures/binary-tree/tree-counter.ts +8 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +3 -3
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -28
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -24
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -1,4 +1,350 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { ElementCallback, TrieOptions } from '../../types';
|
|
9
|
+
import { IterableElementBase } from '../base';
|
|
10
|
+
/**
|
|
11
|
+
* Node used by Trie to store one character and its children.
|
|
12
|
+
* @remarks Time O(1), Space O(1)
|
|
13
|
+
*/
|
|
14
|
+
export declare class TrieNode {
|
|
15
|
+
/**
|
|
16
|
+
* Create a Trie node with a character key.
|
|
17
|
+
* @remarks Time O(1), Space O(1)
|
|
18
|
+
* @returns New TrieNode instance.
|
|
19
|
+
*/
|
|
20
|
+
constructor(key: string);
|
|
21
|
+
protected _key: string;
|
|
22
|
+
/**
|
|
23
|
+
* Get the character key of this node.
|
|
24
|
+
* @remarks Time O(1), Space O(1)
|
|
25
|
+
* @returns Character key string.
|
|
26
|
+
*/
|
|
27
|
+
get key(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Set the character key of this node.
|
|
30
|
+
* @remarks Time O(1), Space O(1)
|
|
31
|
+
* @param value - New character key.
|
|
32
|
+
* @returns void
|
|
33
|
+
*/
|
|
34
|
+
set key(value: string);
|
|
35
|
+
protected _children: Map<string, TrieNode>;
|
|
36
|
+
/**
|
|
37
|
+
* Get the child map of this node.
|
|
38
|
+
* @remarks Time O(1), Space O(1)
|
|
39
|
+
* @returns Map from character to child node.
|
|
40
|
+
*/
|
|
41
|
+
get children(): Map<string, TrieNode>;
|
|
42
|
+
/**
|
|
43
|
+
* Replace the child map of this node.
|
|
44
|
+
* @remarks Time O(1), Space O(1)
|
|
45
|
+
* @param value - New map of character → node.
|
|
46
|
+
* @returns void
|
|
47
|
+
*/
|
|
48
|
+
set children(value: Map<string, TrieNode>);
|
|
49
|
+
protected _isEnd: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Check whether this node marks the end of a word.
|
|
52
|
+
* @remarks Time O(1), Space O(1)
|
|
53
|
+
* @returns True if this node ends a word.
|
|
54
|
+
*/
|
|
55
|
+
get isEnd(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Mark this node as the end of a word or not.
|
|
58
|
+
* @remarks Time O(1), Space O(1)
|
|
59
|
+
* @param value - Whether this node ends a word.
|
|
60
|
+
* @returns void
|
|
61
|
+
*/
|
|
62
|
+
set isEnd(value: boolean);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Prefix tree (Trie) for fast prefix queries and word storage.
|
|
66
|
+
* @remarks Time O(1), Space O(1)
|
|
67
|
+
* @template R
|
|
68
|
+
* 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
|
|
69
|
+
* 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
|
|
70
|
+
* 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
|
|
71
|
+
* 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
|
|
72
|
+
* 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
|
|
73
|
+
* 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
|
|
74
|
+
* 7. String Retrieval: For example, searching for a specific string in a large set of strings.
|
|
75
|
+
* 8. Autocomplete: Providing recommended words or phrases as a user types.
|
|
76
|
+
* 9. Spell Check: Checking the spelling of words.
|
|
77
|
+
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
78
|
+
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
79
|
+
* @example
|
|
80
|
+
* // Autocomplete: Prefix validation and checking
|
|
81
|
+
* const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
|
|
82
|
+
*
|
|
83
|
+
* // Get all completions for a prefix
|
|
84
|
+
* const gmailCompletions = autocomplete.getWords('gmail');
|
|
85
|
+
* console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
|
|
86
|
+
* @example
|
|
87
|
+
* // File System Path Operations
|
|
88
|
+
* const fileSystem = new Trie<string>([
|
|
89
|
+
* '/home/user/documents/file1.txt',
|
|
90
|
+
* '/home/user/documents/file2.txt',
|
|
91
|
+
* '/home/user/pictures/photo.jpg',
|
|
92
|
+
* '/home/user/pictures/vacation/',
|
|
93
|
+
* '/home/user/downloads'
|
|
94
|
+
* ]);
|
|
95
|
+
*
|
|
96
|
+
* // Find common directory prefix
|
|
97
|
+
* console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
|
|
98
|
+
*
|
|
99
|
+
* // List all files in a directory
|
|
100
|
+
* const documentsFiles = fileSystem.getWords('/home/user/documents/');
|
|
101
|
+
* console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
|
|
102
|
+
* @example
|
|
103
|
+
* // Autocomplete: Basic word suggestions
|
|
104
|
+
* // Create a trie for autocomplete
|
|
105
|
+
* const autocomplete = new Trie<string>([
|
|
106
|
+
* 'function',
|
|
107
|
+
* 'functional',
|
|
108
|
+
* 'functions',
|
|
109
|
+
* 'class',
|
|
110
|
+
* 'classes',
|
|
111
|
+
* 'classical',
|
|
112
|
+
* 'closure',
|
|
113
|
+
* 'const',
|
|
114
|
+
* 'constructor'
|
|
115
|
+
* ]);
|
|
116
|
+
*
|
|
117
|
+
* // Test autocomplete with different prefixes
|
|
118
|
+
* console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
|
|
119
|
+
* console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
|
|
120
|
+
* console.log(autocomplete.getWords('con')); // ['constructor', 'const']
|
|
121
|
+
*
|
|
122
|
+
* // Test with non-matching prefix
|
|
123
|
+
* console.log(autocomplete.getWords('xyz')); // []
|
|
124
|
+
* @example
|
|
125
|
+
* // Dictionary: Case-insensitive word lookup
|
|
126
|
+
* // Create a case-insensitive dictionary
|
|
127
|
+
* const dictionary = new Trie<string>([], { caseSensitive: false });
|
|
128
|
+
*
|
|
129
|
+
* // Add words with mixed casing
|
|
130
|
+
* dictionary.add('Hello');
|
|
131
|
+
* dictionary.add('WORLD');
|
|
132
|
+
* dictionary.add('JavaScript');
|
|
133
|
+
*
|
|
134
|
+
* // Test lookups with different casings
|
|
135
|
+
* console.log(dictionary.has('hello')); // true
|
|
136
|
+
* console.log(dictionary.has('HELLO')); // true
|
|
137
|
+
* console.log(dictionary.has('Hello')); // true
|
|
138
|
+
* console.log(dictionary.has('javascript')); // true
|
|
139
|
+
* console.log(dictionary.has('JAVASCRIPT')); // true
|
|
140
|
+
* @example
|
|
141
|
+
* // IP Address Routing Table
|
|
142
|
+
* // Add IP address prefixes and their corresponding routes
|
|
143
|
+
* const routes = {
|
|
144
|
+
* '192.168.1': 'LAN_SUBNET_1',
|
|
145
|
+
* '192.168.2': 'LAN_SUBNET_2',
|
|
146
|
+
* '10.0.0': 'PRIVATE_NETWORK_1',
|
|
147
|
+
* '10.0.1': 'PRIVATE_NETWORK_2'
|
|
148
|
+
* };
|
|
149
|
+
*
|
|
150
|
+
* const ipRoutingTable = new Trie<string>(Object.keys(routes));
|
|
151
|
+
*
|
|
152
|
+
* // Check IP address prefix matching
|
|
153
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
|
|
154
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
|
|
155
|
+
*
|
|
156
|
+
* // Validate IP address belongs to subnet
|
|
157
|
+
* const ip = '192.168.1.100';
|
|
158
|
+
* const subnet = ip.split('.').slice(0, 3).join('.');
|
|
159
|
+
* console.log(ipRoutingTable.hasPrefix(subnet)); // true
|
|
160
|
+
*/
|
|
161
|
+
export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
162
|
+
/**
|
|
163
|
+
* Create a Trie and optionally bulk-insert words.
|
|
164
|
+
* @remarks Time O(totalChars), Space O(totalChars)
|
|
165
|
+
* @param [words] - Iterable of strings (or raw records if toElementFn is provided).
|
|
166
|
+
* @param [options] - Options such as toElementFn and caseSensitive.
|
|
167
|
+
* @returns New Trie instance.
|
|
168
|
+
*/
|
|
169
|
+
constructor(words?: Iterable<string> | Iterable<R>, options?: TrieOptions<R>);
|
|
170
|
+
protected _size: number;
|
|
171
|
+
/**
|
|
172
|
+
* Get the number of stored words.
|
|
173
|
+
* @remarks Time O(1), Space O(1)
|
|
174
|
+
* @returns Word count.
|
|
175
|
+
*/
|
|
176
|
+
get size(): number;
|
|
177
|
+
protected _caseSensitive: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Get whether comparisons are case-sensitive.
|
|
180
|
+
* @remarks Time O(1), Space O(1)
|
|
181
|
+
* @returns True if case-sensitive.
|
|
182
|
+
*/
|
|
183
|
+
get caseSensitive(): boolean;
|
|
184
|
+
protected _root: TrieNode;
|
|
185
|
+
/**
|
|
186
|
+
* Get the root node.
|
|
187
|
+
* @remarks Time O(1), Space O(1)
|
|
188
|
+
* @returns Root TrieNode.
|
|
189
|
+
*/
|
|
190
|
+
get root(): TrieNode;
|
|
191
|
+
/**
|
|
192
|
+
* (Protected) Get total count for base class iteration.
|
|
193
|
+
* @remarks Time O(1), Space O(1)
|
|
194
|
+
* @returns Total number of elements.
|
|
195
|
+
*/
|
|
196
|
+
protected get _total(): number;
|
|
197
|
+
/**
|
|
198
|
+
* Insert one word into the trie.
|
|
199
|
+
* @remarks Time O(L), Space O(L)
|
|
200
|
+
* @param word - Word to insert.
|
|
201
|
+
* @returns True if the word was newly added.
|
|
202
|
+
*/
|
|
203
|
+
add(word: string): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Insert many words from an iterable.
|
|
206
|
+
* @remarks Time O(ΣL), Space O(ΣL)
|
|
207
|
+
* @param words - Iterable of strings (or raw records if toElementFn is provided).
|
|
208
|
+
* @returns Array of per-word 'added' flags.
|
|
209
|
+
*/
|
|
210
|
+
addMany(words: Iterable<string> | Iterable<R>): boolean[];
|
|
211
|
+
/**
|
|
212
|
+
* Check whether a word exists.
|
|
213
|
+
* @remarks Time O(L), Space O(1)
|
|
214
|
+
* @param word - Word to search for.
|
|
215
|
+
* @returns True if present.
|
|
216
|
+
*/
|
|
217
|
+
has(word: string): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Check whether the trie is empty.
|
|
220
|
+
* @remarks Time O(1), Space O(1)
|
|
221
|
+
* @returns True if size is 0.
|
|
222
|
+
*/
|
|
223
|
+
isEmpty(): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Remove all words and reset to a fresh root.
|
|
226
|
+
* @remarks Time O(1), Space O(1)
|
|
227
|
+
* @returns void
|
|
228
|
+
*/
|
|
229
|
+
clear(): void;
|
|
230
|
+
/**
|
|
231
|
+
* Delete one word if present.
|
|
232
|
+
* @remarks Time O(L), Space O(1)
|
|
233
|
+
* @param word - Word to delete.
|
|
234
|
+
* @returns True if a word was removed.
|
|
235
|
+
*/
|
|
236
|
+
delete(word: string): boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Compute the height (max depth) of the trie.
|
|
239
|
+
* @remarks Time O(N), Space O(H)
|
|
240
|
+
* @returns Maximum depth from root to a leaf.
|
|
241
|
+
*/
|
|
242
|
+
getHeight(): number;
|
|
243
|
+
/**
|
|
244
|
+
* Check whether input is a proper prefix of at least one word.
|
|
245
|
+
* @remarks Time O(L), Space O(1)
|
|
246
|
+
* @param input - String to test as prefix.
|
|
247
|
+
* @returns True if input is a prefix but not a full word.
|
|
248
|
+
*/
|
|
249
|
+
hasPurePrefix(input: string): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Check whether any word starts with input.
|
|
252
|
+
* @remarks Time O(L), Space O(1)
|
|
253
|
+
* @param input - String to test as prefix.
|
|
254
|
+
* @returns True if input matches a path from root.
|
|
255
|
+
*/
|
|
256
|
+
hasPrefix(input: string): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Check whether the trie’s longest common prefix equals input.
|
|
259
|
+
* @remarks Time O(min(H,L)), Space O(1)
|
|
260
|
+
* @param input - Candidate longest common prefix.
|
|
261
|
+
* @returns True if input equals the common prefix.
|
|
262
|
+
*/
|
|
263
|
+
hasCommonPrefix(input: string): boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Return the longest common prefix among all words.
|
|
266
|
+
* @remarks Time O(H), Space O(1)
|
|
267
|
+
* @returns The longest common prefix string.
|
|
268
|
+
*/
|
|
269
|
+
getLongestCommonPrefix(): string;
|
|
270
|
+
/**
|
|
271
|
+
* Collect words under a prefix up to a maximum count.
|
|
272
|
+
* @remarks Time O(K·L), Space O(K·L)
|
|
273
|
+
* @param [prefix] - Prefix to match; default empty string for root.
|
|
274
|
+
* @param [max] - Maximum number of words to return; default is Number.MAX_SAFE_INTEGER.
|
|
275
|
+
* @param [isAllWhenEmptyPrefix] - When true, collect from root even if prefix is empty.
|
|
276
|
+
* @returns Array of collected words (at most max).
|
|
277
|
+
*/
|
|
278
|
+
getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
|
|
279
|
+
/**
|
|
280
|
+
* Deep clone this trie by iterating and inserting all words.
|
|
281
|
+
* @remarks Time O(ΣL), Space O(ΣL)
|
|
282
|
+
* @returns A new trie with the same words and options.
|
|
283
|
+
*/
|
|
284
|
+
clone(): this;
|
|
285
|
+
/**
|
|
286
|
+
* Filter words into a new trie of the same class.
|
|
287
|
+
* @remarks Time O(ΣL), Space O(ΣL)
|
|
288
|
+
* @param predicate - Predicate (word, index, trie) → boolean to keep word.
|
|
289
|
+
* @param [thisArg] - Value for `this` inside the predicate.
|
|
290
|
+
* @returns A new trie containing words that satisfy the predicate.
|
|
291
|
+
*/
|
|
292
|
+
filter(predicate: ElementCallback<string, R, boolean>, thisArg?: any): this;
|
|
293
|
+
map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: any): Trie<RM>;
|
|
294
|
+
/**
|
|
295
|
+
* Map words into a new trie (possibly different record type).
|
|
296
|
+
* @remarks Time O(ΣL), Space O(ΣL)
|
|
297
|
+
* @template EM
|
|
298
|
+
* @template RM
|
|
299
|
+
* @param callback - Mapping function (word, index, trie) → newWord (string).
|
|
300
|
+
* @param [options] - Options for the output trie (e.g., toElementFn, caseSensitive).
|
|
301
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
302
|
+
* @returns A new Trie constructed from mapped words.
|
|
303
|
+
*/
|
|
304
|
+
map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: any): IterableElementBase<EM, RM>;
|
|
305
|
+
/**
|
|
306
|
+
* Map words into a new trie of the same element type.
|
|
307
|
+
* @remarks Time O(ΣL), Space O(ΣL)
|
|
308
|
+
* @param callback - Mapping function (word, index, trie) → string.
|
|
309
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
310
|
+
* @returns A new trie with mapped words.
|
|
311
|
+
*/
|
|
312
|
+
mapSame(callback: ElementCallback<string, R, string>, thisArg?: any): this;
|
|
313
|
+
/**
|
|
314
|
+
* (Protected) Create an empty instance of the same concrete class.
|
|
315
|
+
* @remarks Time O(1), Space O(1)
|
|
316
|
+
* @param [options] - Options forwarded to the constructor.
|
|
317
|
+
* @returns An empty like-kind trie instance.
|
|
318
|
+
*/
|
|
319
|
+
protected _createInstance(options?: TrieOptions<R>): this;
|
|
320
|
+
/**
|
|
321
|
+
* (Protected) Create a like-kind trie and seed it from an iterable.
|
|
322
|
+
* @remarks Time O(ΣL), Space O(ΣL)
|
|
323
|
+
* @template RM
|
|
324
|
+
* @param [elements] - Iterable used to seed the new trie.
|
|
325
|
+
* @param [options] - Options forwarded to the constructor.
|
|
326
|
+
* @returns A like-kind Trie instance.
|
|
327
|
+
*/
|
|
328
|
+
protected _createLike<RM>(elements?: Iterable<string> | Iterable<RM>, options?: TrieOptions<RM>): Trie<RM>;
|
|
329
|
+
/**
|
|
330
|
+
* (Protected) Spawn an empty like-kind trie instance.
|
|
331
|
+
* @remarks Time O(1), Space O(1)
|
|
332
|
+
* @template RM
|
|
333
|
+
* @param [options] - Options forwarded to the constructor.
|
|
334
|
+
* @returns An empty like-kind Trie instance.
|
|
335
|
+
*/
|
|
336
|
+
protected _spawnLike<RM>(options?: TrieOptions<RM>): Trie<RM>;
|
|
337
|
+
/**
|
|
338
|
+
* (Protected) Iterate all words in lexicographic order of edges.
|
|
339
|
+
* @remarks Time O(ΣL), Space O(H)
|
|
340
|
+
* @returns Iterator of words.
|
|
341
|
+
*/
|
|
342
|
+
protected _getIterator(): IterableIterator<string>;
|
|
343
|
+
/**
|
|
344
|
+
* (Protected) Normalize a string according to case sensitivity.
|
|
345
|
+
* @remarks Time O(L), Space O(L)
|
|
346
|
+
* @param str - Input string to normalize.
|
|
347
|
+
* @returns Normalized string based on caseSensitive.
|
|
348
|
+
*/
|
|
349
|
+
protected _caseProcess(str: string): string;
|
|
350
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
export * from './data-structures/queue/deque';
|
|
9
|
+
export * from './types/data-structures/queue/deque';
|
|
10
|
+
export * from './types/common';
|
|
11
|
+
export * from './types/utils';
|
|
2
12
|
export * from './common';
|
|
3
|
-
export * from './utils';
|
|
@@ -5,7 +5,7 @@ import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, DFSOrderPattern
|
|
|
5
5
|
* K = key, V = value, R = raw/record used with toEntryFn (optional).
|
|
6
6
|
* Transforming methods like `map` use method-level generics MK/MV/MR.
|
|
7
7
|
*/
|
|
8
|
-
export interface IBinaryTree<K = any, V = any, R
|
|
8
|
+
export interface IBinaryTree<K = any, V = any, R = any> {
|
|
9
9
|
readonly size: number;
|
|
10
10
|
readonly root: BinaryTreeNode<K, V> | null | undefined;
|
|
11
11
|
readonly isMapMode: boolean;
|
|
@@ -14,7 +14,7 @@ export interface IBinaryTree<K = any, V = any, R extends object = object> {
|
|
|
14
14
|
readonly store: Map<K, V | undefined>;
|
|
15
15
|
readonly toEntryFn?: ToEntryFn<K, V, R>;
|
|
16
16
|
readonly isDuplicate: boolean;
|
|
17
|
-
|
|
17
|
+
createNode(key: K, value?: BinaryTreeNode<K, V>['value']): BinaryTreeNode<K, V>;
|
|
18
18
|
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R>;
|
|
19
19
|
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
|
|
20
20
|
addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
|
|
@@ -53,7 +53,7 @@ export interface IBinaryTree<K = any, V = any, R extends object = object> {
|
|
|
53
53
|
search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, onlyOne?: boolean, callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
54
54
|
clone(): this;
|
|
55
55
|
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
|
|
56
|
-
map<MK = K, MV = V, MR
|
|
56
|
+
map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): IBinaryTree<MK, MV, MR>;
|
|
57
57
|
merge(anotherTree: IBinaryTree<K, V, R>): void;
|
|
58
58
|
refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
|
|
59
59
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './base';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IterationType, OptValue } from '../../common';
|
|
2
|
+
import { DFSOperation } from '../../../common';
|
|
3
|
+
export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
|
|
4
|
+
export type BinaryTreeOptions<K, V, R> = {
|
|
5
|
+
iterationType?: IterationType;
|
|
6
|
+
toEntryFn?: ToEntryFn<K, V, R>;
|
|
7
|
+
isMapMode?: boolean;
|
|
8
|
+
isDuplicate?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type BinaryTreePrintOptions = {
|
|
11
|
+
isShowUndefined?: boolean;
|
|
12
|
+
isShowNull?: boolean;
|
|
13
|
+
isShowRedBlackNIL?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type OptNodeOrNull<NODE> = NODE | null | undefined;
|
|
16
|
+
export type BTNOptKeyOrNull<K> = K | null | undefined;
|
|
17
|
+
export type BTNEntry<K, V> = [BTNOptKeyOrNull<K>, OptValue<V>];
|
|
18
|
+
export type BTNOptKeyNodeOrNull<K, NODE> = BTNOptKeyOrNull<K> | NODE;
|
|
19
|
+
export type BTNRep<K, V, NODE> = BTNEntry<K, V> | BTNOptKeyNodeOrNull<K, NODE>;
|
|
20
|
+
export type BinaryTreeDeleteResult<NODE> = {
|
|
21
|
+
deleted: OptNodeOrNull<NODE>;
|
|
22
|
+
needBalanced: OptNodeOrNull<NODE>;
|
|
23
|
+
};
|
|
24
|
+
export type NodeCallback<NODE, D = any> = (node: NODE) => D;
|
|
25
|
+
export type NodePredicate<NODE> = (node: NODE) => boolean;
|
|
26
|
+
export type DFSStackItem<NODE> = {
|
|
27
|
+
opt: DFSOperation;
|
|
28
|
+
node: OptNodeOrNull<NODE>;
|
|
29
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BinaryTreeOptions } from './binary-tree';
|
|
2
|
+
import { Comparable } from '../../utils';
|
|
3
|
+
import { OptValue } from '../../common';
|
|
4
|
+
export type BSTOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'> & {
|
|
5
|
+
specifyComparable?: (key: K) => Comparable;
|
|
6
|
+
isReverse?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type BSTNOptKey<K> = K | undefined;
|
|
9
|
+
export type OptNode<NODE> = NODE | undefined;
|
|
10
|
+
export type BSTNEntry<K, V> = [BSTNOptKey<K>, OptValue<V>];
|
|
11
|
+
export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
|
|
12
|
+
export type BSTNRep<K, V, NODE> = BSTNEntry<K, V> | BSTNOptKeyOrNode<K, NODE>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export * from './binary-tree';
|
|
2
2
|
export * from './bst';
|
|
3
|
-
export * from './binary-indexed-tree';
|
|
4
|
-
export * from './segment-tree';
|
|
5
3
|
export * from './avl-tree';
|
|
6
|
-
export * from './
|
|
4
|
+
export * from './segment-tree';
|
|
7
5
|
export * from './avl-tree-multi-map';
|
|
6
|
+
export * from './red-black-tree';
|
|
8
7
|
export * from './tree-multi-map';
|
|
9
8
|
export * from './tree-counter';
|
|
10
9
|
export * from './avl-tree-counter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SegmentTreeNodeVal = number;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type VertexKey = string | number;
|
|
2
|
+
export type DijkstraResult<V> = {
|
|
3
|
+
distMap: Map<V, number>;
|
|
4
|
+
distPaths?: Map<V, V[]>;
|
|
5
|
+
preMap: Map<V, V | undefined>;
|
|
6
|
+
seen: Set<V>;
|
|
7
|
+
paths: V[][];
|
|
8
|
+
minDist: number;
|
|
9
|
+
minPath: V[];
|
|
10
|
+
} | undefined;
|
|
11
|
+
export type GraphOptions<V = any> = {
|
|
12
|
+
vertexValueInitializer?: (key: VertexKey) => V;
|
|
13
|
+
defaultEdgeWeight?: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TopologicalStatus = 0 | 1 | 2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MapGraphCoordinate = [number, number];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type HashMapLinkedNode<K, V> = {
|
|
2
|
+
key: K;
|
|
3
|
+
value: V;
|
|
4
|
+
next: HashMapLinkedNode<K, V>;
|
|
5
|
+
prev: HashMapLinkedNode<K, V>;
|
|
6
|
+
};
|
|
7
|
+
export type LinkedHashMapOptions<K, V, R> = {
|
|
8
|
+
hashFn?: (key: K) => string;
|
|
9
|
+
objHashFn?: (key: K) => object;
|
|
10
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
11
|
+
};
|
|
12
|
+
export type HashMapOptions<K, V, R> = {
|
|
13
|
+
hashFn?: (key: K) => string;
|
|
14
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
15
|
+
};
|
|
16
|
+
export type HashMapStoreItem<K, V> = {
|
|
17
|
+
key: K;
|
|
18
|
+
value: V;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './heap';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Direction = 'up' | 'right' | 'down' | 'left';
|
|
2
|
+
export type Turning = {
|
|
3
|
+
[key in Direction]: Direction;
|
|
4
|
+
};
|
|
5
|
+
export type NavigatorParams<T = any> = {
|
|
6
|
+
matrix: T[][];
|
|
7
|
+
turning: Turning;
|
|
8
|
+
onMove: (cur: [number, number]) => void;
|
|
9
|
+
init: {
|
|
10
|
+
cur: [number, number];
|
|
11
|
+
charDir: Direction;
|
|
12
|
+
VISITED: T;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|