data-structure-typed 1.47.5 → 1.47.7
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 +103 -28
- 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 +36 -18
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +46 -29
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +158 -129
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +182 -184
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +73 -63
- package/dist/cjs/data-structures/binary-tree/bst.js +168 -169
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -17
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +77 -31
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +29 -40
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +66 -136
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js +1 -1
- package/dist/cjs/data-structures/graph/abstract-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/heap/heap.d.ts +19 -21
- package/dist/cjs/data-structures/heap/heap.js +52 -34
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +2 -5
- package/dist/cjs/data-structures/heap/max-heap.js +2 -2
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +2 -5
- package/dist/cjs/data-structures/heap/min-heap.js +2 -2
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +9 -1
- 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 +2 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +8 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +2 -2
- 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 +2 -5
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +2 -2
- 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 +2 -5
- 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/queue/deque.d.ts +1 -0
- package/dist/cjs/data-structures/queue/deque.js +3 -0
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -0
- package/dist/cjs/data-structures/queue/queue.js +3 -0
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -1
- package/dist/cjs/data-structures/stack/stack.js +10 -2
- 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 +4 -2
- package/dist/cjs/types/common.d.ts +7 -0
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/cjs/types/data-structures/heap/heap.d.ts +4 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +36 -18
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +49 -30
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +158 -129
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +182 -194
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +73 -63
- package/dist/mjs/data-structures/binary-tree/bst.js +171 -170
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -17
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +81 -33
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +29 -40
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +70 -138
- package/dist/mjs/data-structures/graph/abstract-graph.js +1 -1
- 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/heap/heap.d.ts +19 -21
- package/dist/mjs/data-structures/heap/heap.js +53 -35
- package/dist/mjs/data-structures/heap/max-heap.d.ts +2 -5
- package/dist/mjs/data-structures/heap/max-heap.js +2 -2
- package/dist/mjs/data-structures/heap/min-heap.d.ts +2 -5
- package/dist/mjs/data-structures/heap/min-heap.js +2 -2
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +9 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +8 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +2 -2
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +2 -2
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +2 -5
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/mjs/data-structures/queue/deque.d.ts +1 -0
- package/dist/mjs/data-structures/queue/deque.js +3 -0
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -0
- package/dist/mjs/data-structures/queue/queue.js +3 -0
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -1
- package/dist/mjs/data-structures/stack/stack.js +10 -2
- 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 +4 -2
- package/dist/mjs/types/common.d.ts +7 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/mjs/types/data-structures/heap/heap.d.ts +4 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
- package/dist/umd/data-structure-typed.js +629 -595
- 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 +61 -31
- package/src/data-structures/binary-tree/binary-tree.ts +283 -254
- package/src/data-structures/binary-tree/bst.ts +193 -170
- package/src/data-structures/binary-tree/rb-tree.ts +87 -32
- package/src/data-structures/binary-tree/tree-multimap.ts +76 -136
- package/src/data-structures/graph/abstract-graph.ts +1 -1
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/data-structures/heap/heap.ts +57 -39
- package/src/data-structures/heap/max-heap.ts +5 -5
- package/src/data-structures/heap/min-heap.ts +5 -5
- package/src/data-structures/linked-list/doubly-linked-list.ts +10 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +9 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -12
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +4 -0
- package/src/data-structures/queue/queue.ts +4 -0
- package/src/data-structures/stack/stack.ts +12 -3
- package/src/data-structures/trie/trie.ts +23 -4
- package/src/interfaces/binary-tree.ts +14 -2
- package/src/types/common.ts +15 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -3
- package/src/types/data-structures/hash/hash-map.ts +1 -2
- package/src/types/data-structures/heap/heap.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +3 -1
- package/test/integration/{all-in-one.ts → all-in-one.test.ts} +1 -1
- package/test/integration/index.html +87 -0
- package/test/performance/data-structures/comparison/comparison.test.ts +7 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -57
- 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/tree-multimap.test.ts +118 -66
- 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 +4 -3
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +9 -10
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
- package/test/unit/unrestricted-interconversion.test.ts +156 -0
- package/tsconfig-cjs.json +1 -1
- package/test/integration/conversion.test.ts +0 -0
|
@@ -215,6 +215,93 @@
|
|
|
215
215
|
} catch (e) {
|
|
216
216
|
console.error(e);
|
|
217
217
|
}
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
const {
|
|
221
|
+
AVLTree,
|
|
222
|
+
BinaryTree,
|
|
223
|
+
BST,
|
|
224
|
+
Deque,
|
|
225
|
+
DoublyLinkedList,
|
|
226
|
+
HashMap,
|
|
227
|
+
Heap,
|
|
228
|
+
MaxPriorityQueue,
|
|
229
|
+
MinHeap,
|
|
230
|
+
MinPriorityQueue,
|
|
231
|
+
Queue,
|
|
232
|
+
RedBlackTree,
|
|
233
|
+
SinglyLinkedList,
|
|
234
|
+
Stack,
|
|
235
|
+
TreeMultimap,
|
|
236
|
+
Trie
|
|
237
|
+
} = dataStructureTyped;
|
|
238
|
+
const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
|
|
239
|
+
const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle", "track", "trace", "transmit"];
|
|
240
|
+
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
|
241
|
+
|
|
242
|
+
const queue = new Queue(orgArr);
|
|
243
|
+
queue.print();
|
|
244
|
+
|
|
245
|
+
const deque = new Deque(orgArr);
|
|
246
|
+
deque.print();
|
|
247
|
+
|
|
248
|
+
const sList = new SinglyLinkedList(orgArr);
|
|
249
|
+
sList.print();
|
|
250
|
+
|
|
251
|
+
const dList = new DoublyLinkedList(orgArr);
|
|
252
|
+
dList.print();
|
|
253
|
+
|
|
254
|
+
const stack = new Stack(orgArr);
|
|
255
|
+
stack.print();
|
|
256
|
+
|
|
257
|
+
const minHeap = new MinHeap(orgArr);
|
|
258
|
+
minHeap.print();
|
|
259
|
+
|
|
260
|
+
const maxPQ = new MaxPriorityQueue(orgArr);
|
|
261
|
+
maxPQ.print();
|
|
262
|
+
|
|
263
|
+
const biTree = new BinaryTree(entries);
|
|
264
|
+
biTree.print();
|
|
265
|
+
|
|
266
|
+
const bst = new BST(entries);
|
|
267
|
+
bst.print();
|
|
268
|
+
|
|
269
|
+
const rbTree = new RedBlackTree(entries);
|
|
270
|
+
rbTree.print();
|
|
271
|
+
|
|
272
|
+
const avl = new AVLTree(entries);
|
|
273
|
+
avl.print();
|
|
274
|
+
|
|
275
|
+
const treeMulti = new TreeMultimap(entries);
|
|
276
|
+
treeMulti.print();
|
|
277
|
+
|
|
278
|
+
const hm = new HashMap(entries);
|
|
279
|
+
hm.print()
|
|
280
|
+
const rbTreeH = new RedBlackTree(hm);
|
|
281
|
+
rbTreeH.print();
|
|
282
|
+
|
|
283
|
+
const pq = new MinPriorityQueue(orgArr);
|
|
284
|
+
pq.print();
|
|
285
|
+
const bst1 = new BST(pq);
|
|
286
|
+
bst1.print();
|
|
287
|
+
|
|
288
|
+
const dq1 = new Deque(orgArr);
|
|
289
|
+
dq1.print();
|
|
290
|
+
const rbTree1 = new RedBlackTree(dq1);
|
|
291
|
+
rbTree1.print();
|
|
292
|
+
|
|
293
|
+
const trie2 = new Trie(orgStrArr);
|
|
294
|
+
trie2.print();
|
|
295
|
+
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
|
|
296
|
+
heap2.print();
|
|
297
|
+
const dq2 = new Deque(heap2);
|
|
298
|
+
dq2.print();
|
|
299
|
+
const entries2 = dq2.map((el, i) => [i, el]);
|
|
300
|
+
const avl2 = new AVLTree(entries2);
|
|
301
|
+
avl2.print();
|
|
302
|
+
} catch (e) {
|
|
303
|
+
console.error(e);
|
|
304
|
+
}
|
|
218
305
|
</script>
|
|
219
306
|
|
|
220
307
|
</body>
|
|
@@ -23,17 +23,18 @@ const arrHundredThousand = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSA
|
|
|
23
23
|
suite
|
|
24
24
|
.add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
25
25
|
|
|
26
|
-
const pq = new SRCPriorityQueue<number>(
|
|
26
|
+
const pq = new SRCPriorityQueue<number>();
|
|
27
27
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
28
28
|
})
|
|
29
29
|
.add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
const pq = new CJSPriorityQueue<number>();
|
|
32
33
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
33
34
|
})
|
|
34
35
|
.add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
35
36
|
|
|
36
|
-
const pq = new MJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
37
|
+
const pq = new MJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
37
38
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
38
39
|
});
|
|
39
40
|
|
|
@@ -47,19 +48,19 @@ if (isCompetitor) {
|
|
|
47
48
|
|
|
48
49
|
suite
|
|
49
50
|
.add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
50
|
-
const pq = new SRCPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
51
|
+
const pq = new SRCPriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
51
52
|
|
|
52
53
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
53
54
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
54
55
|
})
|
|
55
56
|
.add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
56
|
-
const pq = new CJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
57
|
+
const pq = new CJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
57
58
|
|
|
58
59
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
59
60
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
60
61
|
})
|
|
61
62
|
.add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
62
|
-
const pq = new MJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
63
|
+
const pq = new MJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
63
64
|
|
|
64
65
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
65
66
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
@@ -7,7 +7,7 @@ const { HUNDRED_THOUSAND, TEN_THOUSAND } = magnitude;
|
|
|
7
7
|
|
|
8
8
|
suite
|
|
9
9
|
.add(`${HUNDRED_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
10
|
-
const heap = new Heap<number>({ comparator: (a, b) => b - a });
|
|
10
|
+
const heap = new Heap<number>([], { comparator: (a, b) => b - a });
|
|
11
11
|
|
|
12
12
|
for (let i = 0; i < HUNDRED_THOUSAND; i++) {
|
|
13
13
|
heap.add(i);
|
|
@@ -18,7 +18,7 @@ suite
|
|
|
18
18
|
}
|
|
19
19
|
})
|
|
20
20
|
.add(`${HUNDRED_THOUSAND.toLocaleString()} add & dfs`, () => {
|
|
21
|
-
const heap = new Heap<number>({ comparator: (a, b) => b - a });
|
|
21
|
+
const heap = new Heap<number>([], { comparator: (a, b) => b - a });
|
|
22
22
|
|
|
23
23
|
for (let i = 0; i < HUNDRED_THOUSAND; i++) {
|
|
24
24
|
heap.add(i);
|
|
@@ -8,7 +8,7 @@ const suite = new Benchmark.Suite();
|
|
|
8
8
|
const { HUNDRED_THOUSAND } = magnitude;
|
|
9
9
|
|
|
10
10
|
suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
11
|
-
const pq = new PriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
11
|
+
const pq = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
12
12
|
|
|
13
13
|
for (let i = 0; i < HUNDRED_THOUSAND; i++) {
|
|
14
14
|
pq.add(i);
|
|
@@ -5,7 +5,7 @@ describe('AVL Tree Test', () => {
|
|
|
5
5
|
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
6
6
|
const tree = new AVLTree<number>();
|
|
7
7
|
|
|
8
|
-
for (const i of arr) tree.add(i, i);
|
|
8
|
+
for (const i of arr) tree.add([i, i]);
|
|
9
9
|
|
|
10
10
|
tree.add(null);
|
|
11
11
|
const node6 = tree.getNode(6);
|
|
@@ -112,9 +112,9 @@ describe('AVL Tree Test', () => {
|
|
|
112
112
|
describe('AVL Tree Test recursively', () => {
|
|
113
113
|
it('should perform various operations on a AVL Tree', () => {
|
|
114
114
|
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
115
|
-
const tree = new AVLTree<number>({ iterationType: IterationType.RECURSIVE });
|
|
115
|
+
const tree = new AVLTree<number>([], { iterationType: IterationType.RECURSIVE });
|
|
116
116
|
|
|
117
|
-
for (const i of arr) tree.add(i, i);
|
|
117
|
+
for (const i of arr) tree.add([i, i]);
|
|
118
118
|
|
|
119
119
|
const node6 = tree.getNode(6);
|
|
120
120
|
|
|
@@ -230,7 +230,7 @@ describe('AVLTree APIs test', () => {
|
|
|
230
230
|
avl.add(node2);
|
|
231
231
|
const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
|
|
232
232
|
avl.add(node3);
|
|
233
|
-
avl.add(
|
|
233
|
+
avl.add([3, { id: 3, text: 'text33' }]);
|
|
234
234
|
|
|
235
235
|
const bfsRes = avl.bfs(node => node.key);
|
|
236
236
|
expect(bfsRes[0]).toBe(2);
|
|
@@ -240,26 +240,26 @@ describe('AVLTree APIs test', () => {
|
|
|
240
240
|
describe('AVLTree', () => {
|
|
241
241
|
it('should balance the tree using _balanceLR when nodes are added', () => {
|
|
242
242
|
const avlTree = new AVLTree();
|
|
243
|
-
avlTree.add(10, 'A');
|
|
244
|
-
avlTree.add(5, 'B');
|
|
245
|
-
avlTree.add(15, 'C');
|
|
246
|
-
avlTree.add(3, 'D');
|
|
247
|
-
avlTree.add(7, 'E');
|
|
243
|
+
avlTree.add([10, 'A']);
|
|
244
|
+
avlTree.add([5, 'B']);
|
|
245
|
+
avlTree.add([15, 'C']);
|
|
246
|
+
avlTree.add([3, 'D']);
|
|
247
|
+
avlTree.add([7, 'E']);
|
|
248
248
|
|
|
249
249
|
// Adding nodes to trigger _balanceLR
|
|
250
|
-
avlTree.add(12, 'F');
|
|
250
|
+
avlTree.add([12, 'F']);
|
|
251
251
|
|
|
252
252
|
// You can add more specific assertions to check the tree's balance and structure.
|
|
253
253
|
});
|
|
254
254
|
|
|
255
255
|
it('should balance the tree using _balanceLR when nodes are deleted', () => {
|
|
256
256
|
const avlTree = new AVLTree();
|
|
257
|
-
avlTree.add(10, 'A');
|
|
258
|
-
avlTree.add(5, 'B');
|
|
259
|
-
avlTree.add(15, 'C');
|
|
260
|
-
avlTree.add(3, 'D');
|
|
261
|
-
avlTree.add(7, 'E');
|
|
262
|
-
avlTree.add(12, 'F');
|
|
257
|
+
avlTree.add([10, 'A']);
|
|
258
|
+
avlTree.add([5, 'B']);
|
|
259
|
+
avlTree.add([15, 'C']);
|
|
260
|
+
avlTree.add([3, 'D']);
|
|
261
|
+
avlTree.add([7, 'E']);
|
|
262
|
+
avlTree.add([12, 'F']);
|
|
263
263
|
|
|
264
264
|
// Deleting nodes to trigger _balanceLR
|
|
265
265
|
avlTree.delete(3);
|
|
@@ -279,7 +279,7 @@ describe('AVLTree', () => {
|
|
|
279
279
|
avl.add(node2);
|
|
280
280
|
const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
|
|
281
281
|
avl.add(node3);
|
|
282
|
-
avl.add(
|
|
282
|
+
avl.add([3, { id: 3, text: 'text33' }]);
|
|
283
283
|
|
|
284
284
|
const bfsRes = avl.bfs(node => node);
|
|
285
285
|
expect(bfsRes[0]?.key).toBe(2);
|
|
@@ -291,9 +291,9 @@ describe('AVLTree iterative methods test', () => {
|
|
|
291
291
|
let avl: AVLTree<string>;
|
|
292
292
|
beforeEach(() => {
|
|
293
293
|
avl = new AVLTree();
|
|
294
|
-
avl.add(1, 'a');
|
|
295
|
-
avl.add(2, 'b');
|
|
296
|
-
avl.add(3, 'c');
|
|
294
|
+
avl.add([1, 'a']);
|
|
295
|
+
avl.add([2, 'b']);
|
|
296
|
+
avl.add([3, 'c']);
|
|
297
297
|
});
|
|
298
298
|
|
|
299
299
|
test('The node obtained by get Node should match the node type', () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BinaryTree, BinaryTreeNode, IterationType } from '../../../../src';
|
|
1
|
+
import { BinaryTree, BinaryTreeNode, FamilyPosition, IterationType } from '../../../../src';
|
|
2
2
|
import { getRandomIntArray } from '../../../utils';
|
|
3
|
-
import { FamilyPosition } from 'binary-tree-typed';
|
|
4
3
|
// import {isDebugTest} from '../../../config';
|
|
5
4
|
|
|
6
5
|
// const isDebug = isDebugTest;
|
|
@@ -137,10 +136,10 @@ describe('BinaryTree', () => {
|
|
|
137
136
|
});
|
|
138
137
|
|
|
139
138
|
it('should add and find nodes', () => {
|
|
140
|
-
tree.add(1, 1);
|
|
139
|
+
tree.add([1, 1]);
|
|
141
140
|
tree.add(undefined);
|
|
142
|
-
tree.add(2, 2);
|
|
143
|
-
tree.add(3, 3);
|
|
141
|
+
tree.add([2, 2]);
|
|
142
|
+
tree.add([3, 3]);
|
|
144
143
|
|
|
145
144
|
expect(tree.has(1)).toBe(true);
|
|
146
145
|
expect(tree.has(2)).toBe(true);
|
|
@@ -189,9 +188,9 @@ describe('BinaryTree', () => {
|
|
|
189
188
|
tree.add(4);
|
|
190
189
|
tree.add(2);
|
|
191
190
|
expect(tree.getHeight()).toBe(1);
|
|
192
|
-
tree.
|
|
191
|
+
tree.iterationType = IterationType.RECURSIVE;
|
|
193
192
|
expect(tree.getHeight()).toBe(1);
|
|
194
|
-
tree.
|
|
193
|
+
tree.iterationType = IterationType.ITERATIVE;
|
|
195
194
|
|
|
196
195
|
tree.add(6);
|
|
197
196
|
tree.add(1);
|
|
@@ -381,7 +380,7 @@ describe('BinaryTree', () => {
|
|
|
381
380
|
let tree: BinaryTree<string>;
|
|
382
381
|
|
|
383
382
|
beforeEach(() => {
|
|
384
|
-
tree = new BinaryTree<string>({ iterationType: IterationType.RECURSIVE });
|
|
383
|
+
tree = new BinaryTree<string>([], { iterationType: IterationType.RECURSIVE });
|
|
385
384
|
});
|
|
386
385
|
|
|
387
386
|
afterEach(() => {
|
|
@@ -395,9 +394,9 @@ describe('BinaryTree', () => {
|
|
|
395
394
|
});
|
|
396
395
|
|
|
397
396
|
it('should add nodes to the tree', () => {
|
|
398
|
-
tree.add(5, 'A');
|
|
399
|
-
tree.add(3, 'B');
|
|
400
|
-
tree.add(7, 'C');
|
|
397
|
+
tree.add([5, 'A']);
|
|
398
|
+
tree.add([3, 'B']);
|
|
399
|
+
tree.add([7, 'C']);
|
|
401
400
|
|
|
402
401
|
expect(tree.size).toBe(3);
|
|
403
402
|
expect(tree.isEmpty()).toBe(false);
|
|
@@ -405,9 +404,9 @@ describe('BinaryTree', () => {
|
|
|
405
404
|
});
|
|
406
405
|
|
|
407
406
|
it('should clear the BinaryTree', () => {
|
|
408
|
-
tree.add(5, 'A');
|
|
409
|
-
tree.add(3, 'B');
|
|
410
|
-
tree.add(7, 'C');
|
|
407
|
+
tree.add([5, 'A']);
|
|
408
|
+
tree.add([3, 'B']);
|
|
409
|
+
tree.add([7, 'C']);
|
|
411
410
|
|
|
412
411
|
tree.clear();
|
|
413
412
|
|
|
@@ -417,9 +416,9 @@ describe('BinaryTree', () => {
|
|
|
417
416
|
});
|
|
418
417
|
|
|
419
418
|
it('should get nodes by key', () => {
|
|
420
|
-
tree.add(5, 'A');
|
|
421
|
-
tree.add(3, 'B');
|
|
422
|
-
tree.add(7, 'C');
|
|
419
|
+
tree.add([5, 'A']);
|
|
420
|
+
tree.add([3, 'B']);
|
|
421
|
+
tree.add([7, 'C']);
|
|
423
422
|
|
|
424
423
|
const nodeA = tree.getNode(5);
|
|
425
424
|
const nodeB = tree.getNode(3);
|
|
@@ -431,7 +430,7 @@ describe('BinaryTree', () => {
|
|
|
431
430
|
});
|
|
432
431
|
|
|
433
432
|
it('should return null when getting a non-existent node', () => {
|
|
434
|
-
tree.add(5, 'A');
|
|
433
|
+
tree.add([5, 'A']);
|
|
435
434
|
|
|
436
435
|
const node = tree.getNode(3);
|
|
437
436
|
|
|
@@ -439,18 +438,18 @@ describe('BinaryTree', () => {
|
|
|
439
438
|
});
|
|
440
439
|
|
|
441
440
|
it('should get the depth of a node', () => {
|
|
442
|
-
tree.add(5, 'A');
|
|
443
|
-
tree.add(3, 'B');
|
|
444
|
-
tree.add(7, 'C');
|
|
441
|
+
tree.add([5, 'A']);
|
|
442
|
+
tree.add([3, 'B']);
|
|
443
|
+
tree.add([7, 'C']);
|
|
445
444
|
|
|
446
445
|
expect(tree.getDepth(7)).toBe(1);
|
|
447
446
|
expect(tree.getDepth(3)).toBe(1);
|
|
448
447
|
});
|
|
449
448
|
|
|
450
449
|
it('should get the height of the tree', () => {
|
|
451
|
-
tree.add(5, 'A');
|
|
452
|
-
tree.add(3, 'B');
|
|
453
|
-
tree.add(7, 'C');
|
|
450
|
+
tree.add([5, 'A']);
|
|
451
|
+
tree.add([3, 'B']);
|
|
452
|
+
tree.add([7, 'C']);
|
|
454
453
|
|
|
455
454
|
expect(tree.getHeight()).toBe(1);
|
|
456
455
|
expect(tree.getHeight(undefined, IterationType.RECURSIVE)).toBe(1);
|
|
@@ -458,17 +457,17 @@ describe('BinaryTree', () => {
|
|
|
458
457
|
});
|
|
459
458
|
|
|
460
459
|
it('should check if the tree is a binary search tree', () => {
|
|
461
|
-
tree.add(5, 'A');
|
|
462
|
-
tree.add(3, 'B');
|
|
463
|
-
tree.add(7, 'C');
|
|
460
|
+
tree.add([5, 'A']);
|
|
461
|
+
tree.add([3, 'B']);
|
|
462
|
+
tree.add([7, 'C']);
|
|
464
463
|
|
|
465
464
|
expect(tree.isBST()).toBe(true);
|
|
466
465
|
});
|
|
467
466
|
|
|
468
467
|
it('should perform a depth-first traversal', () => {
|
|
469
|
-
tree.add(5, 'A');
|
|
470
|
-
tree.add(3, 'B');
|
|
471
|
-
tree.add(7, 'C');
|
|
468
|
+
tree.add([5, 'A']);
|
|
469
|
+
tree.add([3, 'B']);
|
|
470
|
+
tree.add([7, 'C']);
|
|
472
471
|
|
|
473
472
|
const result = tree.dfs();
|
|
474
473
|
expect(result).toEqual([3, 5, 7]);
|
|
@@ -476,9 +475,9 @@ describe('BinaryTree', () => {
|
|
|
476
475
|
});
|
|
477
476
|
|
|
478
477
|
it('should perform a breadth-first traversal', () => {
|
|
479
|
-
tree.add(5, 'A');
|
|
480
|
-
tree.add(3, 'B');
|
|
481
|
-
tree.add(7, 'C');
|
|
478
|
+
tree.add([5, 'A']);
|
|
479
|
+
tree.add([3, 'B']);
|
|
480
|
+
tree.add([7, 'C']);
|
|
482
481
|
|
|
483
482
|
const result = tree.bfs(node => node.key);
|
|
484
483
|
expect(result).toEqual([5, 3, 7]);
|
|
@@ -486,9 +485,9 @@ describe('BinaryTree', () => {
|
|
|
486
485
|
});
|
|
487
486
|
|
|
488
487
|
it('should list levels of the tree', () => {
|
|
489
|
-
tree.add(5, 'A');
|
|
490
|
-
tree.add(3, 'B');
|
|
491
|
-
tree.add(7, 'C');
|
|
488
|
+
tree.add([5, 'A']);
|
|
489
|
+
tree.add([3, 'B']);
|
|
490
|
+
tree.add([7, 'C']);
|
|
492
491
|
|
|
493
492
|
const levels = tree.listLevels();
|
|
494
493
|
expect(levels).toEqual([[5], [3, 7]]);
|
|
@@ -496,9 +495,9 @@ describe('BinaryTree', () => {
|
|
|
496
495
|
});
|
|
497
496
|
|
|
498
497
|
it('should delete nodes from the tree', () => {
|
|
499
|
-
tree.add(5, 'A');
|
|
500
|
-
tree.add(3, 'B');
|
|
501
|
-
tree.add(7, 'C');
|
|
498
|
+
tree.add([5, 'A']);
|
|
499
|
+
tree.add([3, 'B']);
|
|
500
|
+
tree.add([7, 'C']);
|
|
502
501
|
|
|
503
502
|
tree.delete(3);
|
|
504
503
|
|
|
@@ -507,17 +506,17 @@ describe('BinaryTree', () => {
|
|
|
507
506
|
});
|
|
508
507
|
|
|
509
508
|
it('should check if the tree is perfectly balanced', () => {
|
|
510
|
-
tree.add(5, 'A');
|
|
511
|
-
tree.add(3, 'B');
|
|
512
|
-
tree.add(7, 'C');
|
|
509
|
+
tree.add([5, 'A']);
|
|
510
|
+
tree.add([3, 'B']);
|
|
511
|
+
tree.add([7, 'C']);
|
|
513
512
|
|
|
514
513
|
expect(tree.isPerfectlyBalanced()).toBe(true);
|
|
515
514
|
});
|
|
516
515
|
|
|
517
516
|
it('should get nodes by a custom callback', () => {
|
|
518
|
-
tree.add(5, 'A');
|
|
519
|
-
tree.add(3, 'B');
|
|
520
|
-
tree.add(7, 'C');
|
|
517
|
+
tree.add([5, 'A']);
|
|
518
|
+
tree.add([3, 'B']);
|
|
519
|
+
tree.add([7, 'C']);
|
|
521
520
|
|
|
522
521
|
const nodes = tree.getNodes('B', (node: BinaryTreeNode<string>) => node.value);
|
|
523
522
|
|
|
@@ -537,15 +536,15 @@ describe('BinaryTree', () => {
|
|
|
537
536
|
});
|
|
538
537
|
|
|
539
538
|
it('should perform Morris traversal', () => {
|
|
540
|
-
tree.add(5, 'A');
|
|
541
|
-
tree.add(3, 'B');
|
|
542
|
-
tree.add(7, 'C');
|
|
539
|
+
tree.add([5, 'A']);
|
|
540
|
+
tree.add([3, 'B']);
|
|
541
|
+
tree.add([7, 'C']);
|
|
543
542
|
|
|
544
|
-
tree.
|
|
543
|
+
tree.iterationType = IterationType.ITERATIVE;
|
|
545
544
|
expect([...tree]).toEqual([[3, "B"], [5, "A"], [7, "C"]]);
|
|
546
|
-
tree.
|
|
545
|
+
tree.iterationType = IterationType.RECURSIVE;
|
|
547
546
|
expect([...tree]).toEqual([[3, "B"], [5, "A"], [7, "C"]]);
|
|
548
|
-
tree.
|
|
547
|
+
tree.iterationType = IterationType.ITERATIVE;
|
|
549
548
|
|
|
550
549
|
const result = tree.morris();
|
|
551
550
|
expect(result).toEqual([3, 5, 7]);
|
|
@@ -553,9 +552,9 @@ describe('BinaryTree', () => {
|
|
|
553
552
|
});
|
|
554
553
|
|
|
555
554
|
it('should perform delete all', () => {
|
|
556
|
-
tree.add(5, 'A');
|
|
557
|
-
tree.add(3, 'B');
|
|
558
|
-
tree.add(7, 'C');
|
|
555
|
+
tree.add([5, 'A']);
|
|
556
|
+
tree.add([3, 'B']);
|
|
557
|
+
tree.add([7, 'C']);
|
|
559
558
|
|
|
560
559
|
tree.delete(5);
|
|
561
560
|
tree.delete(7);
|
|
@@ -570,9 +569,9 @@ describe('BinaryTree iterative methods test', () => {
|
|
|
570
569
|
let binaryTree: BinaryTree<string>;
|
|
571
570
|
beforeEach(() => {
|
|
572
571
|
binaryTree = new BinaryTree();
|
|
573
|
-
binaryTree.add(1, 'a');
|
|
574
|
-
binaryTree.add(2, 'b');
|
|
575
|
-
binaryTree.add(3, 'c');
|
|
572
|
+
binaryTree.add([1, 'a']);
|
|
573
|
+
binaryTree.add([2, 'b']);
|
|
574
|
+
binaryTree.add([3, 'c']);
|
|
576
575
|
});
|
|
577
576
|
|
|
578
577
|
test('The node obtained by get Node should match the node type', () => {
|
|
@@ -7,10 +7,10 @@ describe('BST operations test', () => {
|
|
|
7
7
|
it('should perform various operations on a Binary Search Tree with numeric values', () => {
|
|
8
8
|
const bst = new BST();
|
|
9
9
|
expect(bst).toBeInstanceOf(BST);
|
|
10
|
-
bst.add(11, 11);
|
|
11
|
-
bst.add(3, 3);
|
|
12
|
-
const idsAndValues = [15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
13
|
-
bst.addMany(idsAndValues,
|
|
10
|
+
bst.add([11, 11]);
|
|
11
|
+
bst.add([3, 3]);
|
|
12
|
+
const idsAndValues: [number, number][] = [[15, 15], [1, 1], [8, 8], [13, 13], [16, 16], [2, 2], [6, 6], [9, 9], [12, 12], [14, 14], [4, 4], [7, 7], [10, 10], [5, 5]];
|
|
13
|
+
bst.addMany(idsAndValues, false);
|
|
14
14
|
expect(bst.root).toBeInstanceOf(BSTNode);
|
|
15
15
|
|
|
16
16
|
if (bst.root) expect(bst.root.key).toBe(11);
|
|
@@ -191,30 +191,26 @@ describe('BST operations test', () => {
|
|
|
191
191
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
192
192
|
const objBST = new BST<{ key: number; keyA: number }>();
|
|
193
193
|
expect(objBST).toBeInstanceOf(BST);
|
|
194
|
-
objBST.add(11, { key: 11, keyA: 11 });
|
|
195
|
-
objBST.add(3, { key: 3, keyA: 3 });
|
|
196
|
-
const values = [
|
|
197
|
-
{ key: 15, keyA: 15 },
|
|
198
|
-
{ key: 1, keyA: 1 },
|
|
199
|
-
{ key: 8, keyA: 8 },
|
|
200
|
-
{ key: 13, keyA: 13 },
|
|
201
|
-
{ key: 16, keyA: 16 },
|
|
202
|
-
{ key: 2, keyA: 2 },
|
|
203
|
-
{ key: 6, keyA: 6 },
|
|
204
|
-
{ key: 9, keyA: 9 },
|
|
205
|
-
{ key: 12, keyA: 12 },
|
|
206
|
-
{ key: 14, keyA: 14 },
|
|
207
|
-
{ key: 4, keyA: 4 },
|
|
208
|
-
{ key: 7, keyA: 7 },
|
|
209
|
-
{ key: 10, keyA: 10 },
|
|
210
|
-
{ key: 5, keyA: 5 }
|
|
194
|
+
objBST.add([11, { key: 11, keyA: 11 }]);
|
|
195
|
+
objBST.add([3, { key: 3, keyA: 3 }]);
|
|
196
|
+
const values: [number, { key: number; keyA: number }][] = [
|
|
197
|
+
[15, { key: 15, keyA: 15 }],
|
|
198
|
+
[1, { key: 1, keyA: 1 }],
|
|
199
|
+
[8, { key: 8, keyA: 8 }],
|
|
200
|
+
[13, { key: 13, keyA: 13 }],
|
|
201
|
+
[16, { key: 16, keyA: 16 }],
|
|
202
|
+
[2, { key: 2, keyA: 2 }],
|
|
203
|
+
[6, { key: 6, keyA: 6 }],
|
|
204
|
+
[9, { key: 9, keyA: 9 }],
|
|
205
|
+
[12, { key: 12, keyA: 12 }],
|
|
206
|
+
[14, { key: 14, keyA: 14 }],
|
|
207
|
+
[4, { key: 4, keyA: 4 }],
|
|
208
|
+
[7, { key: 7, keyA: 7 }],
|
|
209
|
+
[10, { key: 10, keyA: 10 }],
|
|
210
|
+
[5, { key: 5, keyA: 5 }]
|
|
211
211
|
];
|
|
212
212
|
|
|
213
|
-
objBST.addMany(
|
|
214
|
-
values.map(item => item.key),
|
|
215
|
-
values,
|
|
216
|
-
false
|
|
217
|
-
);
|
|
213
|
+
objBST.addMany(values, false);
|
|
218
214
|
|
|
219
215
|
expect(objBST.root).toBeInstanceOf(BSTNode);
|
|
220
216
|
|
|
@@ -395,12 +391,12 @@ describe('BST operations test', () => {
|
|
|
395
391
|
|
|
396
392
|
describe('BST operations test recursively', () => {
|
|
397
393
|
it('should perform various operations on a Binary Search Tree with numeric values', () => {
|
|
398
|
-
const bst = new BST({ iterationType: IterationType.RECURSIVE });
|
|
394
|
+
const bst = new BST<number>([], { iterationType: IterationType.RECURSIVE });
|
|
399
395
|
expect(bst).toBeInstanceOf(BST);
|
|
400
|
-
bst.add(11, 11);
|
|
401
|
-
bst.add(3, 3);
|
|
396
|
+
bst.add([11, 11]);
|
|
397
|
+
bst.add([3, 3]);
|
|
402
398
|
const idsAndValues = [15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
403
|
-
bst.addMany(idsAndValues,
|
|
399
|
+
bst.addMany(idsAndValues, false);
|
|
404
400
|
expect(bst.root).toBeInstanceOf(BSTNode);
|
|
405
401
|
|
|
406
402
|
if (bst.root) expect(bst.root.key).toBe(11);
|
|
@@ -414,11 +410,11 @@ describe('BST operations test recursively', () => {
|
|
|
414
410
|
expect(node6 && bst.getDepth(6)).toBe(3);
|
|
415
411
|
|
|
416
412
|
const nodeId10 = bst.getNode(10);
|
|
417
|
-
expect(bst.get(10)).toBe(
|
|
413
|
+
expect(bst.get(10)).toBe(undefined);
|
|
418
414
|
expect(nodeId10?.key).toBe(10);
|
|
419
415
|
|
|
420
416
|
const nodeVal9 = bst.getNode(9, node => node.value);
|
|
421
|
-
expect(nodeVal9?.key).toBe(
|
|
417
|
+
expect(nodeVal9?.key).toBe(undefined);
|
|
422
418
|
|
|
423
419
|
const leftMost = bst.getLeftMost();
|
|
424
420
|
expect(leftMost?.key).toBe(1);
|
|
@@ -582,27 +578,26 @@ describe('BST operations test recursively', () => {
|
|
|
582
578
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
583
579
|
const objBST = new BST<{ key: number; keyA: number }>();
|
|
584
580
|
expect(objBST).toBeInstanceOf(BST);
|
|
585
|
-
objBST.add(11, { key: 11, keyA: 11 });
|
|
586
|
-
objBST.add(3, { key: 3, keyA: 3 });
|
|
587
|
-
const values = [
|
|
588
|
-
{ key: 15, keyA: 15 },
|
|
589
|
-
{ key: 1, keyA: 1 },
|
|
590
|
-
{ key: 8, keyA: 8 },
|
|
591
|
-
{ key: 13, keyA: 13 },
|
|
592
|
-
{ key: 16, keyA: 16 },
|
|
593
|
-
{ key: 2, keyA: 2 },
|
|
594
|
-
{ key: 6, keyA: 6 },
|
|
595
|
-
{ key: 9, keyA: 9 },
|
|
596
|
-
{ key: 12, keyA: 12 },
|
|
597
|
-
{ key: 14, keyA: 14 },
|
|
598
|
-
{ key: 4, keyA: 4 },
|
|
599
|
-
{ key: 7, keyA: 7 },
|
|
600
|
-
{ key: 10, keyA: 10 },
|
|
601
|
-
{ key: 5, keyA: 5 }
|
|
581
|
+
objBST.add([11, { key: 11, keyA: 11 }]);
|
|
582
|
+
objBST.add([3, { key: 3, keyA: 3 }]);
|
|
583
|
+
const values: [number, { key: number; keyA: number }][] = [
|
|
584
|
+
[15, { key: 15, keyA: 15 }],
|
|
585
|
+
[1, { key: 1, keyA: 1 }],
|
|
586
|
+
[8, { key: 8, keyA: 8 }],
|
|
587
|
+
[13, { key: 13, keyA: 13 }],
|
|
588
|
+
[16, { key: 16, keyA: 16 }],
|
|
589
|
+
[2, { key: 2, keyA: 2 }],
|
|
590
|
+
[6, { key: 6, keyA: 6 }],
|
|
591
|
+
[9, { key: 9, keyA: 9 }],
|
|
592
|
+
[12, { key: 12, keyA: 12 }],
|
|
593
|
+
[14, { key: 14, keyA: 14 }],
|
|
594
|
+
[4, { key: 4, keyA: 4 }],
|
|
595
|
+
[7, { key: 7, keyA: 7 }],
|
|
596
|
+
[10, { key: 10, keyA: 10 }],
|
|
597
|
+
[5, { key: 5, keyA: 5 }]
|
|
602
598
|
];
|
|
603
599
|
|
|
604
600
|
objBST.addMany(
|
|
605
|
-
values.map(item => item.key),
|
|
606
601
|
values,
|
|
607
602
|
false
|
|
608
603
|
);
|
|
@@ -834,7 +829,7 @@ describe('BST Performance test', function () {
|
|
|
834
829
|
|
|
835
830
|
it('should the lastKey of a BST to be the largest key', function () {
|
|
836
831
|
const bst = new BST();
|
|
837
|
-
bst.addMany([9, 8, 7, 3, 1, 2, 5, 4, 6],
|
|
832
|
+
bst.addMany([9, 8, 7, 3, 1, 2, 5, 4, 6], false);
|
|
838
833
|
expect(bst.lastKey()).toBe(9);
|
|
839
834
|
});
|
|
840
835
|
|
|
@@ -856,9 +851,9 @@ describe('BST iterative methods test', () => {
|
|
|
856
851
|
let bst: BST<string>;
|
|
857
852
|
beforeEach(() => {
|
|
858
853
|
bst = new BST();
|
|
859
|
-
bst.add(1, 'a');
|
|
860
|
-
bst.add(2, 'b');
|
|
861
|
-
bst.add(3, 'c');
|
|
854
|
+
bst.add([1, 'a']);
|
|
855
|
+
bst.add([2, 'b']);
|
|
856
|
+
bst.add([3, 'c']);
|
|
862
857
|
});
|
|
863
858
|
|
|
864
859
|
test('The node obtained by get Node should match the node type', () => {
|