data-structure-typed 1.52.4 → 1.52.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/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/README_zh-CN.md +216 -26
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +158 -158
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/cjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/cjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/cjs/data-structures/hash/hash-map.js +27 -111
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/cjs/data-structures/heap/heap.js +0 -32
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/cjs/data-structures/queue/deque.js +3 -99
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -54
- package/dist/cjs/data-structures/queue/queue.js +0 -53
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/cjs/data-structures/stack/stack.js +1 -34
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.js +0 -1
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/cjs/data-structures/trie/trie.js +0 -64
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/utils/utils.d.ts +13 -12
- package/dist/cjs/utils/number.d.ts +13 -0
- package/dist/cjs/utils/number.js +13 -0
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +125 -3
- package/dist/cjs/utils/utils.js +177 -21
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/mjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/mjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +298 -332
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/mjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/mjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/mjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/mjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/mjs/data-structures/hash/hash-map.js +27 -111
- package/dist/mjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/mjs/data-structures/heap/heap.js +0 -32
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/mjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/mjs/data-structures/queue/deque.js +3 -99
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -54
- package/dist/mjs/data-structures/queue/queue.js +0 -53
- package/dist/mjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/mjs/data-structures/stack/stack.js +1 -34
- package/dist/mjs/data-structures/tree/tree.js +0 -1
- package/dist/mjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/mjs/data-structures/trie/trie.js +0 -64
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +5 -1
- package/dist/mjs/types/utils/utils.d.ts +13 -12
- package/dist/mjs/utils/number.d.ts +13 -0
- package/dist/mjs/utils/number.js +13 -0
- package/dist/mjs/utils/utils.d.ts +125 -3
- package/dist/mjs/utils/utils.js +177 -21
- package/dist/umd/data-structure-typed.js +408 -1474
- package/dist/umd/data-structure-typed.min.js +5 -4
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
- package/test/config.ts +8 -0
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +13 -13
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +18 -13
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +471 -64
- package/test/unit/data-structures/binary-tree/bst.test.ts +167 -23
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +136 -13
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +18 -13
- package/test/unit/data-structures/graph/directed-graph.test.ts +46 -32
- package/test/unit/data-structures/graph/map-graph.test.ts +24 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +24 -24
- package/test/unit/data-structures/hash/hash-map.test.ts +225 -35
- package/test/unit/data-structures/heap/heap.test.ts +47 -39
- package/test/unit/data-structures/heap/min-heap.test.ts +5 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +34 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +32 -0
- package/test/unit/data-structures/matrix/matrix.test.ts +35 -5
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +31 -0
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +18 -0
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +17 -0
- package/test/unit/data-structures/queue/deque.test.ts +288 -47
- package/test/unit/data-structures/queue/queue.test.ts +62 -37
- package/test/unit/data-structures/stack/stack.test.ts +30 -5
- package/test/unit/data-structures/tree/tree.test.ts +58 -0
- package/test/unit/data-structures/trie/trie.test.ts +46 -5
- package/test/unit/utils/utils.test.ts +169 -0
|
@@ -17,10 +17,10 @@ describe('AVL Tree Test', () => {
|
|
|
17
17
|
expect(getNodeById?.key).toBe(10);
|
|
18
18
|
|
|
19
19
|
const getMinNodeByRoot = tree.getLeftMost();
|
|
20
|
-
expect(getMinNodeByRoot
|
|
20
|
+
expect(getMinNodeByRoot).toBe(1);
|
|
21
21
|
|
|
22
22
|
const node15 = tree.getNode(15);
|
|
23
|
-
const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node15);
|
|
23
|
+
const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node => node, node15);
|
|
24
24
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
25
25
|
|
|
26
26
|
let subTreeSum = 0;
|
|
@@ -125,10 +125,10 @@ describe('AVL Tree Test recursively', () => {
|
|
|
125
125
|
expect(getNodeById?.key).toBe(10);
|
|
126
126
|
|
|
127
127
|
const getMinNodeByRoot = tree.getLeftMost();
|
|
128
|
-
expect(getMinNodeByRoot
|
|
128
|
+
expect(getMinNodeByRoot).toBe(1);
|
|
129
129
|
|
|
130
130
|
const node15 = tree.getNode(15);
|
|
131
|
-
const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node15);
|
|
131
|
+
const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node => node, node15);
|
|
132
132
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
133
133
|
|
|
134
134
|
let subTreeSum = 0;
|
|
@@ -339,14 +339,14 @@ describe('AVLTree iterative methods test', () => {
|
|
|
339
339
|
avl.add([3, 'c']);
|
|
340
340
|
});
|
|
341
341
|
|
|
342
|
-
|
|
342
|
+
it('The node obtained by get Node should match the node type', () => {
|
|
343
343
|
const node3 = avl.getNode(3);
|
|
344
344
|
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
345
345
|
expect(node3).toBeInstanceOf(BSTNode);
|
|
346
346
|
expect(node3).toBeInstanceOf(AVLTreeNode);
|
|
347
347
|
});
|
|
348
348
|
|
|
349
|
-
|
|
349
|
+
it('forEach should iterate over all elements', () => {
|
|
350
350
|
const mockCallback = jest.fn();
|
|
351
351
|
avl.forEach((value, key) => {
|
|
352
352
|
mockCallback(value, key);
|
|
@@ -358,7 +358,7 @@ describe('AVLTree iterative methods test', () => {
|
|
|
358
358
|
expect(mockCallback.mock.calls[2]).toEqual(['c', 3]);
|
|
359
359
|
});
|
|
360
360
|
|
|
361
|
-
|
|
361
|
+
it('filter should return a new tree with filtered elements', () => {
|
|
362
362
|
const filteredTree = avl.filter((value, key) => key > 1);
|
|
363
363
|
expect(filteredTree.size).toBe(2);
|
|
364
364
|
expect([...filteredTree]).toEqual([
|
|
@@ -367,7 +367,7 @@ describe('AVLTree iterative methods test', () => {
|
|
|
367
367
|
]);
|
|
368
368
|
});
|
|
369
369
|
|
|
370
|
-
|
|
370
|
+
it('map should return a new tree with modified elements', () => {
|
|
371
371
|
const mappedTree = avl.map((value, key) => (key * 2).toString());
|
|
372
372
|
expect(mappedTree.size).toBe(3);
|
|
373
373
|
expect([...mappedTree]).toEqual([
|
|
@@ -377,12 +377,12 @@ describe('AVLTree iterative methods test', () => {
|
|
|
377
377
|
]);
|
|
378
378
|
});
|
|
379
379
|
|
|
380
|
-
|
|
380
|
+
it('reduce should accumulate values', () => {
|
|
381
381
|
const sum = avl.reduce((acc, value, key) => acc + key, 0);
|
|
382
382
|
expect(sum).toBe(6);
|
|
383
383
|
});
|
|
384
384
|
|
|
385
|
-
|
|
385
|
+
it('[Symbol.iterator] should provide an iterator', () => {
|
|
386
386
|
const entries = [];
|
|
387
387
|
for (const entry of avl) {
|
|
388
388
|
entries.push(entry);
|
|
@@ -396,19 +396,24 @@ describe('AVLTree iterative methods test', () => {
|
|
|
396
396
|
]);
|
|
397
397
|
});
|
|
398
398
|
|
|
399
|
-
|
|
399
|
+
it('should clone work well', () => {
|
|
400
400
|
const cloned = avl.clone();
|
|
401
401
|
expect(cloned.root?.left?.key).toBe(1);
|
|
402
402
|
expect(cloned.root?.right?.value).toBe('c');
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
-
|
|
405
|
+
it('should keys', () => {
|
|
406
406
|
const keys = avl.keys();
|
|
407
407
|
expect([...keys]).toEqual([1, 2, 3]);
|
|
408
408
|
});
|
|
409
409
|
|
|
410
|
-
|
|
410
|
+
it('should values', () => {
|
|
411
411
|
const values = avl.values();
|
|
412
412
|
expect([...values]).toEqual(['a', 'b', 'c']);
|
|
413
413
|
});
|
|
414
|
+
|
|
415
|
+
it('should leaves', () => {
|
|
416
|
+
const leaves = avl.leaves();
|
|
417
|
+
expect(leaves).toEqual([1, 3]);
|
|
418
|
+
});
|
|
414
419
|
});
|