data-structure-typed 1.52.1 → 1.52.3

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 (90) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +162 -162
  5. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  6. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +2 -2
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.js +2 -2
  12. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  16. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  19. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  20. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  21. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  22. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  23. package/dist/cjs/data-structures/queue/queue.d.ts +18 -0
  24. package/dist/cjs/data-structures/queue/queue.js +32 -6
  25. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  26. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  27. package/dist/cjs/data-structures/trie/trie.js +6 -1
  28. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  29. package/dist/cjs/types/data-structures/queue/queue.d.ts +3 -1
  30. package/dist/mjs/data-structures/binary-tree/binary-tree.js +2 -2
  31. package/dist/mjs/data-structures/binary-tree/bst.js +2 -2
  32. package/dist/mjs/data-structures/queue/queue.d.ts +18 -0
  33. package/dist/mjs/data-structures/queue/queue.js +32 -6
  34. package/dist/mjs/data-structures/trie/trie.js +6 -1
  35. package/dist/mjs/types/data-structures/queue/queue.d.ts +3 -1
  36. package/dist/umd/data-structure-typed.js +36 -5
  37. package/dist/umd/data-structure-typed.min.js +2 -2
  38. package/dist/umd/data-structure-typed.min.js.map +1 -1
  39. package/package.json +7 -7
  40. package/src/data-structures/base/iterable-element-base.ts +2 -2
  41. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  42. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -12
  43. package/src/data-structures/binary-tree/avl-tree.ts +9 -8
  44. package/src/data-structures/binary-tree/binary-tree.ts +11 -10
  45. package/src/data-structures/binary-tree/bst.ts +10 -9
  46. package/src/data-structures/binary-tree/rb-tree.ts +8 -7
  47. package/src/data-structures/binary-tree/tree-multi-map.ts +8 -7
  48. package/src/data-structures/graph/abstract-graph.ts +15 -14
  49. package/src/data-structures/graph/directed-graph.ts +7 -6
  50. package/src/data-structures/graph/undirected-graph.ts +7 -6
  51. package/src/data-structures/hash/hash-map.ts +4 -4
  52. package/src/data-structures/heap/heap.ts +1 -1
  53. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  54. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  55. package/src/data-structures/queue/deque.ts +3 -3
  56. package/src/data-structures/queue/queue.ts +38 -7
  57. package/src/data-structures/stack/stack.ts +1 -1
  58. package/src/data-structures/trie/trie.ts +7 -2
  59. package/src/types/data-structures/graph/abstract-graph.ts +8 -8
  60. package/src/types/data-structures/queue/deque.ts +2 -2
  61. package/src/types/data-structures/queue/queue.ts +3 -1
  62. package/src/types/utils/utils.ts +4 -4
  63. package/test/integration/bst.test.ts +4 -1
  64. package/test/performance/data-structures/comparison/comparison.test.ts +12 -4
  65. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +6 -2
  66. package/test/performance/reportor.ts +23 -8
  67. package/test/performance/types/reportor.ts +5 -1
  68. package/test/types/utils/json2html.ts +5 -1
  69. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +6 -2
  70. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +8 -2
  71. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +36 -11
  72. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -1
  73. package/test/unit/data-structures/binary-tree/bst.test.ts +18 -5
  74. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -1
  75. package/test/unit/data-structures/graph/abstract-graph.test.ts +2 -4
  76. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -5
  77. package/test/unit/data-structures/hash/hash-map.test.ts +6 -2
  78. package/test/unit/data-structures/heap/heap.test.ts +45 -13
  79. package/test/unit/data-structures/heap/max-heap.test.ts +10 -3
  80. package/test/unit/data-structures/heap/min-heap.test.ts +3 -1
  81. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +3 -1
  82. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +6 -2
  83. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +22 -6
  84. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +12 -4
  85. package/test/unit/data-structures/queue/deque.test.ts +14 -8
  86. package/test/unit/data-structures/queue/queue.test.ts +14 -1
  87. package/test/unit/data-structures/trie/trie.test.ts +19 -1
  88. package/test/unit/unrestricted-interconversion.test.ts +3 -1
  89. package/test/utils/big-o.ts +3 -1
  90. package/test/utils/json2html.ts +2 -6
