directed-graph-typed 1.52.2 → 1.52.4
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/dist/data-structures/hash/hash-map.js +2 -4
- package/dist/data-structures/queue/queue.d.ts +4 -4
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/data-structures/trie/trie.js +6 -1
- package/package.json +2 -2
- package/src/data-structures/hash/hash-map.ts +2 -6
- package/src/data-structures/queue/queue.ts +4 -4
- package/src/data-structures/trie/trie.ts +6 -1
|
@@ -26,12 +26,10 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
26
26
|
this._hashFn = (key) => String(key);
|
|
27
27
|
if (options) {
|
|
28
28
|
const { hashFn, toEntryFn } = options;
|
|
29
|
-
if (hashFn)
|
|
29
|
+
if (hashFn)
|
|
30
30
|
this._hashFn = hashFn;
|
|
31
|
-
|
|
32
|
-
if (toEntryFn) {
|
|
31
|
+
if (toEntryFn)
|
|
33
32
|
this._toEntryFn = toEntryFn;
|
|
34
|
-
}
|
|
35
33
|
}
|
|
36
34
|
if (entryOrRawElements) {
|
|
37
35
|
this.setMany(entryOrRawElements);
|
|
@@ -95,9 +95,9 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
|
|
|
95
95
|
* Time Complexity: O(1)
|
|
96
96
|
* Space Complexity: O(1)
|
|
97
97
|
*
|
|
98
|
-
* The push function adds an element to the end of the queue and returns
|
|
98
|
+
* The push function adds an element to the end of the queue and returns true. Adds an element at the back of the queue.
|
|
99
99
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
100
|
-
* @returns
|
|
100
|
+
* @returns Always returns true, indicating the element was successfully added.
|
|
101
101
|
*/
|
|
102
102
|
push(element: E): boolean;
|
|
103
103
|
/**
|
|
@@ -115,13 +115,13 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
|
|
|
115
115
|
shift(): E | undefined;
|
|
116
116
|
/**
|
|
117
117
|
* The delete function removes an element from the list.
|
|
118
|
-
* @param element
|
|
118
|
+
* @param {E} element - Specify the element to be deleted
|
|
119
119
|
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
120
120
|
*/
|
|
121
121
|
delete(element: E): boolean;
|
|
122
122
|
/**
|
|
123
123
|
* The deleteAt function deletes the element at a given index.
|
|
124
|
-
* @param index
|
|
124
|
+
* @param {number} index - Determine the index of the element to be deleted
|
|
125
125
|
* @return A boolean value
|
|
126
126
|
*/
|
|
127
127
|
deleteAt(index: number): boolean;
|
|
@@ -122,9 +122,9 @@ class Queue extends base_1.IterableElementBase {
|
|
|
122
122
|
* Time Complexity: O(1)
|
|
123
123
|
* Space Complexity: O(1)
|
|
124
124
|
*
|
|
125
|
-
* The push function adds an element to the end of the queue and returns
|
|
125
|
+
* The push function adds an element to the end of the queue and returns true. Adds an element at the back of the queue.
|
|
126
126
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
127
|
-
* @returns
|
|
127
|
+
* @returns Always returns true, indicating the element was successfully added.
|
|
128
128
|
*/
|
|
129
129
|
push(element) {
|
|
130
130
|
this.elements.push(element);
|
|
@@ -153,7 +153,7 @@ class Queue extends base_1.IterableElementBase {
|
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* The delete function removes an element from the list.
|
|
156
|
-
* @param element
|
|
156
|
+
* @param {E} element - Specify the element to be deleted
|
|
157
157
|
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
158
158
|
*/
|
|
159
159
|
delete(element) {
|
|
@@ -162,7 +162,7 @@ class Queue extends base_1.IterableElementBase {
|
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* The deleteAt function deletes the element at a given index.
|
|
165
|
-
* @param index
|
|
165
|
+
* @param {number} index - Determine the index of the element to be deleted
|
|
166
166
|
* @return A boolean value
|
|
167
167
|
*/
|
|
168
168
|
deleteAt(index) {
|
|
@@ -418,8 +418,13 @@ class Trie extends base_1.IterableElementBase {
|
|
|
418
418
|
if (prefix) {
|
|
419
419
|
for (const c of prefix) {
|
|
420
420
|
const nodeC = startNode.children.get(c);
|
|
421
|
-
if (nodeC)
|
|
421
|
+
if (nodeC) {
|
|
422
422
|
startNode = nodeC;
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
// Early return if the whole prefix is not found
|
|
426
|
+
return [];
|
|
427
|
+
}
|
|
423
428
|
}
|
|
424
429
|
}
|
|
425
430
|
if (isAllWhenEmptyPrefix || startNode !== this.root)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directed-graph-typed",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.4",
|
|
4
4
|
"description": "Directed Graph. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -147,6 +147,6 @@
|
|
|
147
147
|
"typescript": "^4.9.5"
|
|
148
148
|
},
|
|
149
149
|
"dependencies": {
|
|
150
|
-
"data-structure-typed": "^1.52.
|
|
150
|
+
"data-structure-typed": "^1.52.4"
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -34,12 +34,8 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
34
34
|
super();
|
|
35
35
|
if (options) {
|
|
36
36
|
const { hashFn, toEntryFn } = options;
|
|
37
|
-
if (hashFn)
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (toEntryFn) {
|
|
41
|
-
this._toEntryFn = toEntryFn;
|
|
42
|
-
}
|
|
37
|
+
if (hashFn) this._hashFn = hashFn;
|
|
38
|
+
if (toEntryFn) this._toEntryFn = toEntryFn;
|
|
43
39
|
}
|
|
44
40
|
if (entryOrRawElements) {
|
|
45
41
|
this.setMany(entryOrRawElements);
|
|
@@ -142,9 +142,9 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
142
142
|
* Time Complexity: O(1)
|
|
143
143
|
* Space Complexity: O(1)
|
|
144
144
|
*
|
|
145
|
-
* The push function adds an element to the end of the queue and returns
|
|
145
|
+
* The push function adds an element to the end of the queue and returns true. Adds an element at the back of the queue.
|
|
146
146
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
147
|
-
* @returns
|
|
147
|
+
* @returns Always returns true, indicating the element was successfully added.
|
|
148
148
|
*/
|
|
149
149
|
push(element: E): boolean {
|
|
150
150
|
this.elements.push(element);
|
|
@@ -176,7 +176,7 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
178
|
* The delete function removes an element from the list.
|
|
179
|
-
* @param element
|
|
179
|
+
* @param {E} element - Specify the element to be deleted
|
|
180
180
|
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
181
181
|
*/
|
|
182
182
|
delete(element: E): boolean {
|
|
@@ -186,7 +186,7 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
188
|
* The deleteAt function deletes the element at a given index.
|
|
189
|
-
* @param index
|
|
189
|
+
* @param {number} index - Determine the index of the element to be deleted
|
|
190
190
|
* @return A boolean value
|
|
191
191
|
*/
|
|
192
192
|
deleteAt(index: number): boolean {
|
|
@@ -454,7 +454,12 @@ export class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
|
|
|
454
454
|
if (prefix) {
|
|
455
455
|
for (const c of prefix) {
|
|
456
456
|
const nodeC = startNode.children.get(c);
|
|
457
|
-
if (nodeC)
|
|
457
|
+
if (nodeC) {
|
|
458
|
+
startNode = nodeC;
|
|
459
|
+
} else {
|
|
460
|
+
// Early return if the whole prefix is not found
|
|
461
|
+
return [];
|
|
462
|
+
}
|
|
458
463
|
}
|
|
459
464
|
}
|
|
460
465
|
|