data-structure-typed 1.47.6 → 1.47.8
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/.github/ISSUE_TEMPLATE/bug_report.md +10 -7
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/release-package.yml +1 -1
- package/CHANGELOG.md +1 -1
- package/CODE_OF_CONDUCT.md +32 -10
- package/COMMANDS.md +3 -1
- package/CONTRIBUTING.md +4 -3
- package/README.md +188 -32
- package/SECURITY.md +1 -1
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +563 -8
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +40 -22
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +45 -36
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +105 -113
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +133 -119
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +53 -44
- package/dist/cjs/data-structures/binary-tree/bst.js +137 -154
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +48 -15
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +70 -33
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +26 -37
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +58 -137
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -6
- package/dist/cjs/data-structures/hash/hash-map.js +5 -8
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- 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 +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +3 -0
- package/dist/cjs/data-structures/trie/trie.js +19 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +6 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +40 -22
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +45 -36
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +105 -113
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +133 -128
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +53 -44
- package/dist/mjs/data-structures/binary-tree/bst.js +137 -154
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +48 -15
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +70 -33
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +26 -37
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +59 -138
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -6
- package/dist/mjs/data-structures/hash/hash-map.js +5 -8
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/data-structures/trie/trie.d.ts +3 -0
- package/dist/mjs/data-structures/trie/trie.js +20 -4
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +6 -1
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/umd/data-structure-typed.js +583 -627
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +59 -39
- package/src/data-structures/binary-tree/binary-tree.ts +192 -180
- package/src/data-structures/binary-tree/bst.ts +157 -154
- package/src/data-structures/binary-tree/rb-tree.ts +78 -37
- package/src/data-structures/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +67 -145
- package/src/data-structures/graph/abstract-graph.ts +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/data-structures/trie/trie.ts +23 -4
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +11 -1
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/src/types/data-structures/hash/hash-map.ts +1 -2
- package/test/integration/{all-in-one.ts → all-in-one.test.ts} +1 -1
- package/test/integration/index.html +158 -2
- package/test/performance/data-structures/comparison/comparison.test.ts +5 -5
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +19 -19
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +50 -51
- package/test/unit/data-structures/binary-tree/bst.test.ts +49 -54
- package/test/unit/data-structures/binary-tree/overall.test.ts +17 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +118 -66
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +10 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
- package/test/unit/unrestricted-interconversion.test.ts +61 -5
- package/tsconfig-cjs.json +1 -1
|
@@ -17,8 +17,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should out of bound index', () => {
|
|
20
|
-
expect(list.getNodeAt(-1)).toBe(
|
|
21
|
-
expect(list.getNodeAt(5)).toBe(
|
|
20
|
+
expect(list.getNodeAt(-1)).toBe(undefined);
|
|
21
|
+
expect(list.getNodeAt(5)).toBe(undefined);
|
|
22
22
|
expect(list.insertAt(5, 6)).toBe(true);
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -37,16 +37,16 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
37
37
|
expect(list.tail?.value).toBe(4);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
it('should find
|
|
41
|
-
expect(list.find(value => value === 6)).toBe(
|
|
40
|
+
it('should find undefined', () => {
|
|
41
|
+
expect(list.find(value => value === 6)).toBe(undefined);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
it('should indexOf -1', () => {
|
|
45
45
|
expect(list.indexOf(6)).toBe(-1);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('should findBackward
|
|
49
|
-
expect(list.findBackward(value => value === 0)).toBe(
|
|
48
|
+
it('should findBackward undefined', () => {
|
|
49
|
+
expect(list.findBackward(value => value === 0)).toBe(undefined);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it('should insertAfter tail', () => {
|
|
@@ -69,8 +69,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
69
69
|
|
|
70
70
|
it('should initialize an empty list', () => {
|
|
71
71
|
expect(list.length).toBe(0);
|
|
72
|
-
expect(list.head).
|
|
73
|
-
expect(list.tail).
|
|
72
|
+
expect(list.head).toBe(undefined);
|
|
73
|
+
expect(list.tail).toBe(undefined);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
it('should push elements to the list', () => {
|
|
@@ -134,8 +134,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
134
134
|
// Deleting from the end
|
|
135
135
|
list.deleteAt(0);
|
|
136
136
|
expect(list.length).toBe(0);
|
|
137
|
-
expect(list.head).
|
|
138
|
-
expect(list.tail).
|
|
137
|
+
expect(list.head).toBe(undefined);
|
|
138
|
+
expect(list.tail).toBe(undefined);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
it('should delete elements by value', () => {
|
|
@@ -154,8 +154,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
154
154
|
|
|
155
155
|
list.delete(3);
|
|
156
156
|
expect(list.length).toBe(0);
|
|
157
|
-
expect(list.head).
|
|
158
|
-
expect(list.tail).
|
|
157
|
+
expect(list.head).toBe(undefined);
|
|
158
|
+
expect(list.tail).toBe(undefined);
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
it('should reverse the linked list', () => {
|
|
@@ -259,8 +259,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
259
259
|
list.clear();
|
|
260
260
|
|
|
261
261
|
expect(list.length).toBe(0);
|
|
262
|
-
expect(list.head).toBe(
|
|
263
|
-
expect(list.tail).toBe(
|
|
262
|
+
expect(list.head).toBe(undefined);
|
|
263
|
+
expect(list.tail).toBe(undefined);
|
|
264
264
|
});
|
|
265
265
|
|
|
266
266
|
it('should create a reversed array of values', () => {
|
|
@@ -333,7 +333,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
333
333
|
list.push(1);
|
|
334
334
|
list.push(3);
|
|
335
335
|
const result = list.find(data => data % 2 === 0);
|
|
336
|
-
expect(result).
|
|
336
|
+
expect(result).toBe(undefined);
|
|
337
337
|
});
|
|
338
338
|
});
|
|
339
339
|
|
|
@@ -402,8 +402,8 @@ describe('SinglyLinkedList', () => {
|
|
|
402
402
|
});
|
|
403
403
|
|
|
404
404
|
it('should initialize an empty list', () => {
|
|
405
|
-
expect(list.head).
|
|
406
|
-
expect(list.tail).
|
|
405
|
+
expect(list.head).toBe(undefined);
|
|
406
|
+
expect(list.tail).toBe(undefined);
|
|
407
407
|
expect(list.length).toBe(0);
|
|
408
408
|
});
|
|
409
409
|
|
|
@@ -154,7 +154,7 @@ describe('Deque', () => {
|
|
|
154
154
|
expect(deque.getAt(2)).toBe(3);
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
it('should return
|
|
157
|
+
it('should return undefined for out-of-bounds index', () => {
|
|
158
158
|
// expect(deque.getAt(0)).toThrowError('Index out of bounds.');
|
|
159
159
|
// expect(deque.getAt(1)).toThrow('Index out of bounds');
|
|
160
160
|
// expect(deque.getAt(-1)).toThrow('Index out of bounds');
|
|
@@ -35,9 +35,9 @@ describe('Stack', () => {
|
|
|
35
35
|
expect(stack.size).toBe(2);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
it('should return
|
|
38
|
+
it('should return undefined when popping from an empty stack', () => {
|
|
39
39
|
const poppedElement = stack.pop();
|
|
40
|
-
expect(poppedElement).
|
|
40
|
+
expect(poppedElement).toBe(undefined);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('should convert the stack to an array', () => {
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
BST,
|
|
5
5
|
Deque,
|
|
6
6
|
DoublyLinkedList,
|
|
7
|
+
HashMap,
|
|
8
|
+
Heap,
|
|
7
9
|
MaxHeap,
|
|
8
10
|
MaxPriorityQueue,
|
|
9
11
|
MinHeap,
|
|
@@ -12,12 +14,25 @@ import {
|
|
|
12
14
|
RedBlackTree,
|
|
13
15
|
SinglyLinkedList,
|
|
14
16
|
Stack,
|
|
15
|
-
TreeMultimap
|
|
17
|
+
TreeMultimap,
|
|
18
|
+
Trie
|
|
16
19
|
} from '../../src';
|
|
17
20
|
import { isDebugTest } from "../config";
|
|
18
21
|
|
|
19
22
|
const isDebug = isDebugTest;
|
|
20
23
|
const orgArr: number[] = [6, 1, 2, 7, 5, 3, 4, 9, 8];
|
|
24
|
+
const orgStrArr: string[] = [
|
|
25
|
+
"trie",
|
|
26
|
+
"trial",
|
|
27
|
+
"trick",
|
|
28
|
+
"trip",
|
|
29
|
+
"tree",
|
|
30
|
+
"trend",
|
|
31
|
+
"triangle",
|
|
32
|
+
"track",
|
|
33
|
+
"trace",
|
|
34
|
+
"transmit"
|
|
35
|
+
];
|
|
21
36
|
const entries: [number, number][] = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
|
22
37
|
|
|
23
38
|
describe('conversions', () => {
|
|
@@ -72,28 +87,69 @@ describe('conversions', () => {
|
|
|
72
87
|
})
|
|
73
88
|
|
|
74
89
|
it('Entry Array to BST', () => {
|
|
75
|
-
const bst = new BST<number>(
|
|
90
|
+
const bst = new BST<number>(entries);
|
|
76
91
|
expect(bst.size).toBe(9)
|
|
77
92
|
isDebug && bst.print();
|
|
78
93
|
})
|
|
79
94
|
|
|
80
95
|
it('Entry Array to RedBlackTree', () => {
|
|
81
|
-
const rbTree = new RedBlackTree<number>(
|
|
96
|
+
const rbTree = new RedBlackTree<number>(entries);
|
|
82
97
|
expect(rbTree.size).toBe(9)
|
|
83
98
|
isDebug && rbTree.print();
|
|
84
99
|
})
|
|
85
100
|
|
|
86
101
|
it('Entry Array to AVLTree', () => {
|
|
87
|
-
const avl = new AVLTree<number>(
|
|
102
|
+
const avl = new AVLTree<number>(entries);
|
|
88
103
|
expect(avl.size).toBe(9)
|
|
89
104
|
isDebug && avl.print();
|
|
90
105
|
})
|
|
91
106
|
|
|
92
107
|
it('Entry Array to TreeMultimap', () => {
|
|
93
|
-
const treeMulti = new TreeMultimap<number>(
|
|
108
|
+
const treeMulti = new TreeMultimap<number>(entries);
|
|
94
109
|
expect(treeMulti.size).toBe(9)
|
|
95
110
|
isDebug && treeMulti.print();
|
|
96
111
|
})
|
|
112
|
+
|
|
113
|
+
it('HashMap to RedBlackTree', () => {
|
|
114
|
+
const hm = new HashMap(entries);
|
|
115
|
+
isDebug && hm.print()
|
|
116
|
+
const rbTree = new RedBlackTree<number>(hm);
|
|
117
|
+
expect(rbTree.size).toBe(9)
|
|
118
|
+
isDebug && rbTree.print();
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('PriorityQueue to BST', () => {
|
|
122
|
+
const pq = new MinPriorityQueue(orgArr);
|
|
123
|
+
isDebug && pq.print();
|
|
124
|
+
const bst = new BST<number>(pq);
|
|
125
|
+
expect(bst.size).toBe(9)
|
|
126
|
+
isDebug && bst.print();
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('Deque to RedBlackTree', () => {
|
|
130
|
+
const dq = new Deque(orgArr);
|
|
131
|
+
isDebug && dq.print();
|
|
132
|
+
const rbTree = new RedBlackTree<number>(dq);
|
|
133
|
+
expect(rbTree.size).toBe(9)
|
|
134
|
+
isDebug && rbTree.print();
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('Trie to Heap to Deque', () => {
|
|
138
|
+
const trie = new Trie(orgStrArr);
|
|
139
|
+
expect(trie.size).toBe(10);
|
|
140
|
+
isDebug && trie.print();
|
|
141
|
+
const heap = new Heap<string>(trie, { comparator: (a, b) => Number(a) - Number(b) });
|
|
142
|
+
expect(heap.size).toBe(10);
|
|
143
|
+
isDebug && heap.print();
|
|
144
|
+
const dq = new Deque<string>(heap);
|
|
145
|
+
expect(dq.size).toBe(10);
|
|
146
|
+
isDebug && dq.print();
|
|
147
|
+
const entries = dq.map((el, i) => <[number, string]>[i, el]);
|
|
148
|
+
const avl = new AVLTree<string>(entries);
|
|
149
|
+
expect(avl.size).toBe(10)
|
|
150
|
+
isDebug && avl.print();
|
|
151
|
+
})
|
|
152
|
+
|
|
97
153
|
})
|
|
98
154
|
|
|
99
155
|
|