min-heap-typed 1.40.0-rc → 1.41.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/.dependency-cruiser.js +422 -422
- package/.eslintrc.js +59 -59
- package/.prettierrc.js +14 -14
- package/README.md +20 -3
- package/coverage/clover.xml +11 -7
- package/coverage/coverage-final.json +95 -1
- package/coverage/coverage-summary.json +59 -2
- package/coverage/lcov-report/base.css +278 -99
- package/coverage/lcov-report/index.html +69 -65
- package/coverage/lcov-report/index.ts.html +36 -35
- package/coverage/lcov-report/sorter.js +15 -5
- package/dist/data-structures/binary-tree/avl-tree.d.ts +106 -0
- package/dist/data-structures/binary-tree/avl-tree.js +347 -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 +363 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1135 -0
- package/dist/data-structures/binary-tree/bst.d.ts +167 -0
- package/dist/data-structures/binary-tree/bst.js +512 -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 +97 -0
- package/dist/data-structures/binary-tree/rb-tree.js +388 -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-multiset.d.ts +126 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +355 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +313 -0
- package/dist/data-structures/graph/abstract-graph.js +884 -0
- package/dist/data-structures/graph/directed-graph.d.ts +194 -0
- package/dist/data-structures/graph/directed-graph.js +404 -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 +120 -0
- package/dist/data-structures/graph/undirected-graph.js +239 -0
- package/dist/data-structures/hash/coordinate-map.d.ts +44 -0
- package/dist/data-structures/hash/coordinate-map.js +62 -0
- package/dist/data-structures/hash/coordinate-set.d.ts +36 -0
- package/dist/data-structures/hash/coordinate-set.js +52 -0
- package/dist/data-structures/hash/hash-map.d.ts +50 -0
- package/dist/data-structures/hash/hash-map.js +153 -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 +6 -0
- package/dist/data-structures/hash/index.js +22 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.js +6 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.js +6 -0
- package/dist/data-structures/heap/heap.d.ts +235 -0
- package/dist/data-structures/heap/heap.js +515 -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 +253 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +569 -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 +232 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +533 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +80 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +187 -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 +161 -0
- package/dist/data-structures/queue/deque.js +264 -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 +122 -0
- package/dist/data-structures/queue/queue.js +187 -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 +64 -0
- package/dist/data-structures/stack/stack.js +94 -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 +79 -0
- package/dist/data-structures/trie/trie.js +251 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +18 -4
- 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/data-structures/binary-tree/avl-tree.d.ts +4 -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 +29 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +7 -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 +4 -0
- package/dist/types/data-structures/binary-tree/rb-tree.js +13 -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-multiset.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.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 +6 -0
- package/dist/types/data-structures/graph/directed-graph.js +9 -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/coordinate-map.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-map.js +2 -0
- package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
- package/dist/types/data-structures/hash/coordinate-set.js +2 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -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 +1 -0
- package/dist/types/data-structures/hash/index.js +2 -0
- package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-map.js +2 -0
- package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-set.js +2 -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/helpers.d.ts +8 -0
- package/dist/types/helpers.js +9 -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 +20 -0
- package/dist/utils/utils.js +73 -0
- package/jest.config.js +6 -6
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +350 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1284 -0
- package/src/data-structures/binary-tree/bst.ts +522 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/rb-tree.ts +426 -0
- package/src/data-structures/binary-tree/segment-tree.ts +190 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +379 -0
- package/src/data-structures/graph/abstract-graph.ts +1000 -0
- package/src/data-structures/graph/directed-graph.ts +449 -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 +259 -0
- package/src/data-structures/hash/coordinate-map.ts +63 -0
- package/src/data-structures/hash/coordinate-set.ts +52 -0
- package/src/data-structures/hash/hash-map.ts +185 -0
- package/src/data-structures/hash/hash-table.ts +268 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/tree-map.ts +2 -0
- package/src/data-structures/hash/tree-set.ts +2 -0
- package/src/data-structures/heap/heap.ts +589 -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 +605 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +576 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +221 -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 +282 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +209 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +102 -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 +262 -0
- package/src/index.ts +4 -1
- 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/data-structures/binary-tree/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
- package/src/types/data-structures/binary-tree/bst.ts +11 -0
- package/src/types/data-structures/binary-tree/index.ts +6 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
- package/src/types/data-structures/graph/abstract-graph.ts +11 -0
- package/src/types/data-structures/graph/directed-graph.ts +8 -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/coordinate-map.ts +1 -0
- package/src/types/data-structures/hash/coordinate-set.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +1 -0
- package/src/types/data-structures/hash/hash-table.ts +1 -0
- package/src/types/data-structures/hash/index.ts +1 -0
- package/src/types/data-structures/hash/tree-map.ts +1 -0
- package/src/types/data-structures/hash/tree-set.ts +1 -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/helpers.ts +11 -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 +86 -0
- package/tsconfig.json +1 -2
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = exports.LinkedListQueue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
const linked_list_1 = require("../linked-list");
|
|
10
|
+
class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
11
|
+
/**
|
|
12
|
+
* The enqueue function adds a value to the end of an array.
|
|
13
|
+
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
14
|
+
*/
|
|
15
|
+
enqueue(value) {
|
|
16
|
+
this.push(value);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
20
|
+
* @returns The method is returning the element at the front of the queue, or null if the queue is empty.
|
|
21
|
+
*/
|
|
22
|
+
dequeue() {
|
|
23
|
+
return this.shift();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
27
|
+
* @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
28
|
+
*/
|
|
29
|
+
getFirst() {
|
|
30
|
+
var _a;
|
|
31
|
+
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
35
|
+
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
36
|
+
*/
|
|
37
|
+
peek() {
|
|
38
|
+
return this.getFirst();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.LinkedListQueue = LinkedListQueue;
|
|
42
|
+
class Queue {
|
|
43
|
+
/**
|
|
44
|
+
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
45
|
+
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
46
|
+
* will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
|
|
47
|
+
* initialized as an empty array.
|
|
48
|
+
*/
|
|
49
|
+
constructor(elements) {
|
|
50
|
+
this._nodes = elements || [];
|
|
51
|
+
this._offset = 0;
|
|
52
|
+
}
|
|
53
|
+
get nodes() {
|
|
54
|
+
return this._nodes;
|
|
55
|
+
}
|
|
56
|
+
get offset() {
|
|
57
|
+
return this._offset;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The size function returns the number of elements in an array.
|
|
61
|
+
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
62
|
+
*/
|
|
63
|
+
get size() {
|
|
64
|
+
return this.nodes.length - this.offset;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
68
|
+
* @public
|
|
69
|
+
* @static
|
|
70
|
+
* @param {E[]} elements - The "elements" parameter is an array of elements of type E.
|
|
71
|
+
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
72
|
+
* array.
|
|
73
|
+
*/
|
|
74
|
+
static fromArray(elements) {
|
|
75
|
+
return new Queue(elements);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
|
|
79
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
80
|
+
* @returns The `add` method is returning a `Queue<E>` object.
|
|
81
|
+
*/
|
|
82
|
+
push(element) {
|
|
83
|
+
this.nodes.push(element);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
88
|
+
* necessary to optimize performance.
|
|
89
|
+
* @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
|
|
90
|
+
*/
|
|
91
|
+
shift() {
|
|
92
|
+
if (this.size === 0)
|
|
93
|
+
return undefined;
|
|
94
|
+
const first = this.getFirst();
|
|
95
|
+
this._offset += 1;
|
|
96
|
+
if (this.offset * 2 < this.nodes.length)
|
|
97
|
+
return first;
|
|
98
|
+
// only delete dequeued elements when reaching half size
|
|
99
|
+
// to decrease latency of shifting elements.
|
|
100
|
+
this._nodes = this.nodes.slice(this.offset);
|
|
101
|
+
this._offset = 0;
|
|
102
|
+
return first;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
106
|
+
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
107
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
108
|
+
*/
|
|
109
|
+
getFirst() {
|
|
110
|
+
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
114
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
115
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
116
|
+
*/
|
|
117
|
+
peek() {
|
|
118
|
+
return this.getFirst();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
122
|
+
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
123
|
+
* array is empty, it returns `null`.
|
|
124
|
+
*/
|
|
125
|
+
getLast() {
|
|
126
|
+
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
130
|
+
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
131
|
+
* array is empty, it returns `null`.
|
|
132
|
+
*/
|
|
133
|
+
peekLast() {
|
|
134
|
+
return this.getLast();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The enqueue function adds a value to the end of a queue.
|
|
138
|
+
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
139
|
+
*/
|
|
140
|
+
enqueue(value) {
|
|
141
|
+
this.push(value);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
145
|
+
* @returns The method is returning a value of type E or null.
|
|
146
|
+
*/
|
|
147
|
+
dequeue() {
|
|
148
|
+
return this.shift();
|
|
149
|
+
}
|
|
150
|
+
getAt(index) {
|
|
151
|
+
return this.nodes[index];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The function checks if a data structure is empty by comparing its size to zero.
|
|
155
|
+
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
156
|
+
*/
|
|
157
|
+
isEmpty() {
|
|
158
|
+
return this.size === 0;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
|
|
162
|
+
* @returns An array of type E is being returned.
|
|
163
|
+
*/
|
|
164
|
+
toArray() {
|
|
165
|
+
return this.nodes.slice(this.offset);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The clear function resets the nodes array and offset to their initial values.
|
|
169
|
+
*/
|
|
170
|
+
clear() {
|
|
171
|
+
this._nodes = [];
|
|
172
|
+
this._offset = 0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
176
|
+
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
177
|
+
*/
|
|
178
|
+
clone() {
|
|
179
|
+
return new Queue(this.nodes.slice(this.offset));
|
|
180
|
+
}
|
|
181
|
+
*[Symbol.iterator]() {
|
|
182
|
+
for (const item of this.nodes) {
|
|
183
|
+
yield item;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.Queue = Queue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stack';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./stack"), exports);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export declare class Stack<E = any> {
|
|
7
|
+
/**
|
|
8
|
+
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
9
|
+
* @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
|
|
10
|
+
* of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
11
|
+
* is provided and is an array, it is assigned to the `_elements
|
|
12
|
+
*/
|
|
13
|
+
constructor(elements?: E[]);
|
|
14
|
+
protected _elements: E[];
|
|
15
|
+
get elements(): E[];
|
|
16
|
+
/**
|
|
17
|
+
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
18
|
+
* @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
|
|
19
|
+
* @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
|
|
20
|
+
* array.
|
|
21
|
+
*/
|
|
22
|
+
static fromArray<E>(elements: E[]): Stack<E>;
|
|
23
|
+
/**
|
|
24
|
+
* The function checks if an array is empty and returns a boolean value.
|
|
25
|
+
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
26
|
+
*/
|
|
27
|
+
isEmpty(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The size() function returns the number of elements in an array.
|
|
30
|
+
* @returns The size of the elements array.
|
|
31
|
+
*/
|
|
32
|
+
size(): number;
|
|
33
|
+
/**
|
|
34
|
+
* The `peek` function returns the last element of an array, or null if the array is empty.
|
|
35
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
|
|
36
|
+
*/
|
|
37
|
+
peek(): E | null;
|
|
38
|
+
/**
|
|
39
|
+
* The push function adds an element to the stack and returns the updated stack.
|
|
40
|
+
* @param {E} element - The parameter "element" is of type E, which means it can be any data type.
|
|
41
|
+
* @returns The `push` method is returning the updated `Stack<E>` object.
|
|
42
|
+
*/
|
|
43
|
+
push(element: E): Stack<E>;
|
|
44
|
+
/**
|
|
45
|
+
* The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
|
|
46
|
+
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
47
|
+
* array is empty, it returns `null`.
|
|
48
|
+
*/
|
|
49
|
+
pop(): E | null;
|
|
50
|
+
/**
|
|
51
|
+
* The toArray function returns a copy of the elements in an array.
|
|
52
|
+
* @returns An array of type E.
|
|
53
|
+
*/
|
|
54
|
+
toArray(): E[];
|
|
55
|
+
/**
|
|
56
|
+
* The clear function clears the elements array.
|
|
57
|
+
*/
|
|
58
|
+
clear(): void;
|
|
59
|
+
/**
|
|
60
|
+
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
61
|
+
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
62
|
+
*/
|
|
63
|
+
clone(): Stack<E>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Stack = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class Stack {
|
|
10
|
+
/**
|
|
11
|
+
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
12
|
+
* @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
|
|
13
|
+
* of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
14
|
+
* is provided and is an array, it is assigned to the `_elements
|
|
15
|
+
*/
|
|
16
|
+
constructor(elements) {
|
|
17
|
+
this._elements = Array.isArray(elements) ? elements : [];
|
|
18
|
+
}
|
|
19
|
+
get elements() {
|
|
20
|
+
return this._elements;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
24
|
+
* @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
|
|
25
|
+
* @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
|
|
26
|
+
* array.
|
|
27
|
+
*/
|
|
28
|
+
static fromArray(elements) {
|
|
29
|
+
return new Stack(elements);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The function checks if an array is empty and returns a boolean value.
|
|
33
|
+
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
34
|
+
*/
|
|
35
|
+
isEmpty() {
|
|
36
|
+
return this.elements.length === 0;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The size() function returns the number of elements in an array.
|
|
40
|
+
* @returns The size of the elements array.
|
|
41
|
+
*/
|
|
42
|
+
size() {
|
|
43
|
+
return this.elements.length;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The `peek` function returns the last element of an array, or null if the array is empty.
|
|
47
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
|
|
48
|
+
*/
|
|
49
|
+
peek() {
|
|
50
|
+
if (this.isEmpty())
|
|
51
|
+
return null;
|
|
52
|
+
return this.elements[this.elements.length - 1];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The push function adds an element to the stack and returns the updated stack.
|
|
56
|
+
* @param {E} element - The parameter "element" is of type E, which means it can be any data type.
|
|
57
|
+
* @returns The `push` method is returning the updated `Stack<E>` object.
|
|
58
|
+
*/
|
|
59
|
+
push(element) {
|
|
60
|
+
this.elements.push(element);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
|
|
65
|
+
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
66
|
+
* array is empty, it returns `null`.
|
|
67
|
+
*/
|
|
68
|
+
pop() {
|
|
69
|
+
if (this.isEmpty())
|
|
70
|
+
return null;
|
|
71
|
+
return this.elements.pop() || null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The toArray function returns a copy of the elements in an array.
|
|
75
|
+
* @returns An array of type E.
|
|
76
|
+
*/
|
|
77
|
+
toArray() {
|
|
78
|
+
return this.elements.slice();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The clear function clears the elements array.
|
|
82
|
+
*/
|
|
83
|
+
clear() {
|
|
84
|
+
this._elements = [];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
88
|
+
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
89
|
+
*/
|
|
90
|
+
clone() {
|
|
91
|
+
return new Stack(this.elements.slice());
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.Stack = Stack;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tree';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./tree"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class TreeNode<V = any> {
|
|
2
|
+
key: string;
|
|
3
|
+
value?: V | undefined;
|
|
4
|
+
children?: TreeNode<V>[] | undefined;
|
|
5
|
+
constructor(key: string, value?: V, children?: TreeNode<V>[]);
|
|
6
|
+
addChildren(children: TreeNode<V> | TreeNode<V>[]): void;
|
|
7
|
+
getHeight(): number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TreeNode = void 0;
|
|
4
|
+
class TreeNode {
|
|
5
|
+
constructor(key, value, children) {
|
|
6
|
+
this.key = key;
|
|
7
|
+
this.value = value || undefined;
|
|
8
|
+
this.children = children || [];
|
|
9
|
+
}
|
|
10
|
+
addChildren(children) {
|
|
11
|
+
if (!this.children) {
|
|
12
|
+
this.children = [];
|
|
13
|
+
}
|
|
14
|
+
if (children instanceof TreeNode) {
|
|
15
|
+
this.children.push(children);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.children = this.children.concat(children);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getHeight() {
|
|
22
|
+
let maxDepth = 0;
|
|
23
|
+
if (this) {
|
|
24
|
+
const bfs = (node, level) => {
|
|
25
|
+
if (level > maxDepth) {
|
|
26
|
+
maxDepth = level;
|
|
27
|
+
}
|
|
28
|
+
const { children } = node;
|
|
29
|
+
if (children) {
|
|
30
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
31
|
+
bfs(children[i], level + 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
bfs(this, 0);
|
|
36
|
+
}
|
|
37
|
+
return maxDepth;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.TreeNode = TreeNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './trie';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./trie"), exports);
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
|
|
10
|
+
* and a flag indicating whether it's the end of a word.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TrieNode {
|
|
13
|
+
key: string;
|
|
14
|
+
children: Map<string, TrieNode>;
|
|
15
|
+
isEnd: boolean;
|
|
16
|
+
constructor(key: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Trie {
|
|
22
|
+
constructor(words?: string[], caseSensitive?: boolean);
|
|
23
|
+
protected _caseSensitive: boolean;
|
|
24
|
+
get caseSensitive(): boolean;
|
|
25
|
+
protected _root: TrieNode;
|
|
26
|
+
get root(): TrieNode;
|
|
27
|
+
/**
|
|
28
|
+
* Add a word to the Trie structure.
|
|
29
|
+
* @param {string} word - The word to add.
|
|
30
|
+
* @returns {boolean} True if the word was successfully added.
|
|
31
|
+
*/
|
|
32
|
+
add(word: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Check if the Trie contains a given word.
|
|
35
|
+
* @param {string} word - The word to check for.
|
|
36
|
+
* @returns {boolean} True if the word is present in the Trie.
|
|
37
|
+
*/
|
|
38
|
+
has(word: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Remove a word from the Trie structure.
|
|
41
|
+
* @param{string} word - The word to delete.
|
|
42
|
+
* @returns {boolean} True if the word was successfully removed.
|
|
43
|
+
*/
|
|
44
|
+
delete(word: string): boolean;
|
|
45
|
+
getHeight(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
|
|
48
|
+
* @param {string} input - The input string to check.
|
|
49
|
+
* @returns {boolean} True if it's an absolute prefix in the Trie.
|
|
50
|
+
*/
|
|
51
|
+
hasPurePrefix(input: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 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.
|
|
54
|
+
* @param {string} input - The input string representing the prefix to check.
|
|
55
|
+
* @returns {boolean} True if it's a prefix in the Trie.
|
|
56
|
+
*/
|
|
57
|
+
hasPrefix(input: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
|
|
60
|
+
* @param {string} input - The input string representing the common prefix to check for.
|
|
61
|
+
* @returns {boolean} True if it's a common prefix in the Trie.
|
|
62
|
+
*/
|
|
63
|
+
hasCommonPrefix(input: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Get the longest common prefix among all the words stored in the Trie.
|
|
66
|
+
* @returns {string} The longest common prefix found in the Trie.
|
|
67
|
+
*/
|
|
68
|
+
getLongestCommonPrefix(): string;
|
|
69
|
+
/**
|
|
70
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
71
|
+
* @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
72
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
73
|
+
* @param {number} max - The max count of words will be found
|
|
74
|
+
* @param isAllWhenEmptyPrefix - If true, when the prefix provided as '', returns all the words in the trie.
|
|
75
|
+
* @returns {string[]} an array of strings.
|
|
76
|
+
*/
|
|
77
|
+
getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
|
|
78
|
+
protected _caseProcess(str: string): string;
|
|
79
|
+
}
|