data-structure-typed 1.50.4 → 1.50.6
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 +116 -55
- package/SPECIFICATION.md +2 -2
- package/SPECIFICATION_zh-CN.md +81 -0
- package/{SPONSOR-zh-CN.md → SPONSOR_zh-CN.md} +1 -1
- package/benchmark/report.html +24 -24
- package/benchmark/report.json +261 -237
- package/dist/cjs/data-structures/base/iterable-base.d.ts +10 -8
- package/dist/cjs/data-structures/base/iterable-base.js +8 -12
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -19
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +415 -386
- 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 +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +84 -76
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/cjs/data-structures/graph/abstract-graph.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.d.ts +14 -76
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +16 -86
- 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 +27 -69
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +35 -79
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +0 -53
- package/dist/cjs/data-structures/queue/deque.js +0 -61
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +0 -70
- package/dist/cjs/data-structures/queue/queue.js +0 -87
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +10 -8
- package/dist/mjs/data-structures/base/iterable-base.js +8 -12
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +19 -19
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +412 -386
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +84 -76
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +16 -86
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +33 -79
- package/dist/mjs/data-structures/queue/deque.d.ts +0 -53
- package/dist/mjs/data-structures/queue/deque.js +0 -61
- package/dist/mjs/data-structures/queue/queue.d.ts +0 -70
- package/dist/mjs/data-structures/queue/queue.js +0 -86
- package/dist/umd/data-structure-typed.js +539 -756
- 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/base/iterable-base.ts +14 -10
- package/src/data-structures/binary-tree/binary-tree.ts +19 -19
- package/src/data-structures/binary-tree/rb-tree.ts +437 -395
- package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +16 -94
- package/src/data-structures/linked-list/singly-linked-list.ts +35 -87
- package/src/data-structures/queue/deque.ts +0 -67
- package/src/data-structures/queue/queue.ts +0 -98
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +26 -16
- package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +14 -14
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +11 -6
- package/test/performance/data-structures/queue/deque.test.ts +8 -8
- package/test/performance/data-structures/queue/queue.test.ts +5 -12
- package/test/performance/reportor.ts +43 -1
- package/test/unit/data-structures/binary-tree/overall.test.ts +23 -21
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +168 -105
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +311 -192
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +10 -10
- package/test/unit/data-structures/linked-list/skip-list.test.ts +4 -4
- package/test/unit/data-structures/queue/deque.test.ts +26 -26
- package/test/unit/data-structures/queue/queue.test.ts +20 -20
|
@@ -39,12 +39,12 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
39
39
|
|
|
40
40
|
it('should clone', function () {
|
|
41
41
|
const dList = new DoublyLinkedList<string>();
|
|
42
|
-
dList.
|
|
43
|
-
dList.
|
|
44
|
-
dList.
|
|
45
|
-
dList.
|
|
46
|
-
dList.
|
|
47
|
-
dList.
|
|
42
|
+
dList.push('1');
|
|
43
|
+
dList.push('6');
|
|
44
|
+
dList.push('2');
|
|
45
|
+
dList.push('0');
|
|
46
|
+
dList.push('5');
|
|
47
|
+
dList.push('9');
|
|
48
48
|
dList.delete('2');
|
|
49
49
|
expect([...dList]).toEqual(['1', '6', '0', '5', '9']);
|
|
50
50
|
const cloned = dList.clone();
|
|
@@ -32,7 +32,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
32
32
|
list.push(3);
|
|
33
33
|
const popped = list.pop();
|
|
34
34
|
expect(popped).toBe(3);
|
|
35
|
-
expect(list.
|
|
35
|
+
expect(list.pop()).toBe(2);
|
|
36
36
|
expect(list.toArray()).toEqual([1]);
|
|
37
37
|
});
|
|
38
38
|
|
|
@@ -49,7 +49,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
49
49
|
list.push(3);
|
|
50
50
|
const shifted = list.shift();
|
|
51
51
|
expect(shifted).toBe(1);
|
|
52
|
-
expect(list.
|
|
52
|
+
expect(list.shift()).toBe(2);
|
|
53
53
|
expect(list.toArray()).toEqual([3]);
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -62,7 +62,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
62
62
|
describe('unshift', () => {
|
|
63
63
|
it('should add elements to the beginning of the list', () => {
|
|
64
64
|
list.unshift(1);
|
|
65
|
-
list.
|
|
65
|
+
list.unshift(2);
|
|
66
66
|
expect(list.toArray()).toEqual([2, 1]);
|
|
67
67
|
});
|
|
68
68
|
});
|
|
@@ -350,12 +350,12 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
350
350
|
|
|
351
351
|
it('should clone', function () {
|
|
352
352
|
const sList = new SinglyLinkedList<string>();
|
|
353
|
-
sList.
|
|
354
|
-
sList.
|
|
355
|
-
sList.
|
|
356
|
-
sList.
|
|
357
|
-
sList.
|
|
358
|
-
sList.
|
|
353
|
+
sList.push('1');
|
|
354
|
+
sList.push('6');
|
|
355
|
+
sList.push('2');
|
|
356
|
+
sList.push('0');
|
|
357
|
+
sList.push('5');
|
|
358
|
+
sList.push('9');
|
|
359
359
|
sList.delete('2');
|
|
360
360
|
expect([...sList]).toEqual(['1', '6', '0', '5', '9']);
|
|
361
361
|
const cloned = sList.clone();
|
|
@@ -478,7 +478,7 @@ describe('SinglyLinkedList', () => {
|
|
|
478
478
|
});
|
|
479
479
|
|
|
480
480
|
it('should map the list', () => {
|
|
481
|
-
list.
|
|
481
|
+
list.push(1);
|
|
482
482
|
list.push(2);
|
|
483
483
|
list.push(3);
|
|
484
484
|
expect(list.map(value => value * 2).toArray()).toEqual([2, 4, 6]);
|
|
@@ -65,21 +65,21 @@ describe('SkipList Test2', () => {
|
|
|
65
65
|
skipList.add(4, 'Four');
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
it('
|
|
68
|
+
it('first() should return the first element', () => {
|
|
69
69
|
expect(skipList.first).toBe('One');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
it('
|
|
72
|
+
it('last() should return the last element', () => {
|
|
73
73
|
expect(skipList.last).toBe('Four');
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
it('higher(key) should return the
|
|
76
|
+
it('higher(key) should return the first element greater than the given key', () => {
|
|
77
77
|
expect(skipList.higher(2)).toBe('Three');
|
|
78
78
|
expect(skipList.higher(3)).toBe('Four');
|
|
79
79
|
expect(skipList.higher(4)).toBeUndefined();
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
it('lower(key) should return the
|
|
82
|
+
it('lower(key) should return the last element less than the given key', () => {
|
|
83
83
|
expect(skipList.lower(2)).toBe('One');
|
|
84
84
|
expect(skipList.lower(1)).toBe(undefined);
|
|
85
85
|
});
|
|
@@ -52,12 +52,12 @@ describe('Deque - Basic Operations', () => {
|
|
|
52
52
|
|
|
53
53
|
it('should clone', function () {
|
|
54
54
|
const deque = new Deque<string>();
|
|
55
|
-
deque.
|
|
56
|
-
deque.
|
|
57
|
-
deque.
|
|
58
|
-
deque.
|
|
59
|
-
deque.
|
|
60
|
-
deque.
|
|
55
|
+
deque.push('1');
|
|
56
|
+
deque.push('6');
|
|
57
|
+
deque.push('2');
|
|
58
|
+
deque.push('0');
|
|
59
|
+
deque.push('5');
|
|
60
|
+
deque.push('9');
|
|
61
61
|
expect(deque.size).toBe(6);
|
|
62
62
|
deque.delete('2');
|
|
63
63
|
expect(deque.size).toBe(5);
|
|
@@ -70,7 +70,7 @@ describe('Deque - Basic Operations', () => {
|
|
|
70
70
|
expect([...deque]).toEqual(['1', '6', '0', '9']);
|
|
71
71
|
expect([...cloned]).toEqual(['1', '6', '0', '5', '9']);
|
|
72
72
|
expect(cloned.size).toBe(5);
|
|
73
|
-
cloned.
|
|
73
|
+
cloned.push('8');
|
|
74
74
|
expect(cloned.size).toBe(6);
|
|
75
75
|
cloned.delete('6');
|
|
76
76
|
expect(cloned.size).toBe(5);
|
|
@@ -239,52 +239,52 @@ describe('Deque - Additional Operations', () => {
|
|
|
239
239
|
deque = new Deque<number>();
|
|
240
240
|
});
|
|
241
241
|
|
|
242
|
-
test('
|
|
243
|
-
deque.
|
|
244
|
-
deque.
|
|
242
|
+
test('push should add an element to the end', () => {
|
|
243
|
+
deque.push(1);
|
|
244
|
+
deque.push(2);
|
|
245
245
|
expect(deque.last).toBe(2);
|
|
246
246
|
expect(deque.size).toBe(2);
|
|
247
247
|
});
|
|
248
248
|
|
|
249
|
-
test('
|
|
250
|
-
deque.
|
|
251
|
-
deque.
|
|
252
|
-
expect(deque.
|
|
249
|
+
test('pop should remove and return the last element', () => {
|
|
250
|
+
deque.push(1);
|
|
251
|
+
deque.push(2);
|
|
252
|
+
expect(deque.pop()).toBe(2);
|
|
253
253
|
expect(deque.size).toBe(1);
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
-
test('
|
|
257
|
-
deque.
|
|
258
|
-
deque.
|
|
256
|
+
test('unshift should add an element to the beginning', () => {
|
|
257
|
+
deque.unshift(1);
|
|
258
|
+
deque.unshift(2);
|
|
259
259
|
expect(deque.first).toBe(2);
|
|
260
260
|
expect(deque.size).toBe(2);
|
|
261
261
|
});
|
|
262
262
|
|
|
263
|
-
test('
|
|
264
|
-
deque.
|
|
265
|
-
deque.
|
|
266
|
-
expect(deque.
|
|
263
|
+
test('shift should remove and return the first element', () => {
|
|
264
|
+
deque.unshift(1);
|
|
265
|
+
deque.unshift(2);
|
|
266
|
+
expect(deque.shift()).toBe(2);
|
|
267
267
|
expect(deque.size).toBe(1);
|
|
268
268
|
});
|
|
269
269
|
|
|
270
270
|
test('clear should reset the deque', () => {
|
|
271
|
-
deque.
|
|
271
|
+
deque.unshift(1);
|
|
272
272
|
deque.clear();
|
|
273
273
|
expect(deque.size).toBe(0);
|
|
274
274
|
expect(deque.isEmpty()).toBeTruthy();
|
|
275
275
|
});
|
|
276
276
|
|
|
277
277
|
test('begin should yield elements from the beginning', () => {
|
|
278
|
-
deque.
|
|
279
|
-
deque.
|
|
278
|
+
deque.push(1);
|
|
279
|
+
deque.push(2);
|
|
280
280
|
const iterator = deque.begin();
|
|
281
281
|
expect(iterator.next().value).toBe(1);
|
|
282
282
|
expect(iterator.next().value).toBe(2);
|
|
283
283
|
});
|
|
284
284
|
|
|
285
285
|
test('reverseBegin should yield elements in reverse order', () => {
|
|
286
|
-
deque.
|
|
287
|
-
deque.
|
|
286
|
+
deque.push(1);
|
|
287
|
+
deque.push(2);
|
|
288
288
|
const iterator = deque.reverseBegin();
|
|
289
289
|
expect(iterator.next().value).toBe(2);
|
|
290
290
|
expect(iterator.next().value).toBe(1);
|
|
@@ -23,24 +23,24 @@ describe('Queue', () => {
|
|
|
23
23
|
|
|
24
24
|
test('shift should remove the first element', () => {
|
|
25
25
|
queue.push(1);
|
|
26
|
-
queue.
|
|
26
|
+
queue.push(2);
|
|
27
27
|
expect(queue.shift()).toBe(1);
|
|
28
28
|
expect(queue.size).toBe(1);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test('shift should return undefined if queue is empty', () => {
|
|
32
|
-
expect(queue.
|
|
32
|
+
expect(queue.shift()).toBeUndefined();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
test('
|
|
35
|
+
test('first should return the first element without removing it', () => {
|
|
36
36
|
queue.push(1);
|
|
37
37
|
queue.push(2);
|
|
38
|
-
expect(queue.
|
|
38
|
+
expect(queue.first).toBe(1);
|
|
39
39
|
expect(queue.size).toBe(2);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
test('
|
|
43
|
-
expect(queue.
|
|
42
|
+
test('first should return undefined if queue is empty', () => {
|
|
43
|
+
expect(queue.first).toBeUndefined();
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
test('size should return the number of elements', () => {
|
|
@@ -167,12 +167,12 @@ describe('Queue - Additional Methods', () => {
|
|
|
167
167
|
test('peekLast should return the last element without removing it', () => {
|
|
168
168
|
queue.push(1);
|
|
169
169
|
queue.push(2);
|
|
170
|
-
expect(queue.
|
|
170
|
+
expect(queue.last).toBe(2);
|
|
171
171
|
expect(queue.size).toBe(2);
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
test('peekLast should return undefined if queue is empty', () => {
|
|
175
|
-
expect(queue.
|
|
175
|
+
expect(queue.last).toBeUndefined();
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
test('at should return the element at the specified index', () => {
|
|
@@ -239,25 +239,25 @@ describe('LinkedListQueue', () => {
|
|
|
239
239
|
queue = new LinkedListQueue<string>();
|
|
240
240
|
});
|
|
241
241
|
|
|
242
|
-
it('should
|
|
243
|
-
queue.
|
|
244
|
-
queue.
|
|
245
|
-
expect(queue.
|
|
242
|
+
it('should push elements to the end of the queue', () => {
|
|
243
|
+
queue.push('A');
|
|
244
|
+
queue.push('B');
|
|
245
|
+
expect(queue.first).toBe('A');
|
|
246
246
|
expect(queue.size).toBe(2);
|
|
247
247
|
});
|
|
248
248
|
|
|
249
|
-
it('should
|
|
250
|
-
queue.
|
|
251
|
-
queue.
|
|
252
|
-
const dequeued = queue.
|
|
249
|
+
it('should shift elements from the front of the queue', () => {
|
|
250
|
+
queue.push('A');
|
|
251
|
+
queue.push('B');
|
|
252
|
+
const dequeued = queue.shift();
|
|
253
253
|
expect(dequeued).toBe('A');
|
|
254
|
-
expect(queue.
|
|
254
|
+
expect(queue.first).toBe('B');
|
|
255
255
|
expect(queue.size).toBe(1);
|
|
256
256
|
});
|
|
257
257
|
|
|
258
258
|
it('should peek at the front of the queue', () => {
|
|
259
|
-
queue.
|
|
260
|
-
queue.
|
|
261
|
-
expect(queue.
|
|
259
|
+
queue.push('A');
|
|
260
|
+
queue.push('B');
|
|
261
|
+
expect(queue.first).toBe('A');
|
|
262
262
|
});
|
|
263
263
|
});
|