data-structure-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/CHANGELOG.md +6 -1
- package/dist/cjs/data-structures/hash/hash-map.js +2 -4
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +4 -4
- package/dist/cjs/data-structures/queue/queue.js +4 -4
- package/dist/cjs/data-structures/trie/trie.js +6 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.js +2 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +4 -4
- package/dist/mjs/data-structures/queue/queue.js +4 -4
- package/dist/mjs/data-structures/trie/trie.js +6 -1
- package/dist/umd/data-structure-typed.js +10 -9
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- 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
- package/test/unit/data-structures/trie/trie.test.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.4",
|
|
4
4
|
"description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
67
67
|
"@typescript-eslint/parser": "^6.7.4",
|
|
68
68
|
"auto-changelog": "^2.4.0",
|
|
69
|
-
"avl-tree-typed": "^1.52.
|
|
69
|
+
"avl-tree-typed": "^1.52.3",
|
|
70
70
|
"benchmark": "^2.1.4",
|
|
71
|
-
"binary-tree-typed": "^1.52.
|
|
72
|
-
"bst-typed": "^1.52.
|
|
73
|
-
"data-structure-typed": "^1.52.
|
|
71
|
+
"binary-tree-typed": "^1.52.3",
|
|
72
|
+
"bst-typed": "^1.52.3",
|
|
73
|
+
"data-structure-typed": "^1.52.3",
|
|
74
74
|
"dependency-cruiser": "^14.1.0",
|
|
75
75
|
"doctoc": "^2.2.1",
|
|
76
76
|
"eslint": "^8.50.0",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
80
80
|
"eslint-plugin-import": "^2.28.1",
|
|
81
81
|
"fast-glob": "^3.3.1",
|
|
82
|
-
"heap-typed": "^1.52.
|
|
82
|
+
"heap-typed": "^1.52.3",
|
|
83
83
|
"istanbul-badges-readme": "^1.8.5",
|
|
84
84
|
"jest": "^29.7.0",
|
|
85
85
|
"js-sdsl": "^4.4.2",
|
|
@@ -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
|
|
|
@@ -836,6 +836,22 @@ describe('Trie operations', () => {
|
|
|
836
836
|
expect(words).toEqual(['apple', 'appetizer']);
|
|
837
837
|
});
|
|
838
838
|
|
|
839
|
+
it('Get no words when prefix not found, with no match from the first character', () => {
|
|
840
|
+
trie.add('apple');
|
|
841
|
+
trie.add('appetizer');
|
|
842
|
+
trie.add('banana');
|
|
843
|
+
const words = trie.getWords('cd');
|
|
844
|
+
expect(words).toEqual([]);
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
it('Get no words when prefix not found, with no match from the second character', () => {
|
|
848
|
+
trie.add('apple');
|
|
849
|
+
trie.add('appetizer');
|
|
850
|
+
trie.add('banana');
|
|
851
|
+
const words = trie.getWords('ab');
|
|
852
|
+
expect(words).toEqual([]);
|
|
853
|
+
});
|
|
854
|
+
|
|
839
855
|
it('Tree Height', () => {
|
|
840
856
|
trie.add('apple');
|
|
841
857
|
trie.add('banana');
|