data-structure-typed 1.45.0 → 1.45.1

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.
Files changed (144) hide show
  1. package/.eslintrc.js +6 -6
  2. package/CHANGELOG.md +1 -1
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  4. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  6. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  9. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  10. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  11. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  13. package/dist/cjs/data-structures/hash/hash-map.d.ts +58 -58
  14. package/dist/cjs/data-structures/hash/hash-map.js +73 -73
  15. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  16. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  17. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  18. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  19. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  20. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  21. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  22. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  23. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  24. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  25. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  26. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  27. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  28. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  29. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  30. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  31. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  32. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  33. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  34. package/dist/cjs/utils/utils.js.map +1 -1
  35. package/dist/mjs/data-structures/hash/hash-map.d.ts +58 -58
  36. package/dist/mjs/data-structures/hash/hash-map.js +76 -76
  37. package/dist/umd/data-structure-typed.js +74 -72
  38. package/dist/umd/data-structure-typed.min.js +1 -1
  39. package/dist/umd/data-structure-typed.min.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/data-structures/binary-tree/avl-tree.ts +7 -7
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
  43. package/src/data-structures/binary-tree/binary-tree.ts +39 -31
  44. package/src/data-structures/binary-tree/bst.ts +12 -8
  45. package/src/data-structures/binary-tree/rb-tree.ts +17 -6
  46. package/src/data-structures/binary-tree/segment-tree.ts +1 -1
  47. package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
  48. package/src/data-structures/graph/abstract-graph.ts +46 -31
  49. package/src/data-structures/graph/directed-graph.ts +10 -5
  50. package/src/data-structures/graph/map-graph.ts +8 -8
  51. package/src/data-structures/graph/undirected-graph.ts +9 -9
  52. package/src/data-structures/hash/hash-map.ts +103 -103
  53. package/src/data-structures/hash/hash-table.ts +1 -1
  54. package/src/data-structures/hash/tree-map.ts +2 -1
  55. package/src/data-structures/hash/tree-set.ts +2 -1
  56. package/src/data-structures/heap/heap.ts +8 -5
  57. package/src/data-structures/heap/max-heap.ts +3 -3
  58. package/src/data-structures/heap/min-heap.ts +3 -3
  59. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  60. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  61. package/src/data-structures/matrix/matrix.ts +2 -2
  62. package/src/data-structures/matrix/matrix2d.ts +1 -1
  63. package/src/data-structures/matrix/navigator.ts +3 -3
  64. package/src/data-structures/matrix/vector2d.ts +2 -1
  65. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
  66. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
  67. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  68. package/src/data-structures/queue/deque.ts +5 -4
  69. package/src/data-structures/queue/queue.ts +2 -2
  70. package/src/data-structures/tree/tree.ts +1 -1
  71. package/src/data-structures/trie/trie.ts +1 -1
  72. package/src/interfaces/binary-tree.ts +2 -2
  73. package/src/interfaces/graph.ts +1 -1
  74. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  75. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  76. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  77. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
  78. package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
  79. package/src/types/data-structures/hash/hash-map.ts +6 -6
  80. package/src/types/data-structures/matrix/navigator.ts +1 -1
  81. package/src/types/utils/utils.ts +1 -1
  82. package/src/types/utils/validate-type.ts +18 -4
  83. package/src/utils/utils.ts +6 -6
  84. package/test/integration/all-in-one.ts +1 -1
  85. package/test/integration/avl-tree.test.ts +1 -1
  86. package/test/integration/bst.test.ts +19 -19
  87. package/test/integration/heap.test.js +1 -1
  88. package/test/integration/index.html +7 -7
  89. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
  90. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
  91. package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
  92. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +6 -6
  93. package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
  94. package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
  95. package/test/performance/data-structures/heap/heap.test.ts +5 -5
  96. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
  97. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
  98. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
  99. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +7 -7
  100. package/test/performance/data-structures/queue/deque.test.ts +5 -5
  101. package/test/performance/data-structures/queue/queue.test.ts +6 -6
  102. package/test/performance/data-structures/stack/stack.test.ts +6 -6
  103. package/test/performance/data-structures/trie/trie.test.ts +4 -4
  104. package/test/performance/reportor.ts +15 -13
  105. package/test/performance/types/reportor.ts +1 -1
  106. package/test/types/utils/json2html.ts +1 -1
  107. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
  108. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
  109. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
  110. package/test/unit/data-structures/binary-tree/bst.test.ts +44 -40
  111. package/test/unit/data-structures/binary-tree/overall.test.ts +17 -17
  112. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
  113. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
  114. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +35 -35
  115. package/test/unit/data-structures/graph/abstract-graph.test.ts +7 -7
  116. package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
  117. package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
  118. package/test/unit/data-structures/graph/overall.test.ts +1 -1
  119. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  120. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  121. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  122. package/test/unit/data-structures/hash/hash-map.test.ts +10 -12
  123. package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
  124. package/test/unit/data-structures/heap/heap.test.ts +35 -23
  125. package/test/unit/data-structures/heap/max-heap.test.ts +2 -2
  126. package/test/unit/data-structures/heap/min-heap.test.ts +2 -2
  127. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +5 -5
  128. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +5 -5
  129. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  130. package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
  131. package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
  132. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  133. package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
  134. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
  135. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  136. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -19
  137. package/test/unit/data-structures/queue/deque.test.ts +3 -3
  138. package/test/unit/data-structures/queue/queue.test.ts +3 -3
  139. package/test/unit/data-structures/stack/stack.test.ts +1 -1
  140. package/test/unit/data-structures/tree/tree.test.ts +1 -1
  141. package/test/unit/data-structures/trie/trie.test.ts +1 -1
  142. package/test/utils/array.ts +1 -1
  143. package/test/utils/big-o.ts +4 -4
  144. package/test/utils/json2html.ts +7 -3
