data-structure-typed 0.8.18 → 1.3.0
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/LICENSE +21 -0
- package/README.md +690 -2
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +13 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
- package/dist/data-structures/binary-tree/avl-tree.js +110 -37
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
- package/dist/data-structures/binary-tree/binary-tree.js +27 -979
- package/dist/data-structures/binary-tree/bst.d.ts +118 -28
- package/dist/data-structures/binary-tree/bst.js +162 -124
- package/dist/data-structures/binary-tree/index.d.ts +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
- package/dist/data-structures/binary-tree/rb-tree.js +40 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
- package/dist/data-structures/binary-tree/segment-tree.js +80 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
- package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
- package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
- package/dist/data-structures/graph/abstract-graph.js +365 -92
- package/dist/data-structures/graph/directed-graph.d.ts +175 -26
- package/dist/data-structures/graph/directed-graph.js +249 -95
- package/dist/data-structures/graph/index.d.ts +1 -0
- package/dist/data-structures/graph/index.js +1 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +111 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
- package/dist/data-structures/graph/undirected-graph.js +154 -44
- package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
- package/dist/data-structures/hash/coordinate-map.js +44 -3
- package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
- package/dist/data-structures/hash/coordinate-set.js +34 -0
- package/dist/data-structures/hash/hash-table.d.ts +2 -1
- package/dist/data-structures/hash/hash-table.js +4 -0
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/hash/pair.d.ts +2 -1
- package/dist/data-structures/hash/pair.js +4 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -1
- package/dist/data-structures/hash/tree-map.js +4 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -1
- package/dist/data-structures/hash/tree-set.js +4 -0
- package/dist/data-structures/heap/heap.d.ts +62 -51
- package/dist/data-structures/heap/heap.js +106 -63
- package/dist/data-structures/heap/max-heap.d.ts +13 -4
- package/dist/data-structures/heap/max-heap.js +10 -2
- package/dist/data-structures/heap/min-heap.d.ts +14 -4
- package/dist/data-structures/heap/min-heap.js +11 -2
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
- package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
- package/dist/data-structures/linked-list/index.d.ts +1 -0
- package/dist/data-structures/linked-list/index.js +1 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
- package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +12 -0
- package/dist/data-structures/matrix/matrix.js +14 -0
- package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
- package/dist/data-structures/matrix/matrix2d.js +91 -8
- package/dist/data-structures/matrix/navigator.d.ts +37 -16
- package/dist/data-structures/matrix/navigator.js +28 -0
- package/dist/data-structures/matrix/vector2d.d.ts +156 -29
- package/dist/data-structures/matrix/vector2d.js +184 -55
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
- package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
- package/dist/data-structures/priority-queue/priority-queue.js +219 -75
- package/dist/data-structures/queue/deque.d.ts +141 -13
- package/dist/data-structures/queue/deque.js +151 -7
- package/dist/data-structures/queue/queue.d.ts +68 -42
- package/dist/data-structures/queue/queue.js +95 -51
- package/dist/data-structures/stack/stack.d.ts +30 -36
- package/dist/data-structures/stack/stack.js +31 -37
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
- package/dist/data-structures/trie/trie.d.ts +39 -6
- package/dist/data-structures/trie/trie.js +81 -12
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
- package/dist/interfaces/abstract-binary-tree.js +2 -0
- package/dist/interfaces/abstract-graph.d.ts +17 -0
- package/dist/interfaces/abstract-graph.js +2 -0
- package/dist/interfaces/avl-tree.d.ts +9 -0
- package/dist/interfaces/avl-tree.js +2 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/binary-tree.js +2 -0
- package/dist/interfaces/bst.d.ts +17 -0
- package/dist/interfaces/bst.js +2 -0
- package/dist/interfaces/directed-graph.d.ts +12 -0
- package/dist/interfaces/directed-graph.js +2 -0
- package/dist/interfaces/doubly-linked-list.js +2 -0
- package/dist/interfaces/heap.js +2 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/index.js +31 -0
- package/dist/interfaces/navigator.js +2 -0
- package/dist/interfaces/priority-queue.js +2 -0
- package/dist/interfaces/rb-tree.d.ts +8 -0
- package/dist/interfaces/rb-tree.js +2 -0
- package/dist/interfaces/segment-tree.js +2 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/interfaces/tree-multiset.d.ts +7 -0
- package/dist/interfaces/tree-multiset.js +2 -0
- package/dist/interfaces/undirected-graph.d.ts +5 -0
- package/dist/interfaces/undirected-graph.js +2 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +25 -0
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/abstract-graph.js +2 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.js +2 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/bst.js +9 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/directed-graph.js +9 -0
- package/dist/types/data-structures/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/heap.d.ts +3 -0
- package/dist/types/data-structures/heap.js +2 -0
- package/dist/types/data-structures/index.d.ts +13 -7
- package/dist/types/data-structures/index.js +31 -0
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/map-graph.js +2 -0
- package/dist/types/data-structures/navigator.d.ts +14 -0
- package/dist/types/data-structures/navigator.js +2 -0
- package/dist/types/data-structures/priority-queue.d.ts +7 -0
- package/dist/types/data-structures/priority-queue.js +2 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/rb-tree.js +8 -0
- package/dist/types/data-structures/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/segment-tree.js +2 -0
- package/dist/types/data-structures/singly-linked-list.js +2 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/data-structures/tree-multiset.js +2 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/helpers.js +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.js +18 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/utils.js +2 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/validate-type.js +2 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +19 -0
- package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
- package/package.json +106 -55
- package/.idea/data-structure-typed.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/types/utils.d.ts +0 -46
- package/dist/utils.d.ts +0 -122
- package/dist/utils.js +0 -569
- package/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/src/data-structures/binary-tree/avl-tree.ts +0 -232
- package/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
- package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
- package/src/data-structures/binary-tree/bst.ts +0 -404
- package/src/data-structures/binary-tree/index.ts +0 -11
- package/src/data-structures/binary-tree/rb-tree.ts +0 -3
- package/src/data-structures/binary-tree/segment-tree.ts +0 -164
- package/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
- package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/src/data-structures/graph/abstract-graph.ts +0 -789
- package/src/data-structures/graph/directed-graph.ts +0 -322
- package/src/data-structures/graph/index.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +0 -154
- package/src/data-structures/hash/coordinate-map.ts +0 -24
- package/src/data-structures/hash/coordinate-set.ts +0 -20
- package/src/data-structures/hash/hash-table.ts +0 -1
- package/src/data-structures/hash/index.ts +0 -1
- package/src/data-structures/heap/heap.ts +0 -136
- package/src/data-structures/heap/index.ts +0 -3
- package/src/data-structures/heap/max-heap.ts +0 -22
- package/src/data-structures/heap/min-heap.ts +0 -24
- package/src/data-structures/index.ts +0 -11
- package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
- package/src/data-structures/linked-list/index.ts +0 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
- package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
- package/src/data-structures/matrix/index.ts +0 -4
- package/src/data-structures/matrix/matrix.ts +0 -13
- package/src/data-structures/matrix/matrix2d.ts +0 -125
- package/src/data-structures/matrix/navigator.ts +0 -99
- package/src/data-structures/matrix/vector2d.ts +0 -189
- package/src/data-structures/priority-queue/index.ts +0 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
- package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
- package/src/data-structures/priority-queue/priority-queue.ts +0 -208
- package/src/data-structures/queue/deque.ts +0 -139
- package/src/data-structures/queue/index.ts +0 -2
- package/src/data-structures/queue/queue.ts +0 -123
- package/src/data-structures/stack/index.ts +0 -1
- package/src/data-structures/stack/stack.ts +0 -104
- package/src/data-structures/trampoline.ts +0 -91
- package/src/data-structures/trie/index.ts +0 -1
- package/src/data-structures/trie/trie.ts +0 -153
- package/src/index.ts +0 -1
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- package/src/types/utils.ts +0 -158
- package/src/utils.ts +0 -605
- package/tsconfig.json +0 -53
- /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
- /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
- /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
- /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
- /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
- /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
- /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
- /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
- /package/dist/{types/types → utils}/index.d.ts +0 -0
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Trie = exports.TrieNode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
4
11
|
class TrieNode {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.
|
|
12
|
+
constructor(v) {
|
|
13
|
+
this._val = v;
|
|
7
14
|
this._isEnd = false;
|
|
15
|
+
this._children = new Map();
|
|
16
|
+
}
|
|
17
|
+
get val() {
|
|
18
|
+
return this._val;
|
|
19
|
+
}
|
|
20
|
+
set val(v) {
|
|
21
|
+
this._val = v;
|
|
8
22
|
}
|
|
9
23
|
get children() {
|
|
10
24
|
return this._children;
|
|
@@ -21,21 +35,26 @@ class TrieNode {
|
|
|
21
35
|
}
|
|
22
36
|
exports.TrieNode = TrieNode;
|
|
23
37
|
class Trie {
|
|
38
|
+
constructor(words) {
|
|
39
|
+
this._root = new TrieNode('');
|
|
40
|
+
if (words) {
|
|
41
|
+
for (const i of words) {
|
|
42
|
+
this.add(i);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
24
46
|
get root() {
|
|
25
47
|
return this._root;
|
|
26
48
|
}
|
|
27
49
|
set root(v) {
|
|
28
50
|
this._root = v;
|
|
29
51
|
}
|
|
30
|
-
|
|
31
|
-
this._root = new TrieNode();
|
|
32
|
-
}
|
|
33
|
-
put(input) {
|
|
52
|
+
add(word) {
|
|
34
53
|
let cur = this._root;
|
|
35
|
-
for (const c of
|
|
54
|
+
for (const c of word) {
|
|
36
55
|
let nodeC = cur.children.get(c);
|
|
37
56
|
if (!nodeC) {
|
|
38
|
-
nodeC = new TrieNode();
|
|
57
|
+
nodeC = new TrieNode(c);
|
|
39
58
|
cur.children.set(c, nodeC);
|
|
40
59
|
}
|
|
41
60
|
cur = nodeC;
|
|
@@ -86,8 +105,9 @@ class Trie {
|
|
|
86
105
|
}
|
|
87
106
|
// --- start additional methods ---
|
|
88
107
|
/**
|
|
89
|
-
* Only can present as a prefix, not a word
|
|
90
|
-
* @param input
|
|
108
|
+
* The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
|
|
109
|
+
* @param {string} input - The input parameter is a string that represents the input value for the function.
|
|
110
|
+
* @returns a boolean value.
|
|
91
111
|
*/
|
|
92
112
|
isAbsPrefix(input) {
|
|
93
113
|
let cur = this._root;
|
|
@@ -100,8 +120,9 @@ class Trie {
|
|
|
100
120
|
return !cur.isEnd;
|
|
101
121
|
}
|
|
102
122
|
/**
|
|
103
|
-
* Can present as a prefix or word
|
|
104
|
-
* @param input
|
|
123
|
+
* The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
|
|
124
|
+
* @param {string} input - The input parameter is a string that represents the prefix we want to check.
|
|
125
|
+
* @returns a boolean value.
|
|
105
126
|
*/
|
|
106
127
|
isPrefix(input) {
|
|
107
128
|
let cur = this._root;
|
|
@@ -113,6 +134,54 @@ class Trie {
|
|
|
113
134
|
}
|
|
114
135
|
return true;
|
|
115
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
|
|
139
|
+
* @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
|
|
140
|
+
* in the Trie data structure.
|
|
141
|
+
* @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
|
|
142
|
+
*/
|
|
143
|
+
isCommonPrefix(input) {
|
|
144
|
+
let commonPre = '';
|
|
145
|
+
const dfs = (cur) => {
|
|
146
|
+
commonPre += cur.val;
|
|
147
|
+
if (commonPre === input)
|
|
148
|
+
return;
|
|
149
|
+
if (cur.isEnd)
|
|
150
|
+
return;
|
|
151
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
152
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
153
|
+
else
|
|
154
|
+
return;
|
|
155
|
+
};
|
|
156
|
+
dfs(this._root);
|
|
157
|
+
return commonPre === input;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
|
|
161
|
+
* structure.
|
|
162
|
+
* @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
|
|
163
|
+
* Trie.
|
|
164
|
+
*/
|
|
165
|
+
getLongestCommonPrefix() {
|
|
166
|
+
let commonPre = '';
|
|
167
|
+
const dfs = (cur) => {
|
|
168
|
+
commonPre += cur.val;
|
|
169
|
+
if (cur.isEnd)
|
|
170
|
+
return;
|
|
171
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
172
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
173
|
+
else
|
|
174
|
+
return;
|
|
175
|
+
};
|
|
176
|
+
dfs(this._root);
|
|
177
|
+
return commonPre;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
181
|
+
* @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
182
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
183
|
+
* @returns an array of strings.
|
|
184
|
+
*/
|
|
116
185
|
getAll(prefix = '') {
|
|
117
186
|
const words = [];
|
|
118
187
|
function dfs(node, word) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,3 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./data-structures"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
19
|
+
__exportStar(require("./interfaces"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
|
|
2
|
+
import { AbstractBinaryTreeNode } from '../data-structures';
|
|
3
|
+
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
|
4
|
+
get id(): BinaryTreeNodeId;
|
|
5
|
+
set id(v: BinaryTreeNodeId);
|
|
6
|
+
get val(): T | undefined;
|
|
7
|
+
set val(v: T | undefined);
|
|
8
|
+
get left(): NEIGHBOR | null | undefined;
|
|
9
|
+
set left(v: NEIGHBOR | null | undefined);
|
|
10
|
+
get right(): NEIGHBOR | null | undefined;
|
|
11
|
+
set right(v: NEIGHBOR | null | undefined);
|
|
12
|
+
get parent(): NEIGHBOR | null | undefined;
|
|
13
|
+
set parent(v: NEIGHBOR | null | undefined);
|
|
14
|
+
get familyPosition(): FamilyPosition;
|
|
15
|
+
get height(): number;
|
|
16
|
+
set height(v: number);
|
|
17
|
+
}
|
|
18
|
+
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
19
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
|
|
20
|
+
get loopType(): LoopType;
|
|
21
|
+
get visitedId(): BinaryTreeNodeId[];
|
|
22
|
+
get visitedVal(): Array<N['val']>;
|
|
23
|
+
get visitedNode(): N[];
|
|
24
|
+
get visitedLeftSum(): number[];
|
|
25
|
+
get root(): N | null;
|
|
26
|
+
get size(): number;
|
|
27
|
+
swapLocation(srcNode: N, destNode: N): N;
|
|
28
|
+
clear(): void;
|
|
29
|
+
isEmpty(): boolean;
|
|
30
|
+
add(id: BinaryTreeNodeId | N, val?: N['val']): N | null | undefined;
|
|
31
|
+
addMany(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N['val'][]): (N | null | undefined)[];
|
|
32
|
+
fill(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N[] | Array<N['val']>): boolean;
|
|
33
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
34
|
+
getDepth(node: N): number;
|
|
35
|
+
getHeight(beginRoot?: N | null): number;
|
|
36
|
+
getMinHeight(beginRoot?: N | null): number;
|
|
37
|
+
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
38
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
39
|
+
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
40
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
41
|
+
getPathToRoot(node: N): N[];
|
|
42
|
+
getLeftMost(): N | null;
|
|
43
|
+
getLeftMost(node: N): N;
|
|
44
|
+
getLeftMost(node?: N | null): N | null;
|
|
45
|
+
getRightMost(): N | null;
|
|
46
|
+
getRightMost(node: N): N;
|
|
47
|
+
getRightMost(node?: N | null): N | null;
|
|
48
|
+
isSubtreeBST(node: N | null): boolean;
|
|
49
|
+
isBST(): boolean;
|
|
50
|
+
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
|
51
|
+
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
52
|
+
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
53
|
+
BFS(): BinaryTreeNodeId[];
|
|
54
|
+
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
55
|
+
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
56
|
+
BFS(nodeOrPropertyName: 'node'): N[];
|
|
57
|
+
BFS(nodeOrPropertyName: 'count'): number[];
|
|
58
|
+
BFS(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
59
|
+
DFS(): BinaryTreeNodeId[];
|
|
60
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
61
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
62
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
63
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
64
|
+
DFS(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
65
|
+
DFSIterative(): BinaryTreeNodeId[];
|
|
66
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
67
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
68
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
69
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
70
|
+
DFSIterative(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
71
|
+
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
72
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
73
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
74
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
75
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
76
|
+
levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
77
|
+
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
78
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
79
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
80
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
81
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
82
|
+
listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty<N>[][];
|
|
83
|
+
getPredecessor(node: N): N;
|
|
84
|
+
morris(): BinaryTreeNodeId[];
|
|
85
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
86
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
87
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
88
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
89
|
+
morris(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
90
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VertexId } from '../types';
|
|
2
|
+
export interface IAbstractGraph<V, E> {
|
|
3
|
+
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
4
|
+
addVertex(id: VertexId, val?: V): boolean;
|
|
5
|
+
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
6
|
+
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
7
|
+
degreeOf(vertexOrId: V | VertexId): number;
|
|
8
|
+
edgesOf(vertexOrId: V | VertexId): E[];
|
|
9
|
+
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
10
|
+
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
11
|
+
edgeSet(): E[];
|
|
12
|
+
addEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
|
|
13
|
+
removeEdge(edge: E): E | null;
|
|
14
|
+
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
15
|
+
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
16
|
+
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AVLTreeNode } from '../data-structures';
|
|
2
|
+
import { IBST, IBSTNode } from './bst';
|
|
3
|
+
import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
4
|
+
export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
5
|
+
}
|
|
6
|
+
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null): N | null | undefined;
|
|
8
|
+
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
3
|
+
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> extends IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
|
+
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
|
|
6
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BSTNode } from '../data-structures';
|
|
2
|
+
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
|
|
3
|
+
import { BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName } from '../types';
|
|
4
|
+
export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {
|
|
5
|
+
}
|
|
6
|
+
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
7
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
8
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null | undefined;
|
|
9
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
10
|
+
lastKey(): BinaryTreeNodeId;
|
|
11
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
12
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
13
|
+
lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
|
|
14
|
+
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
15
|
+
perfectlyBalance(): boolean;
|
|
16
|
+
isAVLBalanced(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VertexId } from '../types';
|
|
2
|
+
import { IAbstractGraph } from './abstract-graph';
|
|
3
|
+
export interface IDirectedGraph<V, E> extends IAbstractGraph<V, E> {
|
|
4
|
+
incomingEdgesOf(vertex: V): E[];
|
|
5
|
+
outgoingEdgesOf(vertex: V): E[];
|
|
6
|
+
inDegreeOf(vertexOrId: V | VertexId): number;
|
|
7
|
+
outDegreeOf(vertexOrId: V | VertexId): number;
|
|
8
|
+
getEdgeSrc(e: E): V | null;
|
|
9
|
+
getEdgeDest(e: E): V | null;
|
|
10
|
+
removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
11
|
+
removeEdgesBetween(v1: V | VertexId, v2: V | VertexId): E[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './abstract-binary-tree';
|
|
2
|
+
export * from './abstract-graph';
|
|
3
|
+
export * from './avl-tree';
|
|
4
|
+
export * from './binary-tree';
|
|
5
|
+
export * from './bst';
|
|
6
|
+
export * from './directed-graph';
|
|
7
|
+
export * from './doubly-linked-list';
|
|
8
|
+
export * from './heap';
|
|
9
|
+
export * from './navigator';
|
|
10
|
+
export * from './priority-queue';
|
|
11
|
+
export * from './rb-tree';
|
|
12
|
+
export * from './segment-tree';
|
|
13
|
+
export * from './singly-linked-list';
|
|
14
|
+
export * from './tree-multiset';
|
|
15
|
+
export * from './undirected-graph';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./abstract-binary-tree"), exports);
|
|
18
|
+
__exportStar(require("./abstract-graph"), exports);
|
|
19
|
+
__exportStar(require("./avl-tree"), exports);
|
|
20
|
+
__exportStar(require("./binary-tree"), exports);
|
|
21
|
+
__exportStar(require("./bst"), exports);
|
|
22
|
+
__exportStar(require("./directed-graph"), exports);
|
|
23
|
+
__exportStar(require("./doubly-linked-list"), exports);
|
|
24
|
+
__exportStar(require("./heap"), exports);
|
|
25
|
+
__exportStar(require("./navigator"), exports);
|
|
26
|
+
__exportStar(require("./priority-queue"), exports);
|
|
27
|
+
__exportStar(require("./rb-tree"), exports);
|
|
28
|
+
__exportStar(require("./segment-tree"), exports);
|
|
29
|
+
__exportStar(require("./singly-linked-list"), exports);
|
|
30
|
+
__exportStar(require("./tree-multiset"), exports);
|
|
31
|
+
__exportStar(require("./undirected-graph"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RBTreeNode } from '../data-structures';
|
|
2
|
+
import { IBST, IBSTNode } from './bst';
|
|
3
|
+
import { BinaryTreeNodeId } from '../types';
|
|
4
|
+
export interface IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
5
|
+
}
|
|
6
|
+
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TreeMultisetNode } from '../data-structures';
|
|
2
|
+
import { IBSTNode } from './bst';
|
|
3
|
+
import { IAVLTree } from './avl-tree';
|
|
4
|
+
export interface ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
5
|
+
}
|
|
6
|
+
export interface ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> extends IAVLTree<N> {
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AbstractBinaryTreeNode } from '../../data-structures/binary-tree';
|
|
2
|
+
/**
|
|
3
|
+
* Enum representing different loop types.
|
|
4
|
+
*
|
|
5
|
+
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
6
|
+
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
7
|
+
*/
|
|
8
|
+
export declare enum LoopType {
|
|
9
|
+
ITERATIVE = "ITERATIVE",
|
|
10
|
+
RECURSIVE = "RECURSIVE"
|
|
11
|
+
}
|
|
12
|
+
export declare enum FamilyPosition {
|
|
13
|
+
ROOT = "ROOT",
|
|
14
|
+
LEFT = "LEFT",
|
|
15
|
+
RIGHT = "RIGHT",
|
|
16
|
+
ROOT_LEFT = "ROOT_LEFT",
|
|
17
|
+
ROOT_RIGHT = "ROOT_RIGHT",
|
|
18
|
+
ISOLATED = "ISOLATED",
|
|
19
|
+
MAL_NODE = "MAL_NODE"
|
|
20
|
+
}
|
|
21
|
+
export type BinaryTreeNodePropertyName = 'id' | 'val';
|
|
22
|
+
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
23
|
+
export type DFSOrderPattern = 'in' | 'pre' | 'post';
|
|
24
|
+
export type BinaryTreeNodeId = number;
|
|
25
|
+
export type BinaryTreeDeletedResult<N> = {
|
|
26
|
+
deleted: N | null | undefined;
|
|
27
|
+
needBalanced: N | null;
|
|
28
|
+
};
|
|
29
|
+
export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
|
|
30
|
+
export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];
|
|
31
|
+
export type AbstractBinaryTreeNodeNested<T> = AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
32
|
+
export type AbstractBinaryTreeOptions = {
|
|
33
|
+
loopType?: LoopType;
|
|
34
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FamilyPosition = exports.LoopType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing different loop types.
|
|
6
|
+
*
|
|
7
|
+
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
8
|
+
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
9
|
+
*/
|
|
10
|
+
var LoopType;
|
|
11
|
+
(function (LoopType) {
|
|
12
|
+
LoopType["ITERATIVE"] = "ITERATIVE";
|
|
13
|
+
LoopType["RECURSIVE"] = "RECURSIVE";
|
|
14
|
+
})(LoopType = exports.LoopType || (exports.LoopType = {}));
|
|
15
|
+
/* This enumeration defines the position of a node within a family tree composed of three associated nodes, where 'root' represents the root node of the family tree, 'left' represents the left child node, and 'right' represents the right child node. */
|
|
16
|
+
var FamilyPosition;
|
|
17
|
+
(function (FamilyPosition) {
|
|
18
|
+
FamilyPosition["ROOT"] = "ROOT";
|
|
19
|
+
FamilyPosition["LEFT"] = "LEFT";
|
|
20
|
+
FamilyPosition["RIGHT"] = "RIGHT";
|
|
21
|
+
FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
|
|
22
|
+
FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
23
|
+
FamilyPosition["ISOLATED"] = "ISOLATED";
|
|
24
|
+
FamilyPosition["MAL_NODE"] = "MAL_NODE";
|
|
25
|
+
})(FamilyPosition = exports.FamilyPosition || (exports.FamilyPosition = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type VertexId = string | number;
|
|
2
|
+
export type EdgeId = string;
|
|
3
|
+
export type DijkstraResult<V> = {
|
|
4
|
+
distMap: Map<V, number>;
|
|
5
|
+
distPaths?: Map<V, V[]>;
|
|
6
|
+
preMap: Map<V, V | null>;
|
|
7
|
+
seen: Set<V>;
|
|
8
|
+
paths: V[][];
|
|
9
|
+
minDist: number;
|
|
10
|
+
minPath: V[];
|
|
11
|
+
} | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AVLTreeNode } from '../../data-structures/binary-tree';
|
|
2
|
+
import { BSTOptions } from './bst';
|
|
3
|
+
export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type AVLTreeOptions = BSTOptions & {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BinaryTreeNode } from '../../data-structures/binary-tree';
|
|
2
|
+
import { AbstractBinaryTreeOptions } from './abstract-binary-tree';
|
|
3
|
+
export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type BinaryTreeOptions = AbstractBinaryTreeOptions & {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BSTNode } from '../../data-structures/binary-tree';
|
|
2
|
+
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
+
import { BinaryTreeNodeId } from './abstract-binary-tree';
|
|
4
|
+
export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
|
|
5
|
+
export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BSTOptions = BinaryTreeOptions & {
|
|
7
|
+
comparator?: BSTComparator;
|
|
8
|
+
};
|
|
9
|
+
export declare enum CP {
|
|
10
|
+
lt = "lt",
|
|
11
|
+
eq = "eq",
|
|
12
|
+
gt = "gt"
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TopologicalProperty = void 0;
|
|
4
|
+
var TopologicalProperty;
|
|
5
|
+
(function (TopologicalProperty) {
|
|
6
|
+
TopologicalProperty["VAL"] = "VAL";
|
|
7
|
+
TopologicalProperty["NODE"] = "NODE";
|
|
8
|
+
TopologicalProperty["ID"] = "ID";
|
|
9
|
+
})(TopologicalProperty = exports.TopologicalProperty || (exports.TopologicalProperty = {}));
|