data-structure-typed 1.38.8 → 1.39.0
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 +9 -9
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +3 -3
- package/dist/cjs/data-structures/graph/abstract-graph.js +4 -4
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +4 -4
- package/dist/cjs/data-structures/graph/directed-graph.js +6 -6
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -3
- package/dist/cjs/data-structures/graph/undirected-graph.js +4 -4
- package/dist/cjs/data-structures/heap/heap.d.ts +10 -5
- package/dist/cjs/data-structures/heap/heap.js +10 -10
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +4 -1
- package/dist/cjs/data-structures/heap/max-heap.js +9 -7
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +4 -1
- package/dist/cjs/data-structures/heap/min-heap.js +9 -7
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +9 -7
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +9 -7
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +2 -1
- package/dist/cjs/data-structures/trie/trie.js +3 -2
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +3 -3
- package/dist/mjs/data-structures/graph/abstract-graph.js +4 -4
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +4 -4
- package/dist/mjs/data-structures/graph/directed-graph.js +6 -6
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +3 -3
- package/dist/mjs/data-structures/graph/undirected-graph.js +4 -4
- package/dist/mjs/data-structures/heap/heap.d.ts +10 -5
- package/dist/mjs/data-structures/heap/heap.js +10 -10
- package/dist/mjs/data-structures/heap/max-heap.d.ts +4 -1
- package/dist/mjs/data-structures/heap/max-heap.js +9 -7
- package/dist/mjs/data-structures/heap/min-heap.d.ts +4 -1
- package/dist/mjs/data-structures/heap/min-heap.js +9 -7
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +9 -7
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +9 -7
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/mjs/data-structures/trie/trie.d.ts +2 -1
- package/dist/mjs/data-structures/trie/trie.js +3 -2
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +20 -0
- package/src/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/data-structures/binary-tree/bst.ts +3 -1
- package/src/data-structures/binary-tree/rb-tree.ts +3 -1
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +6 -6
- package/src/data-structures/graph/undirected-graph.ts +4 -4
- package/src/data-structures/heap/heap.ts +12 -12
- package/src/data-structures/heap/max-heap.ts +8 -6
- package/src/data-structures/heap/min-heap.ts +8 -6
- package/src/data-structures/priority-queue/max-priority-queue.ts +8 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +8 -6
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/trie/trie.ts +4 -2
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +35 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +8 -5
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/overall.test.ts +18 -18
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +3 -3
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +2 -2
- package/test/unit/data-structures/heap/max-heap.test.ts +1 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +3 -3
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +10 -10
|
@@ -17,7 +17,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
|
|
20
|
-
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>((a, b) => b.keyA - a.keyA);
|
|
20
|
+
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({comparator: (a, b) => b.keyA - a.keyA});
|
|
21
21
|
priorityQueue.refill([{keyA: 5}, {keyA: 3}, {keyA: 1}]);
|
|
22
22
|
priorityQueue.add({keyA: 7});
|
|
23
23
|
|
|
@@ -53,7 +53,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
53
53
|
|
|
54
54
|
it('should correctly heapify an array', () => {
|
|
55
55
|
const array = [5, 3, 7, 1];
|
|
56
|
-
const heap = MaxPriorityQueue.heapify<number>(array, (a, b) => b - a);
|
|
56
|
+
const heap = MaxPriorityQueue.heapify<number>({nodes: array, comparator: (a, b) => b - a});
|
|
57
57
|
heap.refill(array);
|
|
58
58
|
|
|
59
59
|
expect(heap.poll()).toBe(7);
|
|
@@ -64,7 +64,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
64
64
|
|
|
65
65
|
it('should correctly heapify an object array', () => {
|
|
66
66
|
const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}];
|
|
67
|
-
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>(nodes, (a, b) => b.keyA - a.keyA);
|
|
67
|
+
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA});
|
|
68
68
|
|
|
69
69
|
expect(maxPQ.poll()?.keyA).toBe(7);
|
|
70
70
|
expect(maxPQ.poll()?.keyA).toBe(5);
|
|
@@ -3,7 +3,7 @@ import {getRandomInt} from '../../../utils';
|
|
|
3
3
|
|
|
4
4
|
describe('PriorityQueue Operation Test', () => {
|
|
5
5
|
it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
|
|
6
|
-
const minPQ = new PriorityQueue<number>((a, b) => a - b);
|
|
6
|
+
const minPQ = new PriorityQueue<number>({comparator: (a, b) => a - b});
|
|
7
7
|
minPQ.refill([5, 2, 3, 4, 6, 1]);
|
|
8
8
|
expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]);
|
|
9
9
|
minPQ.poll();
|
|
@@ -11,13 +11,13 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
11
11
|
minPQ.poll();
|
|
12
12
|
expect(minPQ.toArray()).toEqual([4, 5, 6]);
|
|
13
13
|
expect(minPQ.peek()).toBe(4);
|
|
14
|
-
expect(PriorityQueue.heapify([3, 2, 1, 5, 6, 7, 8, 9, 10], (a, b) => a - b).toArray()).toEqual(
|
|
15
|
-
1, 2, 3, 5, 6, 7, 8, 9, 10
|
|
16
|
-
|
|
14
|
+
expect(PriorityQueue.heapify({nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10], comparator: (a, b) => a - b}).toArray()).toEqual(
|
|
15
|
+
[1, 2, 3, 5, 6, 7, 8, 9, 10]
|
|
16
|
+
);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
|
|
20
|
-
const maxPriorityQueue = new PriorityQueue<number>((a, b) => b - a);
|
|
20
|
+
const maxPriorityQueue = new PriorityQueue<number>({comparator: (a, b) => b - a});
|
|
21
21
|
maxPriorityQueue.refill([5, 2, 3, 4, 6, 1]);
|
|
22
22
|
expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
|
|
23
23
|
maxPriorityQueue.poll();
|
|
@@ -25,13 +25,13 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
25
25
|
maxPriorityQueue.poll();
|
|
26
26
|
expect(maxPriorityQueue.toArray()).toEqual([3, 2, 1]);
|
|
27
27
|
expect(maxPriorityQueue.peek()).toBe(3);
|
|
28
|
-
expect(PriorityQueue.heapify([3, 2, 1, 5, 6, 7, 8, 9, 10], (a, b) => a - b).toArray()).toEqual(
|
|
29
|
-
1, 2, 3, 5, 6, 7, 8, 9, 10
|
|
30
|
-
|
|
28
|
+
expect(PriorityQueue.heapify({nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10], comparator: (a, b) => a - b}).toArray()).toEqual(
|
|
29
|
+
[1, 2, 3, 5, 6, 7, 8, 9, 10]
|
|
30
|
+
);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
it('should PriorityQueue clone, sort, getNodes, dfs work well', function () {
|
|
34
|
-
const minPQ1 = new PriorityQueue<number>((a, b) => a - b);
|
|
34
|
+
const minPQ1 = new PriorityQueue<number>({comparator: (a, b) => a - b});
|
|
35
35
|
minPQ1.refill([2, 5, 8, 3, 1, 6, 7, 4]);
|
|
36
36
|
const clonedPriorityQueue = minPQ1.clone();
|
|
37
37
|
expect(clonedPriorityQueue.getNodes()).toEqual(minPQ1.getNodes());
|
|
@@ -45,7 +45,7 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
45
45
|
describe('Priority Queue Performance Test', () => {
|
|
46
46
|
it('should numeric heap work well', function () {
|
|
47
47
|
const values = Array.from(new Array(10000), () => getRandomInt(1, 10000000));
|
|
48
|
-
const minPriorityQueue = new PriorityQueue<number>((a, b) => a - b);
|
|
48
|
+
const minPriorityQueue = new PriorityQueue<number>({comparator: (a, b) => a - b});
|
|
49
49
|
minPriorityQueue.refill(values);
|
|
50
50
|
const sorted = minPriorityQueue.sort();
|
|
51
51
|
expect(sorted).toEqual(values.sort((a, b) => a - b));
|