data-structure-typed 1.52.0 → 1.52.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +141 -54
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +162 -162
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +52 -52
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/cjs/data-structures/binary-tree/bst.js +17 -17
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js.map +1 -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.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/cjs/data-structures/queue/deque.js +16 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +18 -1
- package/dist/cjs/data-structures/queue/queue.js +32 -7
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- 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 +1 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/cjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/cjs/types/data-structures/queue/queue.d.ts +3 -1
- package/dist/cjs/utils/number.js +1 -2
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.js +2 -2
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +52 -52
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -17
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/mjs/data-structures/queue/deque.js +16 -1
- package/dist/mjs/data-structures/queue/queue.d.ts +18 -1
- package/dist/mjs/data-structures/queue/queue.js +32 -7
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +1 -22
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/mjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/mjs/types/data-structures/queue/queue.d.ts +3 -1
- package/dist/umd/data-structure-typed.js +137 -95
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +8 -8
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +25 -24
- package/src/data-structures/binary-tree/avl-tree.ts +20 -19
- package/src/data-structures/binary-tree/binary-tree.ts +162 -157
- package/src/data-structures/binary-tree/bst.ts +54 -50
- package/src/data-structures/binary-tree/rb-tree.ts +18 -17
- package/src/data-structures/binary-tree/tree-multi-map.ts +18 -17
- package/src/data-structures/graph/abstract-graph.ts +15 -14
- package/src/data-structures/graph/directed-graph.ts +9 -7
- package/src/data-structures/graph/undirected-graph.ts +7 -6
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/queue/deque.ts +18 -4
- package/src/data-structures/queue/queue.ts +38 -8
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/binary-tree/binary-tree.ts +21 -1
- package/src/types/data-structures/binary-tree/bst.ts +7 -0
- package/src/types/data-structures/graph/abstract-graph.ts +8 -8
- package/src/types/data-structures/queue/deque.ts +4 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/utils/utils.ts +4 -4
- package/test/integration/bst.test.ts +4 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +12 -4
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +6 -2
- package/test/performance/reportor.ts +23 -8
- package/test/performance/types/reportor.ts +5 -1
- package/test/types/utils/json2html.ts +5 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +6 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +8 -2
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +36 -11
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -1
- package/test/unit/data-structures/binary-tree/bst.test.ts +18 -5
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +2 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +27 -0
- package/test/unit/data-structures/hash/hash-map.test.ts +6 -2
- package/test/unit/data-structures/heap/heap.test.ts +64 -12
- package/test/unit/data-structures/heap/max-heap.test.ts +10 -3
- package/test/unit/data-structures/heap/min-heap.test.ts +3 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +3 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +6 -2
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +22 -6
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +12 -4
- package/test/unit/data-structures/queue/deque.test.ts +31 -6
- package/test/unit/data-structures/queue/queue.test.ts +14 -1
- package/test/unit/data-structures/trie/trie.test.ts +3 -1
- package/test/unit/unrestricted-interconversion.test.ts +3 -1
- package/test/utils/big-o.ts +3 -1
- package/test/utils/json2html.ts +2 -6
|
@@ -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>;
|
|
@@ -260,6 +259,24 @@ describe('Deque - Utility Operations', () => {
|
|
|
260
259
|
// deque.print();
|
|
261
260
|
// expect(consoleSpy).toHaveBeenCalledWith([1, 2]);
|
|
262
261
|
});
|
|
262
|
+
|
|
263
|
+
test('should maxLen work well', () => {
|
|
264
|
+
const dequeMaxLen = new Deque([3, 4, 5, 6, 7], { maxLen: 3 });
|
|
265
|
+
expect(dequeMaxLen.size).toBe(3);
|
|
266
|
+
expect(dequeMaxLen.toArray()).toEqual([5, 6, 7]);
|
|
267
|
+
dequeMaxLen.unshift(4);
|
|
268
|
+
dequeMaxLen.unshift(3);
|
|
269
|
+
expect(dequeMaxLen.size).toBe(3);
|
|
270
|
+
expect(dequeMaxLen.toArray()).toEqual([3, 4, 5]);
|
|
271
|
+
|
|
272
|
+
const dequeNoMaxLen = new Deque([3, 4, 5, 6, 7]);
|
|
273
|
+
expect(dequeNoMaxLen.size).toBe(5);
|
|
274
|
+
expect(dequeNoMaxLen.toArray()).toEqual([3, 4, 5, 6, 7]);
|
|
275
|
+
dequeNoMaxLen.unshift(4);
|
|
276
|
+
dequeNoMaxLen.unshift(3);
|
|
277
|
+
expect(dequeNoMaxLen.size).toBe(7);
|
|
278
|
+
expect(dequeNoMaxLen.toArray()).toEqual([3, 4, 3, 4, 5, 6, 7]);
|
|
279
|
+
});
|
|
263
280
|
});
|
|
264
281
|
|
|
265
282
|
describe('Deque - Additional Operations', () => {
|
|
@@ -325,7 +342,9 @@ describe('Deque - push Method', () => {
|
|
|
325
342
|
const bucketSize = 10;
|
|
326
343
|
|
|
327
344
|
beforeEach(() => {
|
|
328
|
-
deque = new Deque<number>([], {
|
|
345
|
+
deque = new Deque<number>([], {
|
|
346
|
+
bucketSize
|
|
347
|
+
});
|
|
329
348
|
});
|
|
330
349
|
|
|
331
350
|
test('push should add an element when deque is empty', () => {
|
|
@@ -367,7 +386,9 @@ describe('Deque - pop Method', () => {
|
|
|
367
386
|
const bucketSize = 10;
|
|
368
387
|
|
|
369
388
|
beforeEach(() => {
|
|
370
|
-
deque = new Deque<number>([], {
|
|
389
|
+
deque = new Deque<number>([], {
|
|
390
|
+
bucketSize
|
|
391
|
+
});
|
|
371
392
|
});
|
|
372
393
|
|
|
373
394
|
test('pop should remove and return the last element', () => {
|
|
@@ -398,7 +419,9 @@ describe('Deque - unshift Method', () => {
|
|
|
398
419
|
const bucketSize = 10;
|
|
399
420
|
|
|
400
421
|
beforeEach(() => {
|
|
401
|
-
deque = new Deque<number>([], {
|
|
422
|
+
deque = new Deque<number>([], {
|
|
423
|
+
bucketSize
|
|
424
|
+
});
|
|
402
425
|
});
|
|
403
426
|
|
|
404
427
|
test('unshift should add an element to the beginning when deque is empty', () => {
|
|
@@ -430,7 +453,9 @@ describe('Deque - shift Method', () => {
|
|
|
430
453
|
const bucketSize = 10;
|
|
431
454
|
|
|
432
455
|
beforeEach(() => {
|
|
433
|
-
deque = new Deque<number>([], {
|
|
456
|
+
deque = new Deque<number>([], {
|
|
457
|
+
bucketSize
|
|
458
|
+
});
|
|
434
459
|
});
|
|
435
460
|
|
|
436
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<{
|
|
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'], {
|
|
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);
|
|
@@ -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, {
|
|
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([
|
package/test/utils/big-o.ts
CHANGED
|
@@ -32,7 +32,9 @@ export const bigO = {
|
|
|
32
32
|
|
|
33
33
|
function findPotentialN(input: any): number {
|
|
34
34
|
let longestArray: any[] = [];
|
|
35
|
-
let mostProperties: {
|
|
35
|
+
let mostProperties: {
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
} = {};
|
|
36
38
|
|
|
37
39
|
function recurse(obj: any) {
|
|
38
40
|
if (Array.isArray(obj)) {
|
package/test/utils/json2html.ts
CHANGED
|
@@ -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} </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
|
}
|