@@ -2,8 +2,8 @@ import * as Benchmark from 'benchmark';
2
2
  import * as path from 'path';
3
3
  import * as fs from 'fs';
4
4
  import * as fastGlob from 'fast-glob';
5
- import {Color, numberFix, render} from '../utils';
6
- import {PerformanceTest} from './types';
5
+ import { Color, numberFix, render } from '../utils';
6
+ import { PerformanceTest } from './types';
7
7
 
8
8
  const parentDirectory = path.resolve(__dirname, '../..');
9
9
  const reportDistPath = path.join(parentDirectory, 'benchmark');
@@ -11,22 +11,22 @@ const reportDistPath = path.join(parentDirectory, 'benchmark');
11
11
  const testDir = path.join(__dirname, 'data-structures');
12
12
  const testFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts'));
13
13
 
14
- const report: {[key: string]: any} = {};
14
+ const report: { [key: string]: any } = {};
15
15
 
16
16
  let completedCount = 0;
17
17
 
18
18
  const performanceTests: PerformanceTest[] = [];
19
- const {GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW} = Color;
19
+ const { GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW } = Color;
20
20
 
21
21
  testFiles.forEach((file: string) => {
22
22
  const testName = path.basename(file, '.test.ts');
23
23
  const testFunction = require(file);
24
- const {suite} = testFunction;
25
- if (suite) performanceTests.push({testName, suite, file});
24
+ const { suite } = testFunction;
25
+ if (suite) performanceTests.push({ testName, suite, file });
26
26
  });
27
27
 
28
28
  const composeReport = () => {
29
- if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, {recursive: true});
29
+ if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, { recursive: true });
30
30
 
31
31
  const filePath = path.join(reportDistPath, 'report.json');
32
32
  const htmlFilePath = path.join(reportDistPath, 'report.html');
@@ -85,9 +85,9 @@ const composeReport = () => {
85
85
  {
86
86
  '<>': 'tr',
87
87
  html: [
88
- {'<>': 'td', html: '${name}'},
89
- {'<>': 'td', html: '${periodMS}'},
90
- {'<>': 'td', html: '${mean}'}
88
+ { '<>': 'td', html: '${name}' },
89
+ { '<>': 'td', html: '${periodMS}' },
90
+ { '<>': 'td', html: '${mean}' }
91
91
  ]
92
92
  }
93
93
  ]
