red-black-tree-typed 1.47.3
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/.eslintrc.js +61 -0
- package/.prettierignore +6 -0
- package/.prettierrc.js +16 -0
- package/LICENSE +21 -0
- package/README.md +713 -0
- package/coverage/clover.xml +13 -0
- package/coverage/coverage-final.json +96 -0
- package/coverage/coverage-summary.json +60 -0
- package/coverage/lcov-report/base.css +403 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +119 -0
- package/coverage/lcov-report/index.ts.html +109 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +206 -0
- package/coverage/lcov.info +14 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +173 -0
- package/dist/data-structures/binary-tree/avl-tree.js +429 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +515 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1665 -0
- package/dist/data-structures/binary-tree/bst.d.ts +253 -0
- package/dist/data-structures/binary-tree/bst.js +651 -0
- package/dist/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/data-structures/binary-tree/index.js +23 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +169 -0
- package/dist/data-structures/binary-tree/rb-tree.js +524 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
- package/dist/data-structures/binary-tree/segment-tree.js +180 -0
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +162 -0
- package/dist/data-structures/binary-tree/tree-multimap.js +407 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +450 -0
- package/dist/data-structures/graph/abstract-graph.js +1047 -0
- package/dist/data-structures/graph/directed-graph.d.ts +320 -0
- package/dist/data-structures/graph/directed-graph.js +530 -0
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/index.js +20 -0
- package/dist/data-structures/graph/map-graph.d.ts +73 -0
- package/dist/data-structures/graph/map-graph.js +93 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +183 -0
- package/dist/data-structures/graph/undirected-graph.js +302 -0
- package/dist/data-structures/hash/hash-map.d.ts +186 -0
- package/dist/data-structures/hash/hash-map.js +367 -0
- package/dist/data-structures/hash/hash-table.d.ts +103 -0
- package/dist/data-structures/hash/hash-table.js +236 -0
- package/dist/data-structures/hash/index.d.ts +2 -0
- package/dist/data-structures/hash/index.js +18 -0
- package/dist/data-structures/heap/heap.d.ts +410 -0
- package/dist/data-structures/heap/heap.js +697 -0
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/index.js +19 -0
- package/dist/data-structures/heap/max-heap.d.ts +15 -0
- package/dist/data-structures/heap/max-heap.js +26 -0
- package/dist/data-structures/heap/min-heap.d.ts +15 -0
- package/dist/data-structures/heap/min-heap.js +26 -0
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/index.js +27 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +456 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +772 -0
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/index.js +19 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +414 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +715 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +144 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +251 -0
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/index.js +20 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +28 -0
- package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
- package/dist/data-structures/matrix/matrix2d.js +199 -0
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +106 -0
- package/dist/data-structures/matrix/vector2d.d.ts +200 -0
- package/dist/data-structures/matrix/vector2d.js +290 -0
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/index.js +19 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/priority-queue.js +17 -0
- package/dist/data-structures/queue/deque.d.ts +572 -0
- package/dist/data-structures/queue/deque.js +990 -0
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/index.js +18 -0
- package/dist/data-structures/queue/queue.d.ts +209 -0
- package/dist/data-structures/queue/queue.js +274 -0
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/index.js +17 -0
- package/dist/data-structures/stack/stack.d.ts +106 -0
- package/dist/data-structures/stack/stack.js +136 -0
- 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 +8 -0
- package/dist/data-structures/tree/tree.js +40 -0
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/index.js +17 -0
- package/dist/data-structures/trie/trie.d.ts +155 -0
- package/dist/data-structures/trie/trie.js +326 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/interfaces/binary-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.js +2 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/doubly-linked-list.js +2 -0
- package/dist/interfaces/graph.d.ts +5 -0
- package/dist/interfaces/graph.js +2 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/heap.js +2 -0
- package/dist/interfaces/index.d.ts +8 -0
- package/dist/interfaces/index.js +24 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/navigator.js +2 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/priority-queue.js +2 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/segment-tree.js +2 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/types/common.d.ts +20 -0
- package/dist/types/common.js +9 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +31 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/bst.js +2 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/index.js +22 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +9 -0
- package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/tree-multimap.js +2 -0
- package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
- package/dist/types/data-structures/graph/abstract-graph.js +2 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/directed-graph.js +2 -0
- package/dist/types/data-structures/graph/index.d.ts +3 -0
- package/dist/types/data-structures/graph/index.js +19 -0
- package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/map-graph.js +2 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/data-structures/graph/undirected-graph.js +2 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +11 -0
- package/dist/types/data-structures/hash/hash-map.js +2 -0
- package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
- package/dist/types/data-structures/hash/hash-table.js +2 -0
- package/dist/types/data-structures/hash/index.d.ts +3 -0
- package/dist/types/data-structures/hash/index.js +18 -0
- package/dist/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/data-structures/heap/heap.js +2 -0
- package/dist/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/data-structures/heap/index.js +17 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/max-heap.js +2 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/data-structures/heap/min-heap.js +2 -0
- package/dist/types/data-structures/index.d.ts +11 -0
- package/dist/types/data-structures/index.js +27 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/types/data-structures/linked-list/index.js +18 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +17 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix.js +2 -0
- package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/matrix2d.js +2 -0
- package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/data-structures/matrix/navigator.js +2 -0
- package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
- package/dist/types/data-structures/matrix/vector2d.js +2 -0
- package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/types/data-structures/priority-queue/index.js +19 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
- package/dist/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/types/data-structures/queue/deque.js +2 -0
- package/dist/types/data-structures/queue/index.d.ts +2 -0
- package/dist/types/data-structures/queue/index.js +18 -0
- package/dist/types/data-structures/queue/queue.d.ts +1 -0
- package/dist/types/data-structures/queue/queue.js +2 -0
- package/dist/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/data-structures/stack/index.js +17 -0
- package/dist/types/data-structures/stack/stack.d.ts +1 -0
- package/dist/types/data-structures/stack/stack.js +2 -0
- package/dist/types/data-structures/tree/index.d.ts +1 -0
- package/dist/types/data-structures/tree/index.js +17 -0
- package/dist/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/data-structures/tree/tree.js +2 -0
- package/dist/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/data-structures/trie/index.js +17 -0
- package/dist/types/data-structures/trie/trie.d.ts +1 -0
- package/dist/types/data-structures/trie/trie.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -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.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +24 -0
- package/dist/utils/utils.js +89 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1383 -0
- package/docs/classes/AVLTree.html +2046 -0
- package/docs/classes/AVLTreeNode.html +263 -0
- package/docs/index.html +523 -0
- package/docs/modules.html +45 -0
- package/jest.config.js +8 -0
- package/package.json +147 -0
- package/src/data-structures/binary-tree/avl-tree.ts +443 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1974 -0
- package/src/data-structures/binary-tree/bst.ts +676 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/rb-tree.ts +585 -0
- package/src/data-structures/binary-tree/segment-tree.ts +190 -0
- package/src/data-structures/binary-tree/tree-multimap.ts +435 -0
- package/src/data-structures/graph/abstract-graph.ts +1181 -0
- package/src/data-structures/graph/directed-graph.ts +593 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +106 -0
- package/src/data-structures/graph/undirected-graph.ts +331 -0
- package/src/data-structures/hash/hash-map.ts +401 -0
- package/src/data-structures/hash/hash-table.ts +268 -0
- package/src/data-structures/hash/index.ts +2 -0
- package/src/data-structures/heap/heap.ts +790 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +26 -0
- package/src/data-structures/heap/min-heap.ts +26 -0
- package/src/data-structures/index.ts +11 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +837 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +784 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +295 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +211 -0
- package/src/data-structures/matrix/navigator.ts +121 -0
- package/src/data-structures/matrix/vector2d.ts +315 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
- package/src/data-structures/priority-queue/priority-queue.ts +16 -0
- package/src/data-structures/queue/deque.ts +1073 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +308 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +150 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +41 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +345 -0
- package/src/index.ts +11 -0
- package/src/interfaces/binary-tree.ts +10 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/graph.ts +7 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/types/common.ts +23 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +9 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +35 -0
- package/src/types/data-structures/binary-tree/bst.ts +13 -0
- package/src/types/data-structures/binary-tree/index.ts +6 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +10 -0
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-multimap.ts +8 -0
- package/src/types/data-structures/graph/abstract-graph.ts +11 -0
- package/src/types/data-structures/graph/directed-graph.ts +2 -0
- package/src/types/data-structures/graph/index.ts +3 -0
- package/src/types/data-structures/graph/map-graph.ts +1 -0
- package/src/types/data-structures/graph/undirected-graph.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +12 -0
- package/src/types/data-structures/hash/hash-table.ts +1 -0
- package/src/types/data-structures/hash/index.ts +4 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/heap/index.ts +1 -0
- package/src/types/data-structures/heap/max-heap.ts +1 -0
- package/src/types/data-structures/heap/min-heap.ts +1 -0
- package/src/types/data-structures/index.ts +11 -0
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/index.ts +2 -0
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +1 -0
- package/src/types/data-structures/matrix/matrix2d.ts +1 -0
- package/src/types/data-structures/matrix/navigator.ts +14 -0
- package/src/types/data-structures/matrix/vector2d.ts +1 -0
- package/src/types/data-structures/priority-queue/index.ts +3 -0
- package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/data-structures/queue/deque.ts +1 -0
- package/src/types/data-structures/queue/index.ts +2 -0
- package/src/types/data-structures/queue/queue.ts +1 -0
- package/src/types/data-structures/stack/index.ts +1 -0
- package/src/types/data-structures/stack/stack.ts +1 -0
- package/src/types/data-structures/tree/index.ts +1 -0
- package/src/types/data-structures/tree/tree.ts +1 -0
- package/src/types/data-structures/trie/index.ts +1 -0
- package/src/types/data-structures/trie/trie.ts +1 -0
- package/src/types/index.ts +3 -0
- package/src/types/utils/index.ts +2 -0
- package/src/types/utils/utils.ts +6 -0
- package/src/types/utils/validate-type.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +101 -0
- package/test/index.test.ts +111 -0
- package/tsconfig.json +38 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Trie = exports.TrieNode = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
|
|
13
|
+
* and a flag indicating whether it's the end of a word.
|
|
14
|
+
*/
|
|
15
|
+
class TrieNode {
|
|
16
|
+
constructor(key) {
|
|
17
|
+
this.key = key;
|
|
18
|
+
this.isEnd = false;
|
|
19
|
+
this.children = new Map();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.TrieNode = TrieNode;
|
|
23
|
+
/**
|
|
24
|
+
* Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
|
|
25
|
+
*/
|
|
26
|
+
class Trie {
|
|
27
|
+
constructor(words, caseSensitive = true) {
|
|
28
|
+
this._root = new TrieNode('');
|
|
29
|
+
this._caseSensitive = caseSensitive;
|
|
30
|
+
if (words) {
|
|
31
|
+
for (const i of words) {
|
|
32
|
+
this.add(i);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get caseSensitive() {
|
|
37
|
+
return this._caseSensitive;
|
|
38
|
+
}
|
|
39
|
+
get root() {
|
|
40
|
+
return this._root;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Time Complexity: O(M), where M is the length of the word being added.
|
|
44
|
+
* Space Complexity: O(M) - Each character in the word adds a TrieNode.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Time Complexity: O(M), where M is the length of the word being added.
|
|
48
|
+
* Space Complexity: O(M) - Each character in the word adds a TrieNode.
|
|
49
|
+
*
|
|
50
|
+
* Add a word to the Trie structure.
|
|
51
|
+
* @param {string} word - The word to add.
|
|
52
|
+
* @returns {boolean} True if the word was successfully added.
|
|
53
|
+
*/
|
|
54
|
+
add(word) {
|
|
55
|
+
word = this._caseProcess(word);
|
|
56
|
+
let cur = this.root;
|
|
57
|
+
for (const c of word) {
|
|
58
|
+
let nodeC = cur.children.get(c);
|
|
59
|
+
if (!nodeC) {
|
|
60
|
+
nodeC = new TrieNode(c);
|
|
61
|
+
cur.children.set(c, nodeC);
|
|
62
|
+
}
|
|
63
|
+
cur = nodeC;
|
|
64
|
+
}
|
|
65
|
+
cur.isEnd = true;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Time Complexity: O(M), where M is the length of the input word.
|
|
70
|
+
* Space Complexity: O(1) - Constant space.
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Time Complexity: O(M), where M is the length of the input word.
|
|
74
|
+
* Space Complexity: O(1) - Constant space.
|
|
75
|
+
*
|
|
76
|
+
* Check if the Trie contains a given word.
|
|
77
|
+
* @param {string} word - The word to check for.
|
|
78
|
+
* @returns {boolean} True if the word is present in the Trie.
|
|
79
|
+
*/
|
|
80
|
+
has(word) {
|
|
81
|
+
word = this._caseProcess(word);
|
|
82
|
+
let cur = this.root;
|
|
83
|
+
for (const c of word) {
|
|
84
|
+
const nodeC = cur.children.get(c);
|
|
85
|
+
if (!nodeC)
|
|
86
|
+
return false;
|
|
87
|
+
cur = nodeC;
|
|
88
|
+
}
|
|
89
|
+
return cur.isEnd;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Time Complexity: O(M), where M is the length of the word being deleted.
|
|
93
|
+
* Space Complexity: O(M) - Due to the recursive DFS approach.
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* Time Complexity: O(M), where M is the length of the word being deleted.
|
|
97
|
+
* Space Complexity: O(M) - Due to the recursive DFS approach.
|
|
98
|
+
*
|
|
99
|
+
* Remove a word from the Trie structure.
|
|
100
|
+
* @param{string} word - The word to delete.
|
|
101
|
+
* @returns {boolean} True if the word was successfully removed.
|
|
102
|
+
*/
|
|
103
|
+
delete(word) {
|
|
104
|
+
word = this._caseProcess(word);
|
|
105
|
+
let isDeleted = false;
|
|
106
|
+
const dfs = (cur, i) => {
|
|
107
|
+
const char = word[i];
|
|
108
|
+
const child = cur.children.get(char);
|
|
109
|
+
if (child) {
|
|
110
|
+
if (i === word.length - 1) {
|
|
111
|
+
if (child.isEnd) {
|
|
112
|
+
if (child.children.size > 0) {
|
|
113
|
+
child.isEnd = false;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
cur.children.delete(char);
|
|
117
|
+
}
|
|
118
|
+
isDeleted = true;
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
const res = dfs(child, i + 1);
|
|
124
|
+
if (res && !cur.isEnd && child.children.size === 0) {
|
|
125
|
+
cur.children.delete(char);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
};
|
|
132
|
+
dfs(this.root, 0);
|
|
133
|
+
return isDeleted;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Time Complexity: O(N), where N is the total number of nodes in the trie.
|
|
137
|
+
* Space Complexity: O(1) - Constant space.
|
|
138
|
+
*/
|
|
139
|
+
/**
|
|
140
|
+
* Time Complexity: O(N), where N is the total number of nodes in the trie.
|
|
141
|
+
* Space Complexity: O(1) - Constant space.
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
getHeight() {
|
|
145
|
+
const beginRoot = this.root;
|
|
146
|
+
let maxDepth = 0;
|
|
147
|
+
if (beginRoot) {
|
|
148
|
+
const bfs = (node, level) => {
|
|
149
|
+
if (level > maxDepth) {
|
|
150
|
+
maxDepth = level;
|
|
151
|
+
}
|
|
152
|
+
const { children } = node;
|
|
153
|
+
if (children) {
|
|
154
|
+
for (const child of children.entries()) {
|
|
155
|
+
bfs(child[1], level + 1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
bfs(beginRoot, 0);
|
|
160
|
+
}
|
|
161
|
+
return maxDepth;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Time Complexity: O(M), where M is the length of the input prefix.
|
|
165
|
+
* Space Complexity: O(1) - Constant space.
|
|
166
|
+
*/
|
|
167
|
+
/**
|
|
168
|
+
* Time Complexity: O(M), where M is the length of the input prefix.
|
|
169
|
+
* Space Complexity: O(1) - Constant space.
|
|
170
|
+
*
|
|
171
|
+
* Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
|
|
172
|
+
* @param {string} input - The input string to check.
|
|
173
|
+
* @returns {boolean} True if it's an absolute prefix in the Trie.
|
|
174
|
+
*/
|
|
175
|
+
hasPurePrefix(input) {
|
|
176
|
+
input = this._caseProcess(input);
|
|
177
|
+
let cur = this.root;
|
|
178
|
+
for (const c of input) {
|
|
179
|
+
const nodeC = cur.children.get(c);
|
|
180
|
+
if (!nodeC)
|
|
181
|
+
return false;
|
|
182
|
+
cur = nodeC;
|
|
183
|
+
}
|
|
184
|
+
return !cur.isEnd;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Time Complexity: O(M), where M is the length of the input prefix.
|
|
188
|
+
* Space Complexity: O(1) - Constant space.
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
* Time Complexity: O(M), where M is the length of the input prefix.
|
|
192
|
+
* Space Complexity: O(1) - Constant space.
|
|
193
|
+
*
|
|
194
|
+
* Check if a given input string is a prefix of any existing word in the Trie, whether as an absolute prefix or a complete word.
|
|
195
|
+
* @param {string} input - The input string representing the prefix to check.
|
|
196
|
+
* @returns {boolean} True if it's a prefix in the Trie.
|
|
197
|
+
*/
|
|
198
|
+
hasPrefix(input) {
|
|
199
|
+
input = this._caseProcess(input);
|
|
200
|
+
let cur = this.root;
|
|
201
|
+
for (const c of input) {
|
|
202
|
+
const nodeC = cur.children.get(c);
|
|
203
|
+
if (!nodeC)
|
|
204
|
+
return false;
|
|
205
|
+
cur = nodeC;
|
|
206
|
+
}
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Time Complexity: O(N), where N is the total number of nodes in the trie.
|
|
211
|
+
* Space Complexity: O(M), where M is the length of the input prefix.
|
|
212
|
+
*/
|
|
213
|
+
/**
|
|
214
|
+
* Time Complexity: O(N), where N is the total number of nodes in the trie.
|
|
215
|
+
* Space Complexity: O(M), where M is the length of the input prefix.
|
|
216
|
+
*
|
|
217
|
+
* Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
|
|
218
|
+
* @param {string} input - The input string representing the common prefix to check for.
|
|
219
|
+
* @returns {boolean} True if it's a common prefix in the Trie.
|
|
220
|
+
*/
|
|
221
|
+
hasCommonPrefix(input) {
|
|
222
|
+
input = this._caseProcess(input);
|
|
223
|
+
let commonPre = '';
|
|
224
|
+
const dfs = (cur) => {
|
|
225
|
+
commonPre += cur.key;
|
|
226
|
+
if (commonPre === input)
|
|
227
|
+
return;
|
|
228
|
+
if (cur.isEnd)
|
|
229
|
+
return;
|
|
230
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
231
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
232
|
+
else
|
|
233
|
+
return;
|
|
234
|
+
};
|
|
235
|
+
dfs(this.root);
|
|
236
|
+
return commonPre === input;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Time Complexity: O(N), where N is the total number of nodes in the trie.
|
|
240
|
+
* Space Complexity: O(M), where M is the length of the longest common prefix.
|
|
241
|
+
*/
|
|
242
|
+
/**
|
|
243
|
+
* Time Complexity: O(N), where N is the total number of nodes in the trie.
|
|
244
|
+
* Space Complexity: O(M), where M is the length of the longest common prefix.
|
|
245
|
+
*
|
|
246
|
+
* Get the longest common prefix among all the words stored in the Trie.
|
|
247
|
+
* @returns {string} The longest common prefix found in the Trie.
|
|
248
|
+
*/
|
|
249
|
+
getLongestCommonPrefix() {
|
|
250
|
+
let commonPre = '';
|
|
251
|
+
const dfs = (cur) => {
|
|
252
|
+
commonPre += cur.key;
|
|
253
|
+
if (cur.isEnd)
|
|
254
|
+
return;
|
|
255
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
256
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
257
|
+
else
|
|
258
|
+
return;
|
|
259
|
+
};
|
|
260
|
+
dfs(this.root);
|
|
261
|
+
return commonPre;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
|
|
265
|
+
* Space Complexity: O(K * L) - The space required for the output array.
|
|
266
|
+
*/
|
|
267
|
+
/**
|
|
268
|
+
* Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
|
|
269
|
+
* Space Complexity: O(K * L) - The space required for the output array.
|
|
270
|
+
*
|
|
271
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
272
|
+
* @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
273
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
274
|
+
* @param {number} max - The max count of words will be found
|
|
275
|
+
* @param isAllWhenEmptyPrefix - If true, when the prefix provided as '', returns all the words in the trie.
|
|
276
|
+
* @returns {string[]} an array of strings.
|
|
277
|
+
*/
|
|
278
|
+
getWords(prefix = '', max = Number.MAX_SAFE_INTEGER, isAllWhenEmptyPrefix = false) {
|
|
279
|
+
prefix = this._caseProcess(prefix);
|
|
280
|
+
const words = [];
|
|
281
|
+
let found = 0;
|
|
282
|
+
function dfs(node, word) {
|
|
283
|
+
for (const char of node.children.keys()) {
|
|
284
|
+
const charNode = node.children.get(char);
|
|
285
|
+
if (charNode !== undefined) {
|
|
286
|
+
dfs(charNode, word.concat(char));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (node.isEnd) {
|
|
290
|
+
if (found > max - 1)
|
|
291
|
+
return;
|
|
292
|
+
words.push(word);
|
|
293
|
+
found++;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
let startNode = this.root;
|
|
297
|
+
if (prefix) {
|
|
298
|
+
for (const c of prefix) {
|
|
299
|
+
const nodeC = startNode.children.get(c);
|
|
300
|
+
if (nodeC)
|
|
301
|
+
startNode = nodeC;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (isAllWhenEmptyPrefix || startNode !== this.root)
|
|
305
|
+
dfs(startNode, prefix);
|
|
306
|
+
return words;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Time Complexity: O(M), where M is the length of the input string.
|
|
310
|
+
* Space Complexity: O(1) - Constant space.
|
|
311
|
+
*/
|
|
312
|
+
/**
|
|
313
|
+
* Time Complexity: O(M), where M is the length of the input string.
|
|
314
|
+
* Space Complexity: O(1) - Constant space.
|
|
315
|
+
*
|
|
316
|
+
* @param str
|
|
317
|
+
* @protected
|
|
318
|
+
*/
|
|
319
|
+
_caseProcess(str) {
|
|
320
|
+
if (!this._caseSensitive) {
|
|
321
|
+
str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
|
|
322
|
+
}
|
|
323
|
+
return str;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.Trie = Trie;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
export * from './data-structures/binary-tree/rb-tree';
|
|
9
|
+
export * from './types/data-structures/binary-tree/rb-tree';
|
|
10
|
+
export * from './types/common';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* data-structure-typed
|
|
19
|
+
*
|
|
20
|
+
* @author Tyler Zeng
|
|
21
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
22
|
+
* @license MIT License
|
|
23
|
+
*/
|
|
24
|
+
// export { RedBlackTreeNode, RedBlackTree, CP, FamilyPosition, TopologicalProperty, IterationType } from 'data-structure-typed';
|
|
25
|
+
__exportStar(require("./data-structures/binary-tree/rb-tree"), exports);
|
|
26
|
+
__exportStar(require("./types/data-structures/binary-tree/rb-tree"), exports);
|
|
27
|
+
__exportStar(require("./types/common"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import { BinaryTreeNested, BinaryTreeNodeNested, BiTreeDeleteResult, BTNCallback, BTNKey } from '../types';
|
|
3
|
+
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>, TREE extends BinaryTree<V, N, TREE> = BinaryTreeNested<V, N>> {
|
|
4
|
+
createNode(key: BTNKey, value?: N['value']): N;
|
|
5
|
+
add(keyOrNode: BTNKey | N | null, value?: N['value']): N | null | undefined;
|
|
6
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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("./graph"), exports);
|
|
18
|
+
__exportStar(require("./binary-tree"), exports);
|
|
19
|
+
__exportStar(require("./doubly-linked-list"), exports);
|
|
20
|
+
__exportStar(require("./heap"), exports);
|
|
21
|
+
__exportStar(require("./navigator"), exports);
|
|
22
|
+
__exportStar(require("./priority-queue"), exports);
|
|
23
|
+
__exportStar(require("./segment-tree"), exports);
|
|
24
|
+
__exportStar(require("./singly-linked-list"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Comparator<T> = (a: T, b: T) => number;
|
|
2
|
+
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
3
|
+
export type BTNCallback<N, D = any> = (node: N) => D;
|
|
4
|
+
export declare enum CP {
|
|
5
|
+
lt = "lt",
|
|
6
|
+
eq = "eq",
|
|
7
|
+
gt = "gt"
|
|
8
|
+
}
|
|
9
|
+
export interface IterableWithSize<T> extends Iterable<T> {
|
|
10
|
+
size: number | ((...args: any[]) => number);
|
|
11
|
+
}
|
|
12
|
+
export interface IterableWithLength<T> extends Iterable<T> {
|
|
13
|
+
length: number | ((...args: any[]) => number);
|
|
14
|
+
}
|
|
15
|
+
export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
|
|
16
|
+
export type BinaryTreePrintOptions = {
|
|
17
|
+
isShowUndefined?: boolean;
|
|
18
|
+
isShowNull?: boolean;
|
|
19
|
+
isShowRedBlackNIL?: boolean;
|
|
20
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
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 AVLTreeNested<T, N extends AVLTreeNode<T, N>> = AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type AVLTreeOptions = BSTOptions & {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
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 IterationType {
|
|
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 BTNKey = number;
|
|
22
|
+
export type BiTreeDeleteResult<N> = {
|
|
23
|
+
deleted: N | null | undefined;
|
|
24
|
+
needBalanced: N | null | undefined;
|
|
25
|
+
};
|
|
26
|
+
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
27
|
+
export type BinaryTreeNested<T, N extends BinaryTreeNode<T, N>> = BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
28
|
+
export type BinaryTreeOptions = {
|
|
29
|
+
iterationType?: IterationType;
|
|
30
|
+
};
|
|
31
|
+
export type NodeDisplayLayout = [string[], number, number, number];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FamilyPosition = exports.IterationType = 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 IterationType;
|
|
11
|
+
(function (IterationType) {
|
|
12
|
+
IterationType["ITERATIVE"] = "ITERATIVE";
|
|
13
|
+
IterationType["RECURSIVE"] = "RECURSIVE";
|
|
14
|
+
})(IterationType = exports.IterationType || (exports.IterationType = {}));
|
|
15
|
+
var FamilyPosition;
|
|
16
|
+
(function (FamilyPosition) {
|
|
17
|
+
FamilyPosition["ROOT"] = "ROOT";
|
|
18
|
+
FamilyPosition["LEFT"] = "LEFT";
|
|
19
|
+
FamilyPosition["RIGHT"] = "RIGHT";
|
|
20
|
+
FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
|
|
21
|
+
FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
22
|
+
FamilyPosition["ISOLATED"] = "ISOLATED";
|
|
23
|
+
FamilyPosition["MAL_NODE"] = "MAL_NODE";
|
|
24
|
+
})(FamilyPosition = exports.FamilyPosition || (exports.FamilyPosition = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BST, BSTNode } from '../../../data-structures';
|
|
2
|
+
import type { BinaryTreeOptions, BTNKey } from './binary-tree';
|
|
3
|
+
export type BSTComparator = (a: BTNKey, b: BTNKey) => number;
|
|
4
|
+
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type BSTNested<T, N extends BSTNode<T, N>> = BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BSTOptions = BinaryTreeOptions & {
|
|
7
|
+
comparator?: BSTComparator;
|
|
8
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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("./binary-tree"), exports);
|
|
18
|
+
__exportStar(require("./bst"), exports);
|
|
19
|
+
__exportStar(require("./avl-tree"), exports);
|
|
20
|
+
__exportStar(require("./segment-tree"), exports);
|
|
21
|
+
__exportStar(require("./tree-multimap"), exports);
|
|
22
|
+
__exportStar(require("./rb-tree"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RedBlackTree, RedBlackTreeNode } from '../../../data-structures';
|
|
2
|
+
import { BSTOptions } from "./bst";
|
|
3
|
+
export declare enum RBTNColor {
|
|
4
|
+
RED = 1,
|
|
5
|
+
BLACK = 0
|
|
6
|
+
}
|
|
7
|
+
export type RedBlackTreeNodeNested<T> = RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
8
|
+
export type RedBlackTreeNested<T, N extends RedBlackTreeNode<T, N>> = RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
9
|
+
export type RBTreeOptions = BSTOptions & {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RBTNColor = void 0;
|
|
4
|
+
var RBTNColor;
|
|
5
|
+
(function (RBTNColor) {
|
|
6
|
+
RBTNColor[RBTNColor["RED"] = 1] = "RED";
|
|
7
|
+
RBTNColor[RBTNColor["BLACK"] = 0] = "BLACK";
|
|
8
|
+
})(RBTNColor = exports.RBTNColor || (exports.RBTNColor = {}));
|