data-structure-typed 1.52.2 → 1.52.3
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 +5 -1
- 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/trie/trie.js +6 -1
- package/dist/umd/data-structure-typed.js +4 -1
- 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/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.3",
|
|
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.2",
|
|
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.2",
|
|
72
|
+
"bst-typed": "^1.52.2",
|
|
73
|
+
"data-structure-typed": "^1.52.2",
|
|
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.2",
|
|
83
83
|
"istanbul-badges-readme": "^1.8.5",
|
|
84
84
|
"jest": "^29.7.0",
|
|
85
85
|
"js-sdsl": "^4.4.2",
|
|
@@ -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');
|