@@ -142,7 +142,7 @@ function replaceMarkdownContent(startMarker: string, endMarker: string, newText:
142
142
  }
143
143
 
144
144
  performanceTests.forEach(item => {
145
- const {suite, testName, file} = item;
145
+ const { suite, testName, file } = item;
146
146
  const relativeFilePath = path.relative(__dirname, file);
147
147
  const directory = path.dirname(relativeFilePath);
148
148
  const fileName = path.basename(relativeFilePath);
@@ -173,13 +173,15 @@ performanceTests.forEach(item => {
173
173
  console.log(
174
174
  // `Files: ${GREEN}${testFileCount}${END} `,
175
175
  // `Suites: ${GREEN}${performanceTests.length}${END} `,
176
- `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${performanceTests.length}${END}`,
176
+ `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${
177
+ performanceTests.length
178
+ }${END}`,
177
179
  `Time: ${isTimeWarn ? YELLOW : GREEN}${runTime}s${END}`
178
180
  );
179
181
  if (isDone) {
180
182
  composeReport();
181
183
  }
182
184
  })
183
- .run({async: false});
185
+ .run({ async: false });
184
186
  }
185
187
  });
@@ -1,3 +1,3 @@
1
1
  import * as Benchmark from 'benchmark';
2
2
 
3
- export type PerformanceTest = {testName: string; suite: Benchmark.Suite; file: string};
3
+ export type PerformanceTest = { testName: string; suite: Benchmark.Suite; file: string };
@@ -1 +1 @@
1
- export type Json2htmlOptions = {plainHtml?: boolean} & Partial<{[key: string]: any}>;
1
+ export type Json2htmlOptions = { plainHtml?: boolean } & Partial<{ [key: string]: any }>;
@@ -1,4 +1,4 @@
1
- import {AVLTree, AVLTreeNode, CP, IterationType} from '../../../../src';
1
+ import { AVLTree, AVLTreeNode, CP, IterationType } from '../../../../src';
2
2
 
