data-structure-typed 1.35.1 → 1.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +21 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +13 -864
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
- package/dist/data-structures/binary-tree/avl-tree.js +90 -3
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +536 -0
- package/dist/data-structures/binary-tree/binary-tree.js +1194 -2
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +133 -0
- package/dist/data-structures/binary-tree/bst.js +114 -0
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/index.d.ts +12 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
- package/dist/data-structures/binary-tree/segment-tree.js +45 -0
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
- package/dist/data-structures/graph/abstract-graph.js +270 -7
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.d.ts +200 -0
- package/dist/data-structures/graph/directed-graph.js +167 -0
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +54 -0
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
- package/dist/data-structures/graph/undirected-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
- package/dist/data-structures/hash/coordinate-map.js +35 -0
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
- package/dist/data-structures/hash/coordinate-set.js +28 -0
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +56 -0
- package/dist/data-structures/hash/hash-map.js +29 -1
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +106 -0
- package/dist/data-structures/hash/hash-table.js +88 -6
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/index.d.ts +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/heap/heap.d.ts +99 -0
- package/dist/data-structures/heap/heap.js +200 -78
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/max-heap.d.ts +12 -0
- package/dist/data-structures/heap/max-heap.js +16 -6
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.d.ts +12 -0
- package/dist/data-structures/heap/min-heap.js +16 -6
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +15 -0
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
- package/dist/data-structures/matrix/matrix2d.js +91 -2
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +28 -0
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.d.ts +201 -0
- package/dist/data-structures/matrix/vector2d.js +188 -1
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +16 -17
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +16 -17
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +12 -0
- package/dist/data-structures/priority-queue/priority-queue.js +11 -174
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.d.ts +165 -0
- package/dist/data-structures/queue/deque.js +124 -0
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/queue.d.ts +107 -0
- package/dist/data-structures/queue/queue.js +80 -0
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/stack.d.ts +63 -0
- package/dist/data-structures/stack/stack.js +50 -0
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +1 -0
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/trie.d.ts +61 -0
- package/dist/data-structures/trie/trie.js +36 -0
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
- package/dist/interfaces/abstract-graph.d.ts +5 -0
- package/dist/interfaces/avl-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +6 -0
- package/dist/interfaces/directed-graph.d.ts +3 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/rb-tree.d.ts +6 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/tree-multiset.d.ts +6 -0
- package/dist/interfaces/undirected-graph.d.ts +3 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +32 -0
- package/dist/types/data-structures/abstract-binary-tree.js +6 -0
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.d.ts +6 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/hash.d.ts +1 -0
- package/dist/types/data-structures/heap.d.ts +1 -0
- package/dist/types/data-structures/index.d.ts +16 -0
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/navigator.d.ts +14 -0
- package/dist/types/data-structures/priority-queue.d.ts +7 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/utils.d.ts +19 -0
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +3 -509
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +1 -1175
- package/lib/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/lib/data-structures/binary-tree/binary-tree.d.ts +506 -1
- package/lib/data-structures/binary-tree/binary-tree.js +1173 -2
- package/lib/data-structures/binary-tree/bst.d.ts +1 -1
- package/lib/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +1 -1
- package/lib/data-structures/graph/abstract-graph.js +3 -5
- package/lib/data-structures/heap/heap.d.ts +84 -68
- package/lib/data-structures/heap/heap.js +168 -107
- package/lib/data-structures/heap/max-heap.d.ts +6 -17
- package/lib/data-structures/heap/max-heap.js +11 -17
- package/lib/data-structures/heap/min-heap.d.ts +6 -18
- package/lib/data-structures/heap/min-heap.js +11 -18
- package/lib/data-structures/priority-queue/max-priority-queue.d.ts +4 -7
- package/lib/data-structures/priority-queue/max-priority-queue.js +11 -30
- package/lib/data-structures/priority-queue/min-priority-queue.d.ts +4 -7
- package/lib/data-structures/priority-queue/min-priority-queue.js +11 -31
- package/lib/data-structures/priority-queue/priority-queue.d.ts +6 -174
- package/lib/data-structures/priority-queue/priority-queue.js +11 -315
- package/lib/types/data-structures/abstract-binary-tree.d.ts +1 -3
- package/lib/types/data-structures/binary-tree.d.ts +4 -2
- package/lib/types/data-structures/heap.d.ts +1 -3
- package/package.json +10 -6
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +4 -1527
- package/src/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/data-structures/binary-tree/binary-tree.ts +1524 -5
- package/src/data-structures/binary-tree/bst.ts +3 -3
- package/src/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/data-structures/binary-tree/tree-multiset.ts +3 -3
- package/src/data-structures/graph/abstract-graph.ts +3 -5
- package/src/data-structures/heap/heap.ts +167 -143
- package/src/data-structures/heap/max-heap.ts +15 -22
- package/src/data-structures/heap/min-heap.ts +15 -23
- package/src/data-structures/priority-queue/max-priority-queue.ts +13 -46
- package/src/data-structures/priority-queue/min-priority-queue.ts +13 -47
- package/src/data-structures/priority-queue/priority-queue.ts +7 -350
- package/src/types/data-structures/abstract-binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree.ts +2 -2
- package/src/types/data-structures/heap.ts +1 -5
- package/test/unit/data-structures/heap/heap.test.ts +26 -18
- package/test/unit/data-structures/heap/max-heap.test.ts +50 -42
- package/test/unit/data-structures/heap/min-heap.test.ts +38 -68
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +9 -10
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +14 -30
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.LICENSE.txt +15 -0
- package/umd/bundle.min.js.map +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
import { SinglyLinkedList } from '../linked-list';
|
|
7
|
+
export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
8
|
+
/**
|
|
9
|
+
* The enqueue function adds a value to the end of an array.
|
|
10
|
+
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
11
|
+
*/
|
|
12
|
+
enqueue(value: E): void;
|
|
13
|
+
/**
|
|
14
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
15
|
+
* @returns The method is returning the element at the front of the queue, or null if the queue is empty.
|
|
16
|
+
*/
|
|
17
|
+
dequeue(): E | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
20
|
+
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
21
|
+
*/
|
|
22
|
+
peek(): E | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare class Queue<E = any> {
|
|
25
|
+
/**
|
|
26
|
+
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
27
|
+
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
28
|
+
* will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
|
|
29
|
+
* initialized as an empty array.
|
|
30
|
+
*/
|
|
31
|
+
constructor(elements?: E[]);
|
|
32
|
+
private _nodes;
|
|
33
|
+
get nodes(): E[];
|
|
34
|
+
set nodes(value: E[]);
|
|
35
|
+
private _offset;
|
|
36
|
+
get offset(): number;
|
|
37
|
+
set offset(value: number);
|
|
38
|
+
/**
|
|
39
|
+
* The size function returns the number of elements in an array.
|
|
40
|
+
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
41
|
+
*/
|
|
42
|
+
get size(): number;
|
|
43
|
+
/**
|
|
44
|
+
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
45
|
+
* @public
|
|
46
|
+
* @static
|
|
47
|
+
* @param {E[]} elements - The "elements" parameter is an array of elements of type E.
|
|
48
|
+
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
49
|
+
* array.
|
|
50
|
+
*/
|
|
51
|
+
static fromArray<E>(elements: E[]): Queue<E>;
|
|
52
|
+
/**
|
|
53
|
+
* 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.
|
|
54
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
55
|
+
* @returns The `add` method is returning a `Queue<E>` object.
|
|
56
|
+
*/
|
|
57
|
+
push(element: E): Queue<E>;
|
|
58
|
+
/**
|
|
59
|
+
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
60
|
+
* necessary to optimize performance.
|
|
61
|
+
* @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
|
|
62
|
+
*/
|
|
63
|
+
shift(): E | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
66
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
67
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
68
|
+
*/
|
|
69
|
+
peek(): E | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
72
|
+
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
73
|
+
* array is empty, it returns `null`.
|
|
74
|
+
*/
|
|
75
|
+
peekLast(): E | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* The enqueue function adds a value to the end of a queue.
|
|
78
|
+
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
79
|
+
*/
|
|
80
|
+
enqueue(value: E): void;
|
|
81
|
+
/**
|
|
82
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
83
|
+
* @returns The method is returning a value of type E or null.
|
|
84
|
+
*/
|
|
85
|
+
dequeue(): E | undefined;
|
|
86
|
+
getAt(index: number): E | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The function checks if a data structure is empty by comparing its size to zero.
|
|
89
|
+
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
90
|
+
*/
|
|
91
|
+
isEmpty(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
|
|
94
|
+
* @returns An array of type E is being returned.
|
|
95
|
+
*/
|
|
96
|
+
toArray(): E[];
|
|
97
|
+
/**
|
|
98
|
+
* The clear function resets the nodes array and offset to their initial values.
|
|
99
|
+
*/
|
|
100
|
+
clear(): void;
|
|
101
|
+
/**
|
|
102
|
+
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
103
|
+
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
104
|
+
*/
|
|
105
|
+
clone(): Queue<E>;
|
|
106
|
+
[Symbol.iterator](): Generator<E, void, unknown>;
|
|
107
|
+
}
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Queue = exports.LinkedListQueue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
4
9
|
const linked_list_1 = require("../linked-list");
|
|
5
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
|
+
*/
|
|
6
15
|
enqueue(value) {
|
|
7
16
|
this.push(value);
|
|
8
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
|
+
*/
|
|
9
22
|
dequeue() {
|
|
10
23
|
return this.shift();
|
|
11
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
27
|
+
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
28
|
+
*/
|
|
12
29
|
peek() {
|
|
13
30
|
var _a;
|
|
14
31
|
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.val;
|
|
@@ -16,6 +33,12 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
|
16
33
|
}
|
|
17
34
|
exports.LinkedListQueue = LinkedListQueue;
|
|
18
35
|
class Queue {
|
|
36
|
+
/**
|
|
37
|
+
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
38
|
+
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
39
|
+
* will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
|
|
40
|
+
* initialized as an empty array.
|
|
41
|
+
*/
|
|
19
42
|
constructor(elements) {
|
|
20
43
|
this._nodes = elements || [];
|
|
21
44
|
this._offset = 0;
|
|
@@ -32,16 +55,38 @@ class Queue {
|
|
|
32
55
|
set offset(value) {
|
|
33
56
|
this._offset = value;
|
|
34
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* The size function returns the number of elements in an array.
|
|
60
|
+
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
61
|
+
*/
|
|
35
62
|
get size() {
|
|
36
63
|
return this.nodes.length - this.offset;
|
|
37
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
67
|
+
* @public
|
|
68
|
+
* @static
|
|
69
|
+
* @param {E[]} elements - The "elements" parameter is an array of elements of type E.
|
|
70
|
+
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
71
|
+
* array.
|
|
72
|
+
*/
|
|
38
73
|
static fromArray(elements) {
|
|
39
74
|
return new Queue(elements);
|
|
40
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* 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.
|
|
78
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
79
|
+
* @returns The `add` method is returning a `Queue<E>` object.
|
|
80
|
+
*/
|
|
41
81
|
push(element) {
|
|
42
82
|
this.nodes.push(element);
|
|
43
83
|
return this;
|
|
44
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
87
|
+
* necessary to optimize performance.
|
|
88
|
+
* @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
|
|
89
|
+
*/
|
|
45
90
|
shift() {
|
|
46
91
|
if (this.size === 0)
|
|
47
92
|
return undefined;
|
|
@@ -49,35 +94,70 @@ class Queue {
|
|
|
49
94
|
this.offset += 1;
|
|
50
95
|
if (this.offset * 2 < this.nodes.length)
|
|
51
96
|
return first;
|
|
97
|
+
// only remove dequeued elements when reaching half size
|
|
98
|
+
// to decrease latency of shifting elements.
|
|
52
99
|
this.nodes = this.nodes.slice(this.offset);
|
|
53
100
|
this.offset = 0;
|
|
54
101
|
return first;
|
|
55
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
105
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
106
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
107
|
+
*/
|
|
56
108
|
peek() {
|
|
57
109
|
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
58
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
113
|
+
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
114
|
+
* array is empty, it returns `null`.
|
|
115
|
+
*/
|
|
59
116
|
peekLast() {
|
|
60
117
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
61
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The enqueue function adds a value to the end of a queue.
|
|
121
|
+
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
122
|
+
*/
|
|
62
123
|
enqueue(value) {
|
|
63
124
|
this.push(value);
|
|
64
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
|
|
128
|
+
* @returns The method is returning a value of type E or null.
|
|
129
|
+
*/
|
|
65
130
|
dequeue() {
|
|
66
131
|
return this.shift();
|
|
67
132
|
}
|
|
68
133
|
getAt(index) {
|
|
69
134
|
return this.nodes[index];
|
|
70
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* The function checks if a data structure is empty by comparing its size to zero.
|
|
138
|
+
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
139
|
+
*/
|
|
71
140
|
isEmpty() {
|
|
72
141
|
return this.size === 0;
|
|
73
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
|
|
145
|
+
* @returns An array of type E is being returned.
|
|
146
|
+
*/
|
|
74
147
|
toArray() {
|
|
75
148
|
return this.nodes.slice(this.offset);
|
|
76
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The clear function resets the nodes array and offset to their initial values.
|
|
152
|
+
*/
|
|
77
153
|
clear() {
|
|
78
154
|
this.nodes = [];
|
|
79
155
|
this.offset = 0;
|
|
80
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
159
|
+
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
160
|
+
*/
|
|
81
161
|
clone() {
|
|
82
162
|
return new Queue(this.nodes.slice(this.offset));
|
|
83
163
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,gDAAgD;AAEhD,MAAa,eAAyB,SAAQ,8BAAmB;IAC/D;;;OAGG;IACH,OAAO,CAAC,KAAQ;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI;;QACF,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,GAAG,CAAC;IACxB,CAAC;CACF;AAxBD,0CAwBC;AAED,MAAa,KAAK;IAChB;;;;;OAKG;IACH,YAAY,QAAc;QACxB,IAAI,CAAC,MAAM,GAAG,QAAQ,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,KAAK,CAAC,KAAU;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAID,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,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K,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvE,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KAAQ;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAa;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE;YAC7B,MAAM,IAAI,CAAC;SACZ;IACH,CAAC;CACF;AA7JD,sBA6JC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stack';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export declare class Stack<E = any> {
|
|
7
|
+
protected _elements: E[];
|
|
8
|
+
/**
|
|
9
|
+
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
10
|
+
* @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
|
|
11
|
+
* of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
12
|
+
* is provided and is an array, it is assigned to the `_elements
|
|
13
|
+
*/
|
|
14
|
+
constructor(elements?: E[]);
|
|
15
|
+
/**
|
|
16
|
+
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
17
|
+
* @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
|
|
18
|
+
* @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
|
|
19
|
+
* array.
|
|
20
|
+
*/
|
|
21
|
+
static fromArray<E>(elements: E[]): Stack<E>;
|
|
22
|
+
/**
|
|
23
|
+
* The function checks if an array is empty and returns a boolean value.
|
|
24
|
+
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
25
|
+
*/
|
|
26
|
+
isEmpty(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The size() function returns the number of elements in an array.
|
|
29
|
+
* @returns The size of the elements array.
|
|
30
|
+
*/
|
|
31
|
+
size(): number;
|
|
32
|
+
/**
|
|
33
|
+
* The `peek` function returns the last element of an array, or null if the array is empty.
|
|
34
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
|
|
35
|
+
*/
|
|
36
|
+
peek(): E | null;
|
|
37
|
+
/**
|
|
38
|
+
* The push function adds an element to the stack and returns the updated stack.
|
|
39
|
+
* @param {E} element - The parameter "element" is of type E, which means it can be any data type.
|
|
40
|
+
* @returns The `push` method is returning the updated `Stack<E>` object.
|
|
41
|
+
*/
|
|
42
|
+
push(element: E): Stack<E>;
|
|
43
|
+
/**
|
|
44
|
+
* The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
|
|
45
|
+
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
46
|
+
* array is empty, it returns `null`.
|
|
47
|
+
*/
|
|
48
|
+
pop(): E | null;
|
|
49
|
+
/**
|
|
50
|
+
* The toArray function returns a copy of the elements in an array.
|
|
51
|
+
* @returns An array of type E.
|
|
52
|
+
*/
|
|
53
|
+
toArray(): E[];
|
|
54
|
+
/**
|
|
55
|
+
* The clear function clears the elements array.
|
|
56
|
+
*/
|
|
57
|
+
clear(): void;
|
|
58
|
+
/**
|
|
59
|
+
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
60
|
+
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
61
|
+
*/
|
|
62
|
+
clone(): Stack<E>;
|
|
63
|
+
}
|
|
@@ -1,39 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Stack = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @license MIT
|
|
6
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
4
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
|
+
*/
|
|
5
16
|
constructor(elements) {
|
|
6
17
|
this._elements = Array.isArray(elements) ? elements : [];
|
|
7
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
21
|
+
* @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
|
|
22
|
+
* @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
|
|
23
|
+
* array.
|
|
24
|
+
*/
|
|
8
25
|
static fromArray(elements) {
|
|
9
26
|
return new Stack(elements);
|
|
10
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The function checks if an array is empty and returns a boolean value.
|
|
30
|
+
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
31
|
+
*/
|
|
11
32
|
isEmpty() {
|
|
12
33
|
return this._elements.length === 0;
|
|
13
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The size() function returns the number of elements in an array.
|
|
37
|
+
* @returns The size of the elements array.
|
|
38
|
+
*/
|
|
14
39
|
size() {
|
|
15
40
|
return this._elements.length;
|
|
16
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The `peek` function returns the last element of an array, or null if the array is empty.
|
|
44
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
|
|
45
|
+
*/
|
|
17
46
|
peek() {
|
|
18
47
|
if (this.isEmpty())
|
|
19
48
|
return null;
|
|
20
49
|
return this._elements[this._elements.length - 1];
|
|
21
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The push function adds an element to the stack and returns the updated stack.
|
|
53
|
+
* @param {E} element - The parameter "element" is of type E, which means it can be any data type.
|
|
54
|
+
* @returns The `push` method is returning the updated `Stack<E>` object.
|
|
55
|
+
*/
|
|
22
56
|
push(element) {
|
|
23
57
|
this._elements.push(element);
|
|
24
58
|
return this;
|
|
25
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
|
|
62
|
+
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
63
|
+
* array is empty, it returns `null`.
|
|
64
|
+
*/
|
|
26
65
|
pop() {
|
|
27
66
|
if (this.isEmpty())
|
|
28
67
|
return null;
|
|
29
68
|
return this._elements.pop() || null;
|
|
30
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The toArray function returns a copy of the elements in an array.
|
|
72
|
+
* @returns An array of type E.
|
|
73
|
+
*/
|
|
31
74
|
toArray() {
|
|
32
75
|
return this._elements.slice();
|
|
33
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* The clear function clears the elements array.
|
|
79
|
+
*/
|
|
34
80
|
clear() {
|
|
35
81
|
this._elements = [];
|
|
36
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
85
|
+
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
86
|
+
*/
|
|
37
87
|
clone() {
|
|
38
88
|
return new Stack(this._elements.slice());
|
|
39
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,KAAK;IAGhB;;;;;OAKG;IACH,YAAY,QAAc;QACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAI,QAAa;QAC/B,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,IAAI,CAAC;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,OAAU;QACb,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,GAAG;QACD,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,IAAI,CAAC;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AA5FD,sBA4FC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tree';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class TreeNode<V = any> {
|
|
2
|
+
constructor(key: string, value?: V, children?: TreeNode<V>[]);
|
|
3
|
+
private _key;
|
|
4
|
+
get key(): string;
|
|
5
|
+
set key(value: string);
|
|
6
|
+
private _value?;
|
|
7
|
+
get value(): V | undefined;
|
|
8
|
+
set value(value: V | undefined);
|
|
9
|
+
private _children?;
|
|
10
|
+
get children(): TreeNode<V>[] | undefined;
|
|
11
|
+
set children(value: TreeNode<V>[] | undefined);
|
|
12
|
+
addChildren(children: TreeNode<V> | TreeNode<V>[]): void;
|
|
13
|
+
getHeight(): number;
|
|
14
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/data-structures/tree/tree.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAQ;IACnB,YAAY,GAAW,EAAE,KAAS,EAAE,QAAwB;QAC1D,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,SAAS,CAAC;QACjC,IA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,GAAG,CAAC,CAAC,CAAC;qBAC7B;iBACF;YACH,CAAC,CAAC;YACF,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;SACnB;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AApED,4BAoEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './trie';
|
|
@@ -0,0 +1,61 @@
|
|
|
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 declare class TrieNode {
|
|
9
|
+
constructor(v: string);
|
|
10
|
+
private _val;
|
|
11
|
+
get val(): string;
|
|
12
|
+
set val(v: string);
|
|
13
|
+
protected _children: Map<string, TrieNode>;
|
|
14
|
+
get children(): Map<string, TrieNode>;
|
|
15
|
+
set children(v: Map<string, TrieNode>);
|
|
16
|
+
protected _isEnd: boolean;
|
|
17
|
+
get isEnd(): boolean;
|
|
18
|
+
set isEnd(v: boolean);
|
|
19
|
+
}
|
|
20
|
+
export declare class Trie {
|
|
21
|
+
constructor(words?: string[]);
|
|
22
|
+
protected _root: TrieNode;
|
|
23
|
+
get root(): TrieNode;
|
|
24
|
+
set root(v: TrieNode);
|
|
25
|
+
add(word: string): boolean;
|
|
26
|
+
has(input: string): boolean;
|
|
27
|
+
remove(word: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
|
|
30
|
+
* @param {string} input - The input parameter is a string that represents the input value for the function.
|
|
31
|
+
* @returns a boolean value.
|
|
32
|
+
*/
|
|
33
|
+
isAbsPrefix(input: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
|
|
36
|
+
* @param {string} input - The input parameter is a string that represents the prefix we want to check.
|
|
37
|
+
* @returns a boolean value.
|
|
38
|
+
*/
|
|
39
|
+
isPrefix(input: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
|
|
42
|
+
* @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
|
|
43
|
+
* in the Trie data structure.
|
|
44
|
+
* @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
|
|
45
|
+
*/
|
|
46
|
+
isCommonPrefix(input: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
|
|
49
|
+
* structure.
|
|
50
|
+
* @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
|
|
51
|
+
* Trie.
|
|
52
|
+
*/
|
|
53
|
+
getLongestCommonPrefix(): string;
|
|
54
|
+
/**
|
|
55
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
56
|
+
* @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
57
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
58
|
+
* @returns an array of strings.
|
|
59
|
+
*/
|
|
60
|
+
getAll(prefix?: string): string[];
|
|
61
|
+
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Trie = exports.TrieNode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
4
11
|
class TrieNode {
|
|
5
12
|
constructor(v) {
|
|
6
13
|
this._val = v;
|
|
@@ -96,6 +103,12 @@ class Trie {
|
|
|
96
103
|
dfs(this.root, 0);
|
|
97
104
|
return isDeleted;
|
|
98
105
|
}
|
|
106
|
+
// --- start additional methods ---
|
|
107
|
+
/**
|
|
108
|
+
* The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
|
|
109
|
+
* @param {string} input - The input parameter is a string that represents the input value for the function.
|
|
110
|
+
* @returns a boolean value.
|
|
111
|
+
*/
|
|
99
112
|
isAbsPrefix(input) {
|
|
100
113
|
let cur = this._root;
|
|
101
114
|
for (const c of input) {
|
|
@@ -106,6 +119,11 @@ class Trie {
|
|
|
106
119
|
}
|
|
107
120
|
return !cur.isEnd;
|
|
108
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
|
|
124
|
+
* @param {string} input - The input parameter is a string that represents the prefix we want to check.
|
|
125
|
+
* @returns a boolean value.
|
|
126
|
+
*/
|
|
109
127
|
isPrefix(input) {
|
|
110
128
|
let cur = this._root;
|
|
111
129
|
for (const c of input) {
|
|
@@ -116,6 +134,12 @@ class Trie {
|
|
|
116
134
|
}
|
|
117
135
|
return true;
|
|
118
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
|
|
139
|
+
* @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
|
|
140
|
+
* in the Trie data structure.
|
|
141
|
+
* @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
|
|
142
|
+
*/
|
|
119
143
|
isCommonPrefix(input) {
|
|
120
144
|
let commonPre = '';
|
|
121
145
|
const dfs = (cur) => {
|
|
@@ -132,6 +156,12 @@ class Trie {
|
|
|
132
156
|
dfs(this._root);
|
|
133
157
|
return commonPre === input;
|
|
134
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
|
|
161
|
+
* structure.
|
|
162
|
+
* @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
|
|
163
|
+
* Trie.
|
|
164
|
+
*/
|
|
135
165
|
getLongestCommonPrefix() {
|
|
136
166
|
let commonPre = '';
|
|
137
167
|
const dfs = (cur) => {
|
|
@@ -146,6 +176,12 @@ class Trie {
|
|
|
146
176
|
dfs(this._root);
|
|
147
177
|
return commonPre;
|
|
148
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
181
|
+
* @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
182
|
+
* trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
|
|
183
|
+
* @returns an array of strings.
|
|
184
|
+
*/
|
|
149
185
|
getAll(prefix = '') {
|
|
150
186
|
const words = [];
|
|
151
187
|
function dfs(node, word) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,QAAQ;IACnB,YAAY,CAAS;QACnB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC/C,CAAC;IAID,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,GAAG,CAAC,CAAS;QACf,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAChB,CAAC;IAID,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,CAAC,CAAwB;QACnC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACrB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,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AAE,SAAS,GAAG,KAAK,CAAC;aAC9B;SACF;QAED,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;CAGF;AAnLD,oBAmLC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BinaryTreeNodeKey } from '../types';
|
|
2
|
+
import { AbstractBinaryTreeNode } from '../data-structures';
|
|
3
|
+
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
|
4
|
+
}
|
|
5
|
+
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
6
|
+
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null;
|
|
7
|
+
}
|