@@ -11,10 +11,14 @@ describe('SinglyLinkedListNode', () => {
11
11
 
12
12
  describe('SinglyLinkedList Operation Test', () => {
13
13
  let list: SinglyLinkedList<number>;
14
- let objectList: SinglyLinkedList<{ keyA: number }>;
14
+ let objectList: SinglyLinkedList<{
15
+ keyA: number;
16
+ }>;
15
17
  beforeEach(() => {
16
18
  list = new SinglyLinkedList<number>();
17
- objectList = new SinglyLinkedList<{ keyA: number }>();
19
+ objectList = new SinglyLinkedList<{
20
+ keyA: number;
21
+ }>();
18
22
  });
19
23
 
20
24
  describe('push', () => {
@@ -16,7 +16,11 @@ describe('MaxPriorityQueue Operation Test', () => {
16
16
  });
17
17
 
18
18
  it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
19
- const priorityQueue = new MaxPriorityQueue<{ keyA: number }>([], { comparator: (a, b) => b.keyA - a.keyA });
19
+ const priorityQueue = new MaxPriorityQueue<{
20
+ keyA: number;
21
+ }>([], {
22
+ comparator: (a, b) => b.keyA - a.keyA
23
+ });
20
24
  priorityQueue.refill([{ keyA: 5 }, { keyA: 3 }, { keyA: 1 }]);
21
25
  priorityQueue.add({ keyA: 7 });
22
26
 
@@ -52,7 +56,9 @@ describe('MaxPriorityQueue Operation Test', () => {
52
56
 
53
57
  it('should correctly heapify an array', () => {
54
58
  const array = [5, 3, 7, 1];
55
- const heap = MaxPriorityQueue.heapify<number>(array, { comparator: (a, b) => b - a });
59
+ const heap = MaxPriorityQueue.heapify<number>(array, {
60
+ comparator: (a, b) => b - a
61
+ });
56
62
  heap.refill(array);
57
63
 
58
64
  expect(heap.poll()).toBe(7);
@@ -64,7 +70,11 @@ describe('MaxPriorityQueue Operation Test', () => {
64
70
  it('should correctly heapify an object array', () => {
65
71
  const elements = [{ keyA: 5 }, { keyA: 3 }, { keyA: 7 }, { keyA: 1 }];
66
72
  debugger;
67
- const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>(elements, { comparator: (a, b) => b.keyA - a.keyA });
73
+ const maxPQ = MaxPriorityQueue.heapify<{
74
+ keyA: number;
75
+ }>(elements, {
76
+ comparator: (a, b) => b.keyA - a.keyA
77
+ });
68
78
 
69
79
  expect(maxPQ.poll()?.keyA).toBe(7);
70
80
  expect(maxPQ.poll()?.keyA).toBe(5);
@@ -73,7 +83,9 @@ describe('MaxPriorityQueue Operation Test', () => {
73
83
  });
74
84
 
75
85
  it('should object priority queue', () => {
76
- const maxPQ = new MaxPriorityQueue<{ rawItem: { id: number } }>(
86
+ const maxPQ = new MaxPriorityQueue<{
87
+ rawItem: { id: number };
88
+ }>(
77
89
  [
78
90
  { rawItem: { id: 4 } },
79
91
  { rawItem: { id: 8 } },
@@ -83,7 +95,9 @@ describe('MaxPriorityQueue Operation Test', () => {
83
95
  { rawItem: { id: 3 } },
84
96
  { rawItem: { id: 5 } }
85
97
  ],
86
- { comparator: (a, b) => b.rawItem.id - a.rawItem.id }
98
+ {
99
+ comparator: (a, b) => b.rawItem.id - a.rawItem.id
100
+ }
87
101
  );
88
102
 
89
103
  expect([...maxPQ.sort()]).toEqual([
@@ -108,7 +122,9 @@ describe('MaxPriorityQueue Operation Test', () => {
108
122
  { rawItem: { id: 3 } },
109
123
  { rawItem: { id: 5 } }
110
124
  ],
111
- { toElementFn: rawElement => rawElement.rawItem.id }
125
+ {
126
+ toElementFn: rawElement => rawElement.rawItem.id
127
+ }
112
128
  );
113
129
 
114
130
  expect([...maxPQ.sort()]).toEqual([8, 7, 6, 5, 4, 3, 1]);
@@ -5,7 +5,9 @@ import { isDebugTest } from '../../../config';
5
5
  const isDebug = isDebugTest;
6
6
  describe('PriorityQueue Operation Test', () => {
7
7
  it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
8
- const minPQ = new PriorityQueue<number>([], { comparator: (a, b) => a - b });
8
+ const minPQ = new PriorityQueue<number>([], {
9
+ comparator: (a, b) => a - b
10
+ });
9
11
  minPQ.refill([5, 2, 3, 4, 6, 1]);
10
12
  expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]);
11
13
  minPQ.poll();
@@ -21,7 +23,9 @@ describe('PriorityQueue Operation Test', () => {
21
23
  });
22
24
 
23
25
  it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
24
- const maxPriorityQueue = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
26
+ const maxPriorityQueue = new PriorityQueue<number>([], {
27
+ comparator: (a, b) => b - a
28
+ });
25
29
  maxPriorityQueue.refill([5, 2, 3, 4, 6, 1]);
26
30
  expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
27
31
  maxPriorityQueue.poll();
@@ -37,7 +41,9 @@ describe('PriorityQueue Operation Test', () => {
37
41
  });
38
42
 
39
43
  it('should PriorityQueue clone, sort, getNodes, dfs work well', function () {
40
- const minPQ1 = new PriorityQueue<number>([], { comparator: (a, b) => a - b });
44
+ const minPQ1 = new PriorityQueue<number>([], {
45
+ comparator: (a, b) => a - b
46
+ });
41
47
  minPQ1.refill([2, 5, 8, 3, 1, 6, 7, 4]);
42
48
  const clonedPriorityQueue = minPQ1.clone();
43
49
  expect(clonedPriorityQueue.elements).toEqual(minPQ1.elements);
@@ -50,7 +56,9 @@ describe('PriorityQueue Operation Test', () => {
50
56
 
51
57
  describe('Priority Queue Performance Test', () => {
52
58
  it('should numeric heap work well', function () {
53
- const pq = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
59
+ const pq = new PriorityQueue<number>([], {
60
+ comparator: (a, b) => b - a
61
+ });
54
62
 
55
63
  const tS = performance.now();
56
64
 
@@ -204,8 +204,7 @@ describe('Deque - Complex Operations', () => {
204
204
  expect([...deque]).toEqual([1, 2, 3]);
205
205
  });
206
206
 
207
- test('shrinkToFit should reduce the memory footprint', () => {
208
- });
207
+ test('shrinkToFit should reduce the memory footprint', () => {});
209
208
  });
210
209
  describe('Deque - Utility Operations', () => {
211
210
  let deque: Deque<number>;
@@ -264,7 +263,7 @@ describe('Deque - Utility Operations', () => {
264
263
  test('should maxLen work well', () => {
265
264
  const dequeMaxLen = new Deque([3, 4, 5, 6, 7], { maxLen: 3 });
266
265
  expect(dequeMaxLen.size).toBe(3);
267
- expect(dequeMaxLen.toArray()).toEqual([5, 6 ,7]);
266
+ expect(dequeMaxLen.toArray()).toEqual([5, 6, 7]);
268
267
  dequeMaxLen.unshift(4);
269
268
  dequeMaxLen.unshift(3);
270
269
  expect(dequeMaxLen.size).toBe(3);
@@ -277,7 +276,6 @@ describe('Deque - Utility Operations', () => {
277
276
  dequeNoMaxLen.unshift(3);
278
277
  expect(dequeNoMaxLen.size).toBe(7);
279
278
  expect(dequeNoMaxLen.toArray()).toEqual([3, 4, 3, 4, 5, 6, 7]);
280
-
281
279
  });
282
280
  });
283
281
 
@@ -344,7 +342,9 @@ describe('Deque - push Method', () => {
344
342
  const bucketSize = 10;
345
343
 
346
344
  beforeEach(() => {
347
- deque = new Deque<number>([], { bucketSize });
345
+ deque = new Deque<number>([], {
346
+ bucketSize
347
+ });
348
348
  });
349
349
 
350
350
  test('push should add an element when deque is empty', () => {
@@ -386,7 +386,9 @@ describe('Deque - pop Method', () => {
386
386
  const bucketSize = 10;
387
387
 
388
388
  beforeEach(() => {
389
- deque = new Deque<number>([], { bucketSize });
389
+ deque = new Deque<number>([], {
390
+ bucketSize
391
+ });
390
392
  });
391
393
 
392
394
  test('pop should remove and return the last element', () => {
@@ -417,7 +419,9 @@ describe('Deque - unshift Method', () => {
417
419
  const bucketSize = 10;
418
420
 
419
421
  beforeEach(() => {
420
- deque = new Deque<number>([], { bucketSize });
422
+ deque = new Deque<number>([], {
423
+ bucketSize
424
+ });
421
425
  });
422
426
 
423
427
  test('unshift should add an element to the beginning when deque is empty', () => {
@@ -449,7 +453,9 @@ describe('Deque - shift Method', () => {
449
453
  const bucketSize = 10;
450
454
 
451
455
  beforeEach(() => {
452
- deque = new Deque<number>([], { bucketSize });
456
+ deque = new Deque<number>([], {
457
+ bucketSize
458
+ });
453
459
  });
454
460
 
455
461
  test('shift should remove and return the first element', () => {
@@ -90,6 +90,16 @@ describe('Queue', () => {
90
90
  expect(queue.isEmpty()).toBeTruthy();
91
91
  });
92
92
 
93
+ test('compact method should work well', () => {
94
+ for (let i = 0; i < 1000; i++) queue.push(i);
95
+
96
+ for (let i = 0; i < 499; i++) queue.shift();
97
+
98
+ expect(queue.elements.length).toBe(1000);
99
+ queue.compact();
100
+ expect(queue.elements.length).toBe(501);
101
+ });
102
+
93
103
  test('should at after shifting', () => {
94
104
  for (let i = 0; i < 100; i++) {
95
105
  queue.push(i);
@@ -116,7 +126,10 @@ describe('Queue', () => {
116
126
  });
117
127
 
118
128
  it('should object queue map & filter', function () {
119
- const queue = new Queue<{ a: string; key: number }>([
129
+ const queue = new Queue<{
130
+ a: string;
131
+ key: number;
132
+ }>([
120
133
  { key: 1, a: 'a1' },
121
134
  { key: 6, a: 'a6' },
122
135
  { key: 5, a: 'a5' },
@@ -795,7 +795,9 @@ describe('Trie operations', () => {
795
795
  });
796
796
 
797
797
  it('Case Sensitivity', () => {
798
- const caseInsensitiveTrie = new Trie(['apple', 'Banana'], { caseSensitive: false });
798
+ const caseInsensitiveTrie = new Trie(['apple', 'Banana'], {
799
+ caseSensitive: false
800
+ });
799
801
  expect(caseInsensitiveTrie.has('APPLE')).toBe(true);
800
802
  expect(caseInsensitiveTrie.has('banana')).toBe(true);
801
803
  expect(caseInsensitiveTrie.has('Cherry')).toBe(false);
@@ -834,6 +836,22 @@ describe('Trie operations', () => {
834
836
  expect(words).toEqual(['apple', 'appetizer']);
835
837
  });
836
838
 
839
+ it('Get no words when prefix not found, with no match from the first character', () => {
840
+ trie.add('apple');
841
+ trie.add('appetizer');
842
+ trie.add('banana');
843
+ const words = trie.getWords('cd');
844
+ expect(words).toEqual([]);
845
+ });
846
+
847
+ it('Get no words when prefix not found, with no match from the second character', () => {
848
+ trie.add('apple');
849
+ trie.add('appetizer');
850
+ trie.add('banana');
851
+ const words = trie.getWords('ab');
852
+ expect(words).toEqual([]);
853
+ });
854
+
837
855
  it('Tree Height', () => {
838
856
  trie.add('apple');
839
857
  trie.add('banana');
@@ -245,7 +245,9 @@ describe('conversions', () => {
245
245
  const trie = new Trie(orgStrArr);
246
246
  expect(trie.size).toBe(10);
247
247
  isDebug && trie.print();
248
- const heap = new Heap<string>(trie, { comparator: (a, b) => Number(a) - Number(b) });
248
+ const heap = new Heap<string>(trie, {
249
+ comparator: (a, b) => Number(a) - Number(b)
250
+ });
249
251
  expect(heap.size).toBe(10);
250
252
  isDebug && heap.print();
251
253
  expect([...heap]).toEqual([
@@ -32,7 +32,9 @@ export const bigO = {
32
32
 
33
33
  function findPotentialN(input: any): number {
34
34
  let longestArray: any[] = [];
35
- let mostProperties: { [key: string]: any } = {};
35
+ let mostProperties: {
36
+ [key: string]: any;
37
+ } = {};
36
38
 
37
39
  function recurse(obj: any) {
38
40
  if (Array.isArray(obj)) {
@@ -14,13 +14,9 @@ function makeLabelDiv(options: any, level: number, keyName: string | number, dat
14
14
  return `<div class='index'><span class='json-to-html-label'>${keyName}&nbsp;</span></div>`;
15
15
  } else if (typeof keyName === 'string') {
16
16
  if (datatype === 'array') {
17
- return `<div class='collapsible level${level}' ${toggleJS(
18
- options
19
- )}><span class='json-to-html-label'>${keyName}</span></div>`;
17
+ return `<div class='collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}</span></div>`;
20
18
  } else if (datatype === 'object') {
21
- return `<div class='attribute collapsible level${level}' ${toggleJS(
22
- options
23
- )}><span class='json-to-html-label'>${keyName}:</span></div>`;
19
+ return `<div class='attribute collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}:</span></div>`;
24
20
  } else {
25
21
  return `<div class='leaf level${level}'><span class='json-to-html-label'>${keyName}:</span></div>`;
26
22
  }