data-structure-typed 1.33.0 → 1.33.5
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.json → .eslintrc.js} +2 -1
- package/.github/workflows/ci.yml +15 -3
- package/.github/workflows/release-package.yml +32 -0
- package/{.prettierrc → .prettierrc.js} +1 -1
- package/CHANGELOG.md +5 -1
- package/README.md +196 -257
- package/coverage/coverage-final.json +64 -64
- package/coverage/coverage-summary.json +16 -16
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1 -16
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +3 -4
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +12 -12
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +107 -2
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +30 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +5 -8
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +6 -6
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/docs/index.html +196 -256
- package/docs/modules.html +2 -0
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +8 -18
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +5 -23
- package/lib/data-structures/binary-tree/avl-tree.d.ts +7 -10
- package/lib/data-structures/binary-tree/avl-tree.js +6 -9
- package/lib/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/lib/data-structures/binary-tree/bst.d.ts +2 -2
- package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/lib/data-structures/binary-tree/rb-tree.js +3 -3
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +3 -3
- package/lib/data-structures/binary-tree/tree-multiset.js +1 -1
- package/lib/data-structures/graph/abstract-graph.d.ts +10 -10
- package/lib/data-structures/graph/abstract-graph.js +2 -2
- package/lib/data-structures/graph/directed-graph.d.ts +6 -6
- package/lib/data-structures/graph/directed-graph.js +2 -2
- package/lib/data-structures/graph/map-graph.d.ts +6 -6
- package/lib/data-structures/graph/map-graph.js +2 -2
- package/lib/data-structures/graph/undirected-graph.d.ts +6 -6
- package/lib/data-structures/graph/undirected-graph.js +2 -2
- package/lib/data-structures/hash/hash-table.d.ts +61 -1
- package/lib/data-structures/hash/hash-table.js +136 -0
- package/lib/data-structures/heap/heap.d.ts +31 -31
- package/lib/data-structures/heap/heap.js +11 -11
- package/lib/data-structures/heap/max-heap.d.ts +4 -4
- package/lib/data-structures/heap/max-heap.js +1 -1
- package/lib/data-structures/heap/min-heap.d.ts +4 -4
- package/lib/data-structures/heap/min-heap.js +1 -1
- package/lib/data-structures/linked-list/doubly-linked-list.d.ts +93 -54
- package/lib/data-structures/linked-list/doubly-linked-list.js +79 -22
- package/lib/data-structures/linked-list/singly-linked-list.d.ts +46 -46
- package/lib/data-structures/linked-list/singly-linked-list.js +20 -20
- package/lib/data-structures/matrix/matrix.d.ts +3 -3
- package/lib/data-structures/matrix/matrix2d.d.ts +1 -1
- package/lib/data-structures/matrix/matrix2d.js +3 -2
- package/lib/data-structures/priority-queue/max-priority-queue.d.ts +4 -4
- package/lib/data-structures/priority-queue/min-priority-queue.d.ts +4 -4
- package/lib/data-structures/priority-queue/priority-queue.d.ts +26 -26
- package/lib/data-structures/priority-queue/priority-queue.js +8 -8
- package/lib/data-structures/queue/deque.d.ts +30 -30
- package/lib/data-structures/queue/deque.js +7 -7
- package/lib/data-structures/queue/queue.d.ts +27 -27
- package/lib/data-structures/queue/queue.js +8 -8
- package/lib/data-structures/stack/stack.d.ts +15 -15
- package/lib/data-structures/stack/stack.js +6 -6
- package/lib/data-structures/tree/tree.d.ts +7 -7
- package/lib/interfaces/abstract-binary-tree.d.ts +0 -1
- package/lib/interfaces/avl-tree.d.ts +1 -1
- package/lib/types/data-structures/navigator.d.ts +1 -1
- package/package.json +68 -62
- package/src/data-structures/binary-tree/aa-tree.ts +1 -0
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +1608 -0
- package/src/data-structures/binary-tree/avl-tree.ts +307 -0
- package/src/data-structures/binary-tree/b-tree.ts +1 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +76 -0
- package/src/data-structures/binary-tree/binary-tree.ts +47 -0
- package/src/data-structures/binary-tree/bst.ts +537 -0
- package/src/data-structures/binary-tree/index.ts +12 -0
- package/src/data-structures/binary-tree/rb-tree.ts +366 -0
- package/src/data-structures/binary-tree/segment-tree.ts +242 -0
- package/src/data-structures/binary-tree/splay-tree.ts +1 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +700 -0
- package/src/data-structures/binary-tree/two-three-tree.ts +1 -0
- package/src/data-structures/graph/abstract-graph.ts +1040 -0
- package/src/data-structures/graph/directed-graph.ts +470 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +129 -0
- package/src/data-structures/graph/undirected-graph.ts +274 -0
- package/src/data-structures/hash/coordinate-map.ts +67 -0
- package/src/data-structures/hash/coordinate-set.ts +56 -0
- package/src/data-structures/hash/hash-table.ts +157 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/pair.ts +1 -0
- package/src/data-structures/hash/tree-map.ts +1 -0
- package/src/data-structures/hash/tree-set.ts +1 -0
- package/src/data-structures/heap/heap.ts +212 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +31 -0
- package/src/data-structures/heap/min-heap.ts +32 -0
- package/src/data-structures/index.ts +11 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +636 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +501 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -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 +213 -0
- package/src/data-structures/matrix/navigator.ts +121 -0
- package/src/data-structures/matrix/vector2d.ts +316 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +56 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/priority-queue.ts +359 -0
- package/src/data-structures/queue/deque.ts +297 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +191 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +98 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +69 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +225 -0
- package/src/index.ts +4 -0
- package/src/interfaces/abstract-binary-tree.ts +189 -0
- package/src/interfaces/abstract-graph.ts +31 -0
- package/src/interfaces/avl-tree.ts +25 -0
- package/src/interfaces/binary-tree.ts +6 -0
- package/src/interfaces/bst.ts +31 -0
- package/src/interfaces/directed-graph.ts +20 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +15 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/rb-tree.ts +9 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/interfaces/tree-multiset.ts +7 -0
- package/src/interfaces/undirected-graph.ts +6 -0
- package/src/types/data-structures/abstract-binary-tree.ts +50 -0
- package/src/types/data-structures/abstract-graph.ts +11 -0
- package/src/types/data-structures/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree.ts +5 -0
- package/src/types/data-structures/bst.ts +13 -0
- package/src/types/data-structures/directed-graph.ts +8 -0
- package/src/types/data-structures/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/heap.ts +5 -0
- package/src/types/data-structures/index.ts +15 -0
- package/src/types/data-structures/map-graph.ts +1 -0
- package/src/types/data-structures/navigator.ts +13 -0
- package/src/types/data-structures/priority-queue.ts +9 -0
- package/src/types/data-structures/rb-tree.ts +8 -0
- package/src/types/data-structures/segment-tree.ts +1 -0
- package/src/types/data-structures/singly-linked-list.ts +1 -0
- package/src/types/data-structures/tree-multiset.ts +6 -0
- package/src/types/helpers.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 +79 -0
- package/test/integration/avl-tree.test.ts +14 -17
- package/test/integration/bst.test.ts +50 -41
- package/test/integration/heap.test.js +0 -3
- package/test/integration/index.html +6 -6
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -17
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +142 -0
- package/test/unit/data-structures/binary-tree/bst.test.ts +50 -41
- package/test/unit/data-structures/binary-tree/overall.test.ts +36 -28
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +43 -0
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +23 -12
- package/test/unit/data-structures/graph/directed-graph.test.ts +27 -25
- package/test/unit/data-structures/graph/map-graph.test.ts +4 -5
- package/test/unit/data-structures/graph/overall.test.ts +10 -11
- package/test/unit/data-structures/graph/undirected-graph.test.ts +0 -1
- package/test/unit/data-structures/hash/coordinate-map.test.ts +54 -0
- package/test/unit/data-structures/hash/coordinate-set.test.ts +41 -0
- package/test/unit/data-structures/hash/hash-table.test.ts +97 -0
- package/test/unit/data-structures/heap/heap.test.ts +7 -8
- package/test/unit/data-structures/heap/max-heap.test.ts +7 -5
- package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +8 -9
- package/test/unit/data-structures/linked-list/linked-list.test.ts +2 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +57 -7
- package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +3 -3
- package/test/unit/data-structures/matrix/matrix.test.ts +54 -0
- package/test/unit/data-structures/matrix/matrix2d.test.ts +138 -0
- package/test/unit/data-structures/matrix/navigator.test.ts +79 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +5 -7
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +13 -13
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +8 -8
- package/test/unit/data-structures/queue/deque.test.ts +130 -0
- package/test/unit/data-structures/queue/queue.test.ts +167 -4
- package/test/unit/data-structures/stack/stack.test.ts +67 -0
- package/test/unit/data-structures/tree/tree.test.ts +39 -0
- package/test/unit/data-structures/trie/trie.test.ts +95 -0
- package/test/utils/magnitude.ts +3 -3
- package/tsconfig.json +3 -12
- package/tsconfig.prod.json +25 -0
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
- package/.auto-changelog +0 -9
- package/.gitattributes +0 -112
- package/.idea/data-structure-typed.iml +0 -19
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.prettierignore +0 -6
- package/webpack.config.js +0 -28
|
@@ -5,81 +5,81 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
export declare class SinglyLinkedListNode<
|
|
8
|
+
export declare class SinglyLinkedListNode<E = any> {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
11
|
-
* @param {
|
|
11
|
+
* @param {E} val - The "val" parameter is of type E, which means it can be any data type. It represents the value that
|
|
12
12
|
* will be stored in the node of a linked list.
|
|
13
13
|
*/
|
|
14
|
-
constructor(val:
|
|
14
|
+
constructor(val: E);
|
|
15
15
|
private _val;
|
|
16
|
-
get val():
|
|
17
|
-
set val(value:
|
|
16
|
+
get val(): E;
|
|
17
|
+
set val(value: E);
|
|
18
18
|
private _next;
|
|
19
|
-
get next(): SinglyLinkedListNode<
|
|
20
|
-
set next(value: SinglyLinkedListNode<
|
|
19
|
+
get next(): SinglyLinkedListNode<E> | null;
|
|
20
|
+
set next(value: SinglyLinkedListNode<E> | null);
|
|
21
21
|
}
|
|
22
|
-
export declare class SinglyLinkedList<
|
|
22
|
+
export declare class SinglyLinkedList<E = any> {
|
|
23
23
|
/**
|
|
24
24
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
25
25
|
*/
|
|
26
26
|
constructor();
|
|
27
27
|
private _head;
|
|
28
|
-
get head(): SinglyLinkedListNode<
|
|
29
|
-
set head(value: SinglyLinkedListNode<
|
|
28
|
+
get head(): SinglyLinkedListNode<E> | null;
|
|
29
|
+
set head(value: SinglyLinkedListNode<E> | null);
|
|
30
30
|
private _tail;
|
|
31
|
-
get tail(): SinglyLinkedListNode<
|
|
32
|
-
set tail(value: SinglyLinkedListNode<
|
|
31
|
+
get tail(): SinglyLinkedListNode<E> | null;
|
|
32
|
+
set tail(value: SinglyLinkedListNode<E> | null);
|
|
33
33
|
private _length;
|
|
34
34
|
get length(): number;
|
|
35
35
|
/**
|
|
36
36
|
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
37
37
|
* array.
|
|
38
|
-
* @param {
|
|
38
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
39
39
|
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
40
40
|
*/
|
|
41
|
-
static fromArray<
|
|
41
|
+
static fromArray<E>(data: E[]): SinglyLinkedList<E>;
|
|
42
42
|
getLength(): number;
|
|
43
43
|
/**
|
|
44
44
|
* The `push` function adds a new node with the given data to the end of a singly linked list.
|
|
45
|
-
* @param {
|
|
46
|
-
* any type (
|
|
45
|
+
* @param {E} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
|
|
46
|
+
* any type (E) as specified in the generic type declaration of the class or function.
|
|
47
47
|
*/
|
|
48
|
-
push(data:
|
|
48
|
+
push(data: E): void;
|
|
49
49
|
/**
|
|
50
50
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
51
51
|
* pointers accordingly.
|
|
52
52
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
53
53
|
* the linked list is empty, it returns `null`.
|
|
54
54
|
*/
|
|
55
|
-
pop():
|
|
55
|
+
pop(): E | undefined;
|
|
56
56
|
/**
|
|
57
57
|
* The `shift()` function removes and returns the value of the first node in a linked list.
|
|
58
58
|
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
59
59
|
*/
|
|
60
|
-
shift():
|
|
60
|
+
shift(): E | undefined;
|
|
61
61
|
/**
|
|
62
62
|
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
63
|
-
* @param {
|
|
63
|
+
* @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
|
|
64
64
|
* linked list.
|
|
65
65
|
*/
|
|
66
|
-
unshift(val:
|
|
66
|
+
unshift(val: E): void;
|
|
67
67
|
/**
|
|
68
68
|
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
69
69
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
70
70
|
* retrieve from the list.
|
|
71
|
-
* @returns The method `getAt(index: number):
|
|
71
|
+
* @returns The method `getAt(index: number): E | null` returns the value at the specified index in the linked list, or
|
|
72
72
|
* `null` if the index is out of bounds.
|
|
73
73
|
*/
|
|
74
|
-
getAt(index: number):
|
|
74
|
+
getAt(index: number): E | undefined;
|
|
75
75
|
/**
|
|
76
76
|
* The function `getNodeAt` returns the node at a given index in a singly linked list.
|
|
77
77
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
78
78
|
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
79
|
-
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<
|
|
79
|
+
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
|
|
80
80
|
* specified index exists, or `null` if the index is out of bounds.
|
|
81
81
|
*/
|
|
82
|
-
getNodeAt(index: number): SinglyLinkedListNode<
|
|
82
|
+
getNodeAt(index: number): SinglyLinkedListNode<E> | null;
|
|
83
83
|
/**
|
|
84
84
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
85
85
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
@@ -87,19 +87,19 @@ export declare class SinglyLinkedList<T = any> {
|
|
|
87
87
|
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
88
88
|
* bounds.
|
|
89
89
|
*/
|
|
90
|
-
deleteAt(index: number):
|
|
91
|
-
delete(valueOrNode:
|
|
92
|
-
delete(valueOrNode: SinglyLinkedListNode<
|
|
90
|
+
deleteAt(index: number): E | undefined;
|
|
91
|
+
delete(valueOrNode: E): boolean;
|
|
92
|
+
delete(valueOrNode: SinglyLinkedListNode<E>): boolean;
|
|
93
93
|
/**
|
|
94
94
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
95
95
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
96
96
|
* linked list. It is of type number.
|
|
97
|
-
* @param {
|
|
97
|
+
* @param {E} val - The `val` parameter represents the value that you want to insert into the linked list at the
|
|
98
98
|
* specified index.
|
|
99
99
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
100
100
|
* if the index is out of bounds.
|
|
101
101
|
*/
|
|
102
|
-
insertAt(index: number, val:
|
|
102
|
+
insertAt(index: number, val: E): boolean;
|
|
103
103
|
/**
|
|
104
104
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
105
105
|
* whether it is empty or not.
|
|
@@ -112,9 +112,9 @@ export declare class SinglyLinkedList<T = any> {
|
|
|
112
112
|
clear(): void;
|
|
113
113
|
/**
|
|
114
114
|
* The `toArray` function converts a linked list into an array.
|
|
115
|
-
* @returns The `toArray()` method is returning an array of type `
|
|
115
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
116
116
|
*/
|
|
117
|
-
toArray():
|
|
117
|
+
toArray(): E[];
|
|
118
118
|
/**
|
|
119
119
|
* The `reverse` function reverses the order of the nodes in a singly linked list.
|
|
120
120
|
* @returns The reverse() method does not return anything. It has a return type of void.
|
|
@@ -122,36 +122,36 @@ export declare class SinglyLinkedList<T = any> {
|
|
|
122
122
|
reverse(): void;
|
|
123
123
|
/**
|
|
124
124
|
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
125
|
-
* @param callback - A function that takes a value of type
|
|
125
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
126
126
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
127
127
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
128
128
|
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
129
129
|
*/
|
|
130
|
-
find(callback: (val:
|
|
130
|
+
find(callback: (val: E) => boolean): E | null;
|
|
131
131
|
/**
|
|
132
132
|
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
|
|
133
|
-
* @param {
|
|
133
|
+
* @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
|
|
134
134
|
* @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
|
|
135
135
|
* value is not found, it returns -1.
|
|
136
136
|
*/
|
|
137
|
-
indexOf(value:
|
|
137
|
+
indexOf(value: E): number;
|
|
138
138
|
/**
|
|
139
139
|
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
|
|
140
140
|
* null.
|
|
141
|
-
* @param {
|
|
142
|
-
* @returns a `SinglyLinkedListNode<
|
|
141
|
+
* @param {E} value - The value parameter is the value that we want to search for in the linked list.
|
|
142
|
+
* @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
|
|
143
143
|
* the specified value is found, the function returns `null`.
|
|
144
144
|
*/
|
|
145
|
-
findNode(value:
|
|
146
|
-
insertBefore(existingValue:
|
|
147
|
-
insertBefore(existingValue: SinglyLinkedListNode<
|
|
148
|
-
insertAfter(existingValueOrNode:
|
|
149
|
-
insertAfter(existingValueOrNode: SinglyLinkedListNode<
|
|
145
|
+
findNode(value: E): SinglyLinkedListNode<E> | null;
|
|
146
|
+
insertBefore(existingValue: E, newValue: E): boolean;
|
|
147
|
+
insertBefore(existingValue: SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
148
|
+
insertAfter(existingValueOrNode: E, newValue: E): boolean;
|
|
149
|
+
insertAfter(existingValueOrNode: SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
150
150
|
/**
|
|
151
151
|
* The function counts the number of occurrences of a given value in a linked list.
|
|
152
|
-
* @param {
|
|
152
|
+
* @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
|
|
153
153
|
* @returns The count of occurrences of the given value in the linked list.
|
|
154
154
|
*/
|
|
155
|
-
countOccurrences(value:
|
|
156
|
-
[Symbol.iterator](): Generator<
|
|
155
|
+
countOccurrences(value: E): number;
|
|
156
|
+
[Symbol.iterator](): Generator<E, void, unknown>;
|
|
157
157
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
export class SinglyLinkedListNode {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
11
|
-
* @param {
|
|
11
|
+
* @param {E} val - The "val" parameter is of type E, which means it can be any data type. It represents the value that
|
|
12
12
|
* will be stored in the node of a linked list.
|
|
13
13
|
*/
|
|
14
14
|
constructor(val) {
|
|
@@ -55,7 +55,7 @@ export class SinglyLinkedList {
|
|
|
55
55
|
/**
|
|
56
56
|
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
57
57
|
* array.
|
|
58
|
-
* @param {
|
|
58
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
59
59
|
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
60
60
|
*/
|
|
61
61
|
static fromArray(data) {
|
|
@@ -70,8 +70,8 @@ export class SinglyLinkedList {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* The `push` function adds a new node with the given data to the end of a singly linked list.
|
|
73
|
-
* @param {
|
|
74
|
-
* any type (
|
|
73
|
+
* @param {E} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
|
|
74
|
+
* any type (E) as specified in the generic type declaration of the class or function.
|
|
75
75
|
*/
|
|
76
76
|
push(data) {
|
|
77
77
|
const newNode = new SinglyLinkedListNode(data);
|
|
@@ -125,7 +125,7 @@ export class SinglyLinkedList {
|
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
128
|
-
* @param {
|
|
128
|
+
* @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
|
|
129
129
|
* linked list.
|
|
130
130
|
*/
|
|
131
131
|
unshift(val) {
|
|
@@ -144,7 +144,7 @@ export class SinglyLinkedList {
|
|
|
144
144
|
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
145
145
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
146
146
|
* retrieve from the list.
|
|
147
|
-
* @returns The method `getAt(index: number):
|
|
147
|
+
* @returns The method `getAt(index: number): E | null` returns the value at the specified index in the linked list, or
|
|
148
148
|
* `null` if the index is out of bounds.
|
|
149
149
|
*/
|
|
150
150
|
getAt(index) {
|
|
@@ -160,7 +160,7 @@ export class SinglyLinkedList {
|
|
|
160
160
|
* The function `getNodeAt` returns the node at a given index in a singly linked list.
|
|
161
161
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
162
162
|
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
163
|
-
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<
|
|
163
|
+
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
|
|
164
164
|
* specified index exists, or `null` if the index is out of bounds.
|
|
165
165
|
*/
|
|
166
166
|
getNodeAt(index) {
|
|
@@ -192,8 +192,8 @@ export class SinglyLinkedList {
|
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
194
194
|
* The delete function removes a node with a specific value from a singly linked list.
|
|
195
|
-
* @param {
|
|
196
|
-
* or a `SinglyLinkedListNode<
|
|
195
|
+
* @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
|
|
196
|
+
* or a `SinglyLinkedListNode<E>` object.
|
|
197
197
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
|
|
198
198
|
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
199
199
|
*/
|
|
@@ -232,7 +232,7 @@ export class SinglyLinkedList {
|
|
|
232
232
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
233
233
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
234
234
|
* linked list. It is of type number.
|
|
235
|
-
* @param {
|
|
235
|
+
* @param {E} val - The `val` parameter represents the value that you want to insert into the linked list at the
|
|
236
236
|
* specified index.
|
|
237
237
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
238
238
|
* if the index is out of bounds.
|
|
@@ -273,7 +273,7 @@ export class SinglyLinkedList {
|
|
|
273
273
|
}
|
|
274
274
|
/**
|
|
275
275
|
* The `toArray` function converts a linked list into an array.
|
|
276
|
-
* @returns The `toArray()` method is returning an array of type `
|
|
276
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
277
277
|
*/
|
|
278
278
|
toArray() {
|
|
279
279
|
const array = [];
|
|
@@ -304,7 +304,7 @@ export class SinglyLinkedList {
|
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
306
|
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
307
|
-
* @param callback - A function that takes a value of type
|
|
307
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
308
308
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
309
309
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
310
310
|
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
@@ -321,7 +321,7 @@ export class SinglyLinkedList {
|
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
323
323
|
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
|
|
324
|
-
* @param {
|
|
324
|
+
* @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
|
|
325
325
|
* @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
|
|
326
326
|
* value is not found, it returns -1.
|
|
327
327
|
*/
|
|
@@ -340,8 +340,8 @@ export class SinglyLinkedList {
|
|
|
340
340
|
/**
|
|
341
341
|
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
|
|
342
342
|
* null.
|
|
343
|
-
* @param {
|
|
344
|
-
* @returns a `SinglyLinkedListNode<
|
|
343
|
+
* @param {E} value - The value parameter is the value that we want to search for in the linked list.
|
|
344
|
+
* @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
|
|
345
345
|
* the specified value is found, the function returns `null`.
|
|
346
346
|
*/
|
|
347
347
|
findNode(value) {
|
|
@@ -356,9 +356,9 @@ export class SinglyLinkedList {
|
|
|
356
356
|
}
|
|
357
357
|
/**
|
|
358
358
|
* The `insertBefore` function inserts a new value before an existing value in a singly linked list.
|
|
359
|
-
* @param {
|
|
359
|
+
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
360
360
|
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
361
|
-
* @param {
|
|
361
|
+
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
362
362
|
* @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
363
363
|
* inserted before the existing value, and `false` otherwise.
|
|
364
364
|
*/
|
|
@@ -391,9 +391,9 @@ export class SinglyLinkedList {
|
|
|
391
391
|
}
|
|
392
392
|
/**
|
|
393
393
|
* The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
|
|
394
|
-
* @param {
|
|
394
|
+
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
|
|
395
395
|
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
396
|
-
* @param {
|
|
396
|
+
* @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
|
|
397
397
|
* @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
|
|
398
398
|
* existing value or node, and false if the existing value or node was not found in the linked list.
|
|
399
399
|
*/
|
|
@@ -419,7 +419,7 @@ export class SinglyLinkedList {
|
|
|
419
419
|
}
|
|
420
420
|
/**
|
|
421
421
|
* The function counts the number of occurrences of a given value in a linked list.
|
|
422
|
-
* @param {
|
|
422
|
+
* @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
|
|
423
423
|
* @returns The count of occurrences of the given value in the linked list.
|
|
424
424
|
*/
|
|
425
425
|
countOccurrences(value) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
export declare class MatrixNTI2D<
|
|
8
|
+
export declare class MatrixNTI2D<V = any> {
|
|
9
9
|
private readonly _matrix;
|
|
10
10
|
/**
|
|
11
11
|
* The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
|
|
@@ -15,7 +15,7 @@ export declare class MatrixNTI2D<T = number> {
|
|
|
15
15
|
constructor(options: {
|
|
16
16
|
row: number;
|
|
17
17
|
col: number;
|
|
18
|
-
initialVal?:
|
|
18
|
+
initialVal?: V;
|
|
19
19
|
});
|
|
20
|
-
toArray(): Array<Array<
|
|
20
|
+
toArray(): Array<Array<V>>;
|
|
21
21
|
}
|
|
@@ -37,7 +37,7 @@ export declare class Matrix2D {
|
|
|
37
37
|
* @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
|
|
38
38
|
* the first column of the matrix.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
toVector(): Vector2D;
|
|
41
41
|
/**
|
|
42
42
|
* The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
|
|
43
43
|
* @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
|
|
@@ -59,7 +59,7 @@ export class Matrix2D {
|
|
|
59
59
|
* @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
|
|
60
60
|
* the first column of the matrix.
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
toVector() {
|
|
63
63
|
return new Vector2D(this._matrix[0][0], this._matrix[1][0]);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
@@ -134,7 +134,8 @@ export class Matrix2D {
|
|
|
134
134
|
* @returns a Vector2D.
|
|
135
135
|
*/
|
|
136
136
|
static multiplyByVector(matrix, vector) {
|
|
137
|
-
|
|
137
|
+
const resultMatrix = Matrix2D.multiply(matrix, new Matrix2D(vector));
|
|
138
|
+
return resultMatrix.toVector();
|
|
138
139
|
}
|
|
139
140
|
/**
|
|
140
141
|
* The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { PriorityQueue } from './priority-queue';
|
|
9
9
|
import type { PriorityQueueOptions } from '../../types';
|
|
10
|
-
export declare class MaxPriorityQueue<
|
|
10
|
+
export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
11
11
|
constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
|
|
12
|
-
constructor(options: PriorityQueueOptions<
|
|
13
|
-
static heapify<
|
|
14
|
-
static heapify<
|
|
12
|
+
constructor(options: PriorityQueueOptions<E>);
|
|
13
|
+
static heapify<E extends number>(options?: Omit<PriorityQueueOptions<E>, 'comparator'>): MaxPriorityQueue<E>;
|
|
14
|
+
static heapify<E>(options: PriorityQueueOptions<E>): MaxPriorityQueue<E>;
|
|
15
15
|
}
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { PriorityQueue } from './priority-queue';
|
|
9
9
|
import type { PriorityQueueOptions } from '../../types';
|
|
10
|
-
export declare class MinPriorityQueue<
|
|
10
|
+
export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
11
11
|
constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
|
|
12
|
-
constructor(options: PriorityQueueOptions<
|
|
13
|
-
static heapify<
|
|
14
|
-
static heapify<
|
|
12
|
+
constructor(options: PriorityQueueOptions<E>);
|
|
13
|
+
static heapify<E extends number>(options?: Omit<PriorityQueueOptions<E>, 'comparator'>): MinPriorityQueue<E>;
|
|
14
|
+
static heapify<E>(options: PriorityQueueOptions<E>): MinPriorityQueue<E>;
|
|
15
15
|
}
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions } from '../../types';
|
|
9
|
-
export declare class PriorityQueue<
|
|
9
|
+
export declare class PriorityQueue<E = any> {
|
|
10
10
|
/**
|
|
11
11
|
* The constructor initializes a priority queue with the given options, including an array of nodes and a comparator
|
|
12
12
|
* function.
|
|
13
13
|
* @param options - The `options` parameter is an object that contains the following properties:
|
|
14
14
|
*/
|
|
15
|
-
constructor(options: PriorityQueueOptions<
|
|
16
|
-
protected _nodes:
|
|
17
|
-
get nodes():
|
|
15
|
+
constructor(options: PriorityQueueOptions<E>);
|
|
16
|
+
protected _nodes: E[];
|
|
17
|
+
get nodes(): E[];
|
|
18
18
|
get size(): number;
|
|
19
19
|
/**
|
|
20
20
|
* The `heapify` function creates a new PriorityQueue instance and fixes the heap property.
|
|
@@ -23,7 +23,7 @@ export declare class PriorityQueue<T = number> {
|
|
|
23
23
|
* the priority queue, and "initialValues" which is an array of initial values to be added to the priority
|
|
24
24
|
* @returns a new instance of the PriorityQueue class after performing the heapify operation on it.
|
|
25
25
|
*/
|
|
26
|
-
static heapify<
|
|
26
|
+
static heapify<E>(options: PriorityQueueOptions<E>): PriorityQueue<E>;
|
|
27
27
|
/**
|
|
28
28
|
* The function checks if a priority queue is valid by creating a new priority queue with a fix option and then calling
|
|
29
29
|
* the isValid method.
|
|
@@ -31,41 +31,41 @@ export declare class PriorityQueue<T = number> {
|
|
|
31
31
|
* following properties:
|
|
32
32
|
* @returns the result of calling the `isValid()` method on a new instance of the `PriorityQueue` class.
|
|
33
33
|
*/
|
|
34
|
-
static isPriorityQueueified<
|
|
34
|
+
static isPriorityQueueified<E>(options: Omit<PriorityQueueOptions<E>, 'isFix'>): boolean;
|
|
35
35
|
/**
|
|
36
36
|
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
37
37
|
*/
|
|
38
|
-
getNodes():
|
|
38
|
+
getNodes(): E[];
|
|
39
39
|
/**
|
|
40
40
|
* The "add" function adds a node to the heap and ensures that the heap property is maintained.
|
|
41
|
-
* @param {
|
|
41
|
+
* @param {E} node - The parameter "node" is of type E, which means it can be any data type. It represents the node
|
|
42
42
|
* that needs to be added to the heap.
|
|
43
43
|
*/
|
|
44
|
-
add(node:
|
|
44
|
+
add(node: E): void;
|
|
45
45
|
/**
|
|
46
46
|
* The "has" function checks if a given node is present in the list of nodes.
|
|
47
|
-
* @param {
|
|
47
|
+
* @param {E} node - The parameter `node` is of type `E`, which means it can be any type. It represents the node that
|
|
48
48
|
* we want to check if it exists in the `nodes` array.
|
|
49
49
|
* @returns a boolean value indicating whether the given node is included in the array of nodes.
|
|
50
50
|
*/
|
|
51
|
-
has(node:
|
|
51
|
+
has(node: E): boolean;
|
|
52
52
|
/**
|
|
53
53
|
* The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
|
|
54
|
-
* @returns The `peek()` function is returning the first element (`
|
|
54
|
+
* @returns The `peek()` function is returning the first element (`E`) of the `nodes` array if the `size` is not zero.
|
|
55
55
|
* Otherwise, it returns `null`.
|
|
56
56
|
*/
|
|
57
|
-
peek():
|
|
57
|
+
peek(): E | null;
|
|
58
58
|
/**
|
|
59
59
|
* The `poll` function removes and returns the top element from a heap data structure.
|
|
60
|
-
* @returns The `poll()` method returns a value of type `
|
|
60
|
+
* @returns The `poll()` method returns a value of type `E` or `null`.
|
|
61
61
|
*/
|
|
62
|
-
poll():
|
|
62
|
+
poll(): E | null;
|
|
63
63
|
/**
|
|
64
64
|
* The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.
|
|
65
|
-
* @returns The method `leaf()` is returning the last element (`
|
|
65
|
+
* @returns The method `leaf()` is returning the last element (`E`) in the `nodes` array if it exists. If the array is
|
|
66
66
|
* empty or the last element is `null`, then it returns `null`.
|
|
67
67
|
*/
|
|
68
|
-
leaf():
|
|
68
|
+
leaf(): E | null;
|
|
69
69
|
/**
|
|
70
70
|
* The function checks if the size of an object is equal to zero and returns a boolean value indicating whether the
|
|
71
71
|
* object is empty or not.
|
|
@@ -79,16 +79,16 @@ export declare class PriorityQueue<T = number> {
|
|
|
79
79
|
clear(): void;
|
|
80
80
|
/**
|
|
81
81
|
* The toArray function returns an array containing all the elements in the nodes property.
|
|
82
|
-
* @returns An array of type
|
|
82
|
+
* @returns An array of type E, which is the elements of the nodes property.
|
|
83
83
|
*/
|
|
84
|
-
toArray():
|
|
84
|
+
toArray(): E[];
|
|
85
85
|
/**
|
|
86
86
|
* The `clone` function returns a new instance of the `PriorityQueue` class with the same nodes and comparator as the
|
|
87
87
|
* original instance.
|
|
88
88
|
* @returns The `clone()` method is returning a new instance of the `PriorityQueue` class with the same `nodes` and
|
|
89
89
|
* `comparator` properties as the original instance.
|
|
90
90
|
*/
|
|
91
|
-
clone(): PriorityQueue<
|
|
91
|
+
clone(): PriorityQueue<E>;
|
|
92
92
|
/**
|
|
93
93
|
* The `isValid` function recursively checks if a binary tree satisfies a certain condition.
|
|
94
94
|
* @returns The function `isValid()` returns a boolean value.
|
|
@@ -100,19 +100,19 @@ export declare class PriorityQueue<T = number> {
|
|
|
100
100
|
/**
|
|
101
101
|
* The function sorts the elements in a data structure and returns them in an array.
|
|
102
102
|
* Plan to support sorting of duplicate elements.
|
|
103
|
-
* @returns The `sort()` method is returning an array of type `
|
|
103
|
+
* @returns The `sort()` method is returning an array of type `E[]`.
|
|
104
104
|
*/
|
|
105
|
-
sort():
|
|
105
|
+
sort(): E[];
|
|
106
106
|
/**
|
|
107
107
|
* The DFS function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
|
|
108
108
|
* based on the specified traversal order.
|
|
109
109
|
* @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
|
|
110
110
|
* the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:
|
|
111
|
-
* @returns an array of type `(
|
|
111
|
+
* @returns an array of type `(E | null)[]`.
|
|
112
112
|
*/
|
|
113
|
-
DFS(dfsMode: PriorityQueueDFSOrderPattern): (
|
|
114
|
-
protected _setNodes(value:
|
|
115
|
-
protected readonly _comparator: PriorityQueueComparator<
|
|
113
|
+
DFS(dfsMode: PriorityQueueDFSOrderPattern): (E | null)[];
|
|
114
|
+
protected _setNodes(value: E[]): void;
|
|
115
|
+
protected readonly _comparator: PriorityQueueComparator<E>;
|
|
116
116
|
/**
|
|
117
117
|
* The function compares two numbers using a custom comparator function.
|
|
118
118
|
* @param {number} a - The parameter "a" is a number that represents the index of a node in an array.
|
|
@@ -54,7 +54,7 @@ export class PriorityQueue {
|
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* The "add" function adds a node to the heap and ensures that the heap property is maintained.
|
|
57
|
-
* @param {
|
|
57
|
+
* @param {E} node - The parameter "node" is of type E, which means it can be any data type. It represents the node
|
|
58
58
|
* that needs to be added to the heap.
|
|
59
59
|
*/
|
|
60
60
|
add(node) {
|
|
@@ -63,7 +63,7 @@ export class PriorityQueue {
|
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* The "has" function checks if a given node is present in the list of nodes.
|
|
66
|
-
* @param {
|
|
66
|
+
* @param {E} node - The parameter `node` is of type `E`, which means it can be any type. It represents the node that
|
|
67
67
|
* we want to check if it exists in the `nodes` array.
|
|
68
68
|
* @returns a boolean value indicating whether the given node is included in the array of nodes.
|
|
69
69
|
*/
|
|
@@ -72,7 +72,7 @@ export class PriorityQueue {
|
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
|
|
75
|
-
* @returns The `peek()` function is returning the first element (`
|
|
75
|
+
* @returns The `peek()` function is returning the first element (`E`) of the `nodes` array if the `size` is not zero.
|
|
76
76
|
* Otherwise, it returns `null`.
|
|
77
77
|
*/
|
|
78
78
|
peek() {
|
|
@@ -80,7 +80,7 @@ export class PriorityQueue {
|
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* The `poll` function removes and returns the top element from a heap data structure.
|
|
83
|
-
* @returns The `poll()` method returns a value of type `
|
|
83
|
+
* @returns The `poll()` method returns a value of type `E` or `null`.
|
|
84
84
|
*/
|
|
85
85
|
poll() {
|
|
86
86
|
var _a, _b;
|
|
@@ -97,7 +97,7 @@ export class PriorityQueue {
|
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.
|
|
100
|
-
* @returns The method `leaf()` is returning the last element (`
|
|
100
|
+
* @returns The method `leaf()` is returning the last element (`E`) in the `nodes` array if it exists. If the array is
|
|
101
101
|
* empty or the last element is `null`, then it returns `null`.
|
|
102
102
|
*/
|
|
103
103
|
leaf() {
|
|
@@ -121,7 +121,7 @@ export class PriorityQueue {
|
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* The toArray function returns an array containing all the elements in the nodes property.
|
|
124
|
-
* @returns An array of type
|
|
124
|
+
* @returns An array of type E, which is the elements of the nodes property.
|
|
125
125
|
*/
|
|
126
126
|
toArray() {
|
|
127
127
|
return [...this.nodes];
|
|
@@ -162,7 +162,7 @@ export class PriorityQueue {
|
|
|
162
162
|
/**
|
|
163
163
|
* The function sorts the elements in a data structure and returns them in an array.
|
|
164
164
|
* Plan to support sorting of duplicate elements.
|
|
165
|
-
* @returns The `sort()` method is returning an array of type `
|
|
165
|
+
* @returns The `sort()` method is returning an array of type `E[]`.
|
|
166
166
|
*/
|
|
167
167
|
sort() {
|
|
168
168
|
const visitedNode = [];
|
|
@@ -178,7 +178,7 @@ export class PriorityQueue {
|
|
|
178
178
|
* based on the specified traversal order.
|
|
179
179
|
* @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
|
|
180
180
|
* the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:
|
|
181
|
-
* @returns an array of type `(
|
|
181
|
+
* @returns an array of type `(E | null)[]`.
|
|
182
182
|
*/
|
|
183
183
|
DFS(dfsMode) {
|
|
184
184
|
const visitedNode = [];
|