3
3
  describe('AVL Tree Test', () => {
4
4
  it('should perform various operations on a AVL Tree', () => {
@@ -112,7 +112,7 @@ 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
117
  for (const i of arr) tree.add(i, i);
118
118
 
@@ -228,9 +228,9 @@ describe('AVLTree APIs test', () => {
228
228
  avl.add(1);
229
229
  const node2 = new AVLTreeNode(2);
230
230
  avl.add(node2);
231
- const node3 = new AVLTreeNode(3, {id: 3, text: 'text3'});
231
+ const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
232
232
  avl.add(node3);
233
- avl.add(node3, {id: 3, text: 'text33'});
233
+ avl.add(node3, { id: 3, text: 'text33' });
234
234
 
235
235
  const bfsRes = avl.bfs(node => node.key);
236
236
  expect(bfsRes[0]).toBe(2);
@@ -277,9 +277,9 @@ describe('AVLTree', () => {
277
277
  avl.add(1);
278
278
  const node2 = new AVLTreeNode(2);
279
279
  avl.add(node2);
280
- const node3 = new AVLTreeNode(3, {id: 3, text: 'text3'});
280
+ const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
281
281
  avl.add(node3);
282
- avl.add(node3, {id: 3, text: 'text33'});
282
+ avl.add(node3, { id: 3, text: 'text33' });
283
283
 
284
284
  const bfsRes = avl.bfs(node => node);
285
285
  expect(bfsRes[0]?.key).toBe(2);
@@ -1,4 +1,4 @@
1
- import {BinaryIndexedTree} from '../../../../src';
1
+ import { BinaryIndexedTree } from '../../../../src';
2
2
  // import {isDebugTest} from '../../../config';
3
3
 
4
4
  // const isDebug = isDebugTest;
@@ -8,13 +8,13 @@ describe('BinaryIndexedTree simple', () => {
8
8
 
9
9
  beforeEach(() => {
10
10
  //Create a new BinaryIndexedTree instance before each test case
11
- bit = new BinaryIndexedTree({frequency: 0, max: 10}); // Modify the value of max as needed
11
+ bit = new BinaryIndexedTree({ frequency: 0, max: 10 }); // Modify the value of max as needed
12
12
  });
13
13
 
14
14
  it('should initialize correctly', () => {
15
15
  expect(bit.freq).toBe(0);
16
16
  expect(bit.max).toBe(10);
17
- expect(bit.freqMap).toEqual({0: 0}); // Modify the initialized record value according to the actual situation
17
+ expect(bit.freqMap).toEqual({ 0: 0 }); // Modify the initialized record value according to the actual situation
18
18
  // More initialization checks can be added
19
19
  });
20
20
 
@@ -54,7 +54,7 @@ describe('BinaryIndexedTree', () => {
54
54
  let bit: BinaryIndexedTree;
55
55
 
56
56
  beforeEach(function () {
57
- bit = new BinaryIndexedTree({frequency, max});
57
+ bit = new BinaryIndexedTree({ frequency, max });
58
58
  });
59
59
  it('should validate the index', function () {
60
60
  expect(() => bit.readSingle(-1)).toThrow('Index out of range');
@@ -73,7 +73,7 @@ describe('BinaryIndexedTree', () => {
73
73
  it('should frequency and max', function () {
74
74
  const frequency = 200;
75
75
  const max = 1000;
76
- const bit = new BinaryIndexedTree({frequency, max});
76
+ const bit = new BinaryIndexedTree({ frequency, max });
77
77
 
78
78
  expect(bit.freq).toBe(frequency);
79
79
  expect(bit.max).toBe(max);
@@ -123,7 +123,7 @@ describe('designated values', function () {
123
123
  let bit: BinaryIndexedTree;
124
124
 
125
125
  beforeEach(function () {
126
- bit = new BinaryIndexedTree({max: array.length});
126
+ bit = new BinaryIndexedTree({ max: array.length });
127
127
  array.forEach((value, i) => bit.writeSingle(i, value));
128
128
  });
129
129
 
@@ -182,7 +182,7 @@ describe('descending sequence', function () {
182
182
  let bit: BinaryIndexedTree;
183
183
 
184
184
  beforeEach(function () {
185
- bit = new BinaryIndexedTree({max: array.length});
185
+ bit = new BinaryIndexedTree({ max: array.length });
186
186
  array.forEach((value, i) => bit.writeSingle(i, value));
187
187
  });
188
188
 
@@ -219,7 +219,7 @@ describe('descending sequence', function () {
219
219
 
220
220
  describe('BinaryIndexedTree additional tests', () => {
221
221
  it('should handle read method correctly', () => {
222
- const bit = new BinaryIndexedTree({max: 10});
222
+ const bit = new BinaryIndexedTree({ max: 10 });
223
223
  bit.writeSingle(2, 10);
224
224
  bit.writeSingle(5, 20);
225
225
  bit.writeSingle(8, 30);
@@ -227,7 +227,7 @@ describe('BinaryIndexedTree additional tests', () => {
227
227
  });
228
228
 
229
229
  it('should handle consecutive operations', () => {
230
- const bit = new BinaryIndexedTree({max: 10});
230
+ const bit = new BinaryIndexedTree({ max: 10 });
231
231
  bit.writeSingle(2, 10);
232
232
  bit.update(2, 5);
233
233
  expect(bit.readSingle(2)).toBe(15);
@@ -237,7 +237,7 @@ describe('BinaryIndexedTree additional tests', () => {
237
237
  });
238
238
 
239
239
  it('should handle frequent increment updates', () => {
240
- const bit = new BinaryIndexedTree({max: 10});
240
+ const bit = new BinaryIndexedTree({ max: 10 });
241
241
  for (let i = 0; i < 10; i++) {
242
242
  bit.update(2, 5);
243
243
  }
@@ -245,7 +245,7 @@ describe('BinaryIndexedTree additional tests', () => {
245
245
  });
246
246
 
247
247
  it('should handle edge cases', () => {
248
- const bit = new BinaryIndexedTree({max: 10});
248
+ const bit = new BinaryIndexedTree({ max: 10 });
249
249
  bit.writeSingle(9, 100);
250
250
  expect(bit.readSingle(9)).toBe(100);
251
251
  expect(bit.lowerBound(200)).toBe(10);
@@ -291,7 +291,7 @@ describe('', () => {
291
291
 
292
292
  constructor(nums: number[]) {
293
293
  this._nums = nums;
294
- this._tree = new BinaryIndexedTree({max: nums.length + 1});
294
+ this._tree = new BinaryIndexedTree({ max: nums.length + 1 });
295
295
  for (let i = 0; i < nums.length; i++) {
296
296
  this._tree.update(i + 1, nums[i]);
297
297
  }
@@ -1,6 +1,6 @@
1
- import {BinaryTree, BinaryTreeNode, IterationType} from '../../../../src';
2
- import {getRandomIntArray} from '../../../utils';
3
- import {FamilyPosition} from 'binary-tree-typed';
1
+ import { BinaryTree, BinaryTreeNode, IterationType } from '../../../../src';
2
+ import { getRandomIntArray } from '../../../utils';
3
+ import { FamilyPosition } from 'binary-tree-typed';
4
4
  // import {isDebugTest} from '../../../config';
5
5
 
6
6
  // const isDebug = isDebugTest;
@@ -242,8 +242,12 @@ describe('BinaryTree', () => {
242
242
  tree.addMany([4, 2, 6, null, 1, 3, null, 5, null, 7]);
243
243
  expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]);
244
244
  expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]);
245
- expect(tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true)).toEqual([6, 3, 7, null]);
246
- expect(tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true)).toEqual([6, 3, 7, null]);
245
+ expect(
246
+ tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true)
247
+ ).toEqual([6, 3, 7, null]);
248
+ expect(
249
+ tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true)
250
+ ).toEqual([6, 3, 7, null]);
247
251
  });
248
252
 
249
253
  it('should clear the tree', () => {
@@ -315,81 +319,41 @@ describe('BinaryTree traversals', () => {
315
319
 
316
320
  const arr = [35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55];
317
321
  tree.refill(arr);
318
- expect(tree.bfs(node => node, tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null))).toEqual([
319
- 35,
320
- 20,
321
- 40,
322
- 15,
323
- 29,
324
- null,
325
- 50,
326
- null,
327
- 16,
328
- 28,
329
- 30,
330
- 45,
331
- 55
332
- ]);
333
- expect(tree.bfs(node => node, tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null))).toEqual([
334
- 35,
335
- 20,
336
- 40,
337
- 15,
338
- 29,
339
- null,
340
- 50,
341
- null,
342
- 16,
343
- 28,
344
- 30,
345
- 45,
346
- 55
347
- ]);
348
- expect(tree.bfs(node => node, tree.root, IterationType.ITERATIVE).map(node => (node === null ? null : node.key))).toEqual([
349
- 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55
350
- ]);
351
- expect(tree.bfs(node => node, tree.root, IterationType.RECURSIVE).map(node => (node === null ? null : node.key))).toEqual([
352
- 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55
353
- ]);
322
+ expect(
323
+ tree.bfs(node => node, tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null))
324
+ ).toEqual([35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]);
325
+ expect(
326
+ tree.bfs(node => node, tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null))
327
+ ).toEqual([35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]);
328
+ expect(
329
+ tree.bfs(node => node, tree.root, IterationType.ITERATIVE).map(node => (node === null ? null : node.key))
330
+ ).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]);
331
+ expect(
332
+ tree.bfs(node => node, tree.root, IterationType.RECURSIVE).map(node => (node === null ? null : node.key))
333
+ ).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]);
354
334
 
355
335
  expect(tree.dfs(node => node.key, 'pre')).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]);
356
- expect(tree.dfs(node => node.key, 'pre', tree.root, IterationType.RECURSIVE)).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]);
357
- expect(tree.dfs(node => node, 'pre', tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null))).toEqual([
358
- 35,
359
- 20,
360
- 15,
361
- null,
362
- 16,
363
- 29,
364
- 28,
365
- 30,
366
- 40,
367
- null,
368
- 50,
369
- 45,
370
- 55
371
- ]);
372
- expect(tree.dfs(node => node, 'pre', tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null))).toEqual([
373
- 35,
374
- 20,
375
- 15,
376
- null,
377
- 16,
378
- 29,
379
- 28,
380
- 30,
381
- 40,
382
- null,
383
- 50,
384
- 45,
385
- 55
336
+ expect(tree.dfs(node => node.key, 'pre', tree.root, IterationType.RECURSIVE)).toEqual([
337
+ 35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55
386
338
  ]);
339
+ expect(
340
+ tree.dfs(node => node, 'pre', tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null))
341
+ ).toEqual([35, 20, 15, null, 16, 29, 28, 30, 40, null, 50, 45, 55]);
342
+ expect(
343
+ tree.dfs(node => node, 'pre', tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null))
344
+ ).toEqual([35, 20, 15, null, 16, 29, 28, 30, 40, null, 50, 45, 55]);
387
345
 
388
346
  expect(tree.dfs(node => node.key, 'in')).toEqual([15, 16, 20, 28, 29, 30, 35, 40, 45, 50, 55]);
389
347
  expect(tree.dfs(node => node.key, 'post')).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]);
390
- expect(tree.dfs(node => node.key, 'post', tree.root, IterationType.RECURSIVE)).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]);
391
- expect(tree.bfs(node => node.key, tree.root, IterationType.RECURSIVE)).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]);
392
- expect(tree.bfs(node => node.key, tree.root, IterationType.ITERATIVE)).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]);
348
+ expect(tree.dfs(node => node.key, 'post', tree.root, IterationType.RECURSIVE)).toEqual([
349
+ 16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35
350
+ ]);
351
+ expect(tree.bfs(node => node.key, tree.root, IterationType.RECURSIVE)).toEqual([
352
+ 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55
353
+ ]);
354
+ expect(tree.bfs(node => node.key, tree.root, IterationType.ITERATIVE)).toEqual([
355
+ 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55
356
+ ]);
393
357
 
394
358
  expect(tree.listLevels(node => node.key)).toEqual([[35], [20, 40], [15, 29, 50], [16, 28, 30, 45, 55]]);
395
359
 
@@ -417,7 +381,7 @@ describe('BinaryTree', () => {
417
381
  let tree: BinaryTree<string>;
418
382
 
419
383
  beforeEach(() => {
420
- tree = new BinaryTree<string>({iterationType: IterationType.RECURSIVE});
384
+ tree = new BinaryTree<string>({ iterationType: IterationType.RECURSIVE });
421
385
  });
422
386
 
423
387
  afterEach(() => {
@@ -560,7 +524,13 @@ describe('BinaryTree', () => {
560
524
  expect(nodes.length).toBe(1);
561
525
  expect(nodes[0].key).toBe(3);
562
526
 
563
- const nodesRec = tree.getNodes('B', (node: BinaryTreeNode<string>) => node.value, false, tree.root, IterationType.RECURSIVE);
527
+ const nodesRec = tree.getNodes(
528
+ 'B',
529
+ (node: BinaryTreeNode<string>) => node.value,
530
+ false,
531
+ tree.root,
532
+ IterationType.RECURSIVE
533
+ );
564
534
 
565
535
  expect(nodesRec.length).toBe(1);
566
536
  expect(nodesRec[0].key).toBe(3);
@@ -1,5 +1,5 @@
1
- import {BST, BSTNode, CP, IterationType} from '../../../../src';
2
- import {isDebugTest} from '../../../config';
1
+ import { BST, BSTNode, CP, IterationType } from '../../../../src';
2
+ import { isDebugTest } from '../../../config';
3
3
 
4
4
  const isDebug = isDebugTest;
5
5
 
@@ -191,23 +191,23 @@ 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});
194
+ objBST.add(11, { key: 11, keyA: 11 });
195
+ objBST.add(3, { key: 3, keyA: 3 });
196
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}
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 }
211
211
  ];
212
212
 
213
213
  objBST.addMany(
@@ -236,7 +236,7 @@ describe('BST operations test', () => {
236
236
  expect(leftMost?.key).toBe(1);
237
237
 
238
238
  const node15 = objBST.getNode(15);
239
- expect(node15?.value).toEqual({key: 15, keyA: 15});
239
+ expect(node15?.value).toEqual({ key: 15, keyA: 15 });
240
240
  const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
241
241
  expect(minNodeBySpecificNode?.key).toBe(12);
242
242
 
@@ -395,7 +395,7 @@ describe('BST operations test', () => {
395
395
 
396
396
  describe('BST operations test recursively', () => {
397
397
  it('should perform various operations on a Binary Search Tree with numeric values', () => {
398
- const bst = new BST({iterationType: IterationType.RECURSIVE});
398
+ const bst = new BST({ iterationType: IterationType.RECURSIVE });
399
399
  expect(bst).toBeInstanceOf(BST);
400
400
  bst.add(11, 11);
401
401
  bst.add(3, 3);
@@ -582,23 +582,23 @@ describe('BST operations test recursively', () => {
582
582
  it('should perform various operations on a Binary Search Tree with object values', () => {
583
583
  const objBST = new BST<{ key: number; keyA: number }>();
584
584
  expect(objBST).toBeInstanceOf(BST);
585
- objBST.add(11, {key: 11, keyA: 11});
586
- objBST.add(3, {key: 3, keyA: 3});
585
+ objBST.add(11, { key: 11, keyA: 11 });
586
+ objBST.add(3, { key: 3, keyA: 3 });
587
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}
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 }
602
602
  ];
603
603
 
604
604
  objBST.addMany(
@@ -614,7 +614,7 @@ describe('BST operations test recursively', () => {
614
614
  expect(objBST.has(6)).toBe(true);
615
615
 
616
616
  const node6 = objBST.getNode(6);
617
- expect(objBST.get(6)).toEqual({key: 6, keyA: 6});
617
+ expect(objBST.get(6)).toEqual({ key: 6, keyA: 6 });
618
618
  expect(node6 && objBST.getHeight(node6)).toBe(2);
619
619
  expect(node6 && objBST.getDepth(node6)).toBe(3);
620
620
 
@@ -628,7 +628,7 @@ describe('BST operations test recursively', () => {
628
628
  expect(leftMost?.key).toBe(1);
629
629
 
630
630
  const node15 = objBST.getNode(15);
631
- expect(node15?.value).toEqual({key: 15, keyA: 15});
631
+ expect(node15?.value).toEqual({ key: 15, keyA: 15 });
632
632
  const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
633
633
  expect(minNodeBySpecificNode?.key).toBe(12);
634
634
 
@@ -843,7 +843,11 @@ describe('BST Performance test', function () {
843
843
  bst.addMany([4, 2, 6, 1, 3, 5, 7]);
844
844
  expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.ITERATIVE)).toEqual([6, 5, 7]);
845
845
  expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.RECURSIVE)).toEqual([6, 5, 7]);
846
- expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.ITERATIVE, true)).toEqual([6, 5, 7]);
847
- expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.RECURSIVE, true)).toEqual([6, 5, 7]);
846
+ expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.ITERATIVE, true)).toEqual([
847
+ 6, 5, 7
848
+ ]);
849
+ expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.RECURSIVE, true)).toEqual([
850
+ 6, 5, 7
851
+ ]);
848
852
  });
849
853
  });
@@ -1,4 +1,4 @@
1
- import {AVLTree, BST} from '../../../../src';
1
+ import { AVLTree, BST } from '../../../../src';
2
2
 
3
3
  describe('Overall BinaryTree Test', () => {
4
4
  it('should perform various operations on BinaryTree', () => {
@@ -30,26 +30,26 @@ describe('Overall BinaryTree Test', () => {
30
30
  expect(bfsIDs[0]).toBe(11);
31
31
 
32
32
  const objBST = new BST<{ key: number; keyA: number }>();
33
- objBST.add(11, {key: 11, keyA: 11});
34
- objBST.add(3, {key: 3, keyA: 3});
33
+ objBST.add(11, { key: 11, keyA: 11 });
34
+ objBST.add(3, { key: 3, keyA: 3 });
35
35
 
36
36
  objBST.addMany(
37
37
  [15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5],
38
38
  [
39
- {key: 15, keyA: 15},
40
- {key: 1, keyA: 1},
41
- {key: 8, keyA: 8},
42
- {key: 13, keyA: 13},
43
- {key: 16, keyA: 16},
44
- {key: 2, keyA: 2},
45
- {key: 6, keyA: 6},
46
- {key: 9, keyA: 9},
47
- {key: 12, keyA: 12},
48
- {key: 14, keyA: 14},
49
- {key: 4, keyA: 4},
50
- {key: 7, keyA: 7},
51
- {key: 10, keyA: 10},
52
- {key: 5, keyA: 5}
39
+ { key: 15, keyA: 15 },
40
+ { key: 1, keyA: 1 },
41
+ { key: 8, keyA: 8 },
42
+ { key: 13, keyA: 13 },
43
+ { key: 16, keyA: 16 },
44
+ { key: 2, keyA: 2 },
45
+ { key: 6, keyA: 6 },
46
+ { key: 9, keyA: 9 },
47
+ { key: 12, keyA: 12 },
48
+ { key: 14, keyA: 14 },
49
+ { key: 4, keyA: 4 },
50
+ { key: 7, keyA: 7 },
51
+ { key: 10, keyA: 10 },
52
+ { key: 5, keyA: 5 }
53
53
  ]
54
54
  );
55
55
 
@@ -1,7 +1,7 @@
1
- import {IterationType, RBTNColor, RedBlackTree, RedBlackTreeNode} from '../../../../src';
2
- import {getRandomInt, getRandomIntArray, magnitude} from '../../../utils';
3
- import {isDebugTest} from '../../../config';
4
- import {OrderedMap} from 'js-sdsl';
1
+ import { IterationType, RBTNColor, RedBlackTree, RedBlackTreeNode } from '../../../../src';
2
+ import { getRandomInt, getRandomIntArray, magnitude } from '../../../utils';
3
+ import { isDebugTest } from '../../../config';
4
+ import { OrderedMap } from 'js-sdsl';
5
5
 
6
6
  const isDebug = isDebugTest;
7
7
 
@@ -438,12 +438,12 @@ describe('RedBlackTree', () => {
438
438
  expect(tree.size).toBe(51);
439
439
  expect(tree.isBST()).toBe(true);
440
440
  expect(tree.dfs(n => n.key, 'in', tree.root, IterationType.ITERATIVE)).toEqual([
441
- 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
442
- 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
441
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
442
+ 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
443
443
  ]);
444
444
  expect(tree.dfs(n => n.key, 'in', tree.root, IterationType.RECURSIVE)).toEqual([
445
- 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
446
- 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
445
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
446
+ 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
447
447
  ]);
448
448
  });
449
449
 
@@ -468,7 +468,7 @@ describe('RedBlackTree', () => {
468
468
  // TODO there is a bug when dfs the tree with NIL node
469
469
  // expect(tree.isBST()).toBe(true);
470
470
  });
471
- const {HUNDRED_THOUSAND} = magnitude;
471
+ const { HUNDRED_THOUSAND } = magnitude;
472
472
  const arr = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true);
473
473
  const competitor = new OrderedMap<number, number>();
474
474
 
@@ -1,4 +1,4 @@
1
- import {SegmentTree} from '../../../../src';
1
+ import { SegmentTree } from '../../../../src';
2
2
 
3
3
  describe('SegmentTree', () => {
4
4
  let segmentTree: SegmentTree;