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.
Files changed (82) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +116 -55
  3. package/SPECIFICATION.md +2 -2
  4. package/SPECIFICATION_zh-CN.md +81 -0
  5. package/{SPONSOR-zh-CN.md → SPONSOR_zh-CN.md} +1 -1
  6. package/benchmark/report.html +24 -24
  7. package/benchmark/report.json +261 -237
  8. package/dist/cjs/data-structures/base/iterable-base.d.ts +10 -8
  9. package/dist/cjs/data-structures/base/iterable-base.js +8 -12
  10. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -19
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js +415 -386
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  17. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +84 -76
  18. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  19. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  20. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
  21. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  23. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
  24. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +16 -86
  25. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +35 -79
  28. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  29. package/dist/cjs/data-structures/queue/deque.d.ts +0 -53
  30. package/dist/cjs/data-structures/queue/deque.js +0 -61
  31. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  32. package/dist/cjs/data-structures/queue/queue.d.ts +0 -70
  33. package/dist/cjs/data-structures/queue/queue.js +0 -87
  34. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  35. package/dist/mjs/data-structures/base/iterable-base.d.ts +10 -8
  36. package/dist/mjs/data-structures/base/iterable-base.js +8 -12
  37. package/dist/mjs/data-structures/binary-tree/binary-tree.js +19 -19
  38. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
  39. package/dist/mjs/data-structures/binary-tree/rb-tree.js +412 -386
  40. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  41. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +84 -76
  42. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  43. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
  44. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
  45. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +16 -86
  46. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
  47. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +33 -79
  48. package/dist/mjs/data-structures/queue/deque.d.ts +0 -53
  49. package/dist/mjs/data-structures/queue/deque.js +0 -61
  50. package/dist/mjs/data-structures/queue/queue.d.ts +0 -70
  51. package/dist/mjs/data-structures/queue/queue.js +0 -86
  52. package/dist/umd/data-structure-typed.js +539 -756
  53. package/dist/umd/data-structure-typed.min.js +2 -2
  54. package/dist/umd/data-structure-typed.min.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/data-structures/base/iterable-base.ts +14 -10
  57. package/src/data-structures/binary-tree/binary-tree.ts +19 -19
  58. package/src/data-structures/binary-tree/rb-tree.ts +437 -395
  59. package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
  60. package/src/data-structures/graph/abstract-graph.ts +4 -0
  61. package/src/data-structures/heap/heap.ts +1 -1
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +16 -94
  63. package/src/data-structures/linked-list/singly-linked-list.ts +35 -87
  64. package/src/data-structures/queue/deque.ts +0 -67
  65. package/src/data-structures/queue/queue.ts +0 -98
  66. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +3 -3
  67. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
  68. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +26 -16
  69. package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
  70. package/test/performance/data-structures/heap/heap.test.ts +14 -14
  71. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +11 -6
  72. package/test/performance/data-structures/queue/deque.test.ts +8 -8
  73. package/test/performance/data-structures/queue/queue.test.ts +5 -12
  74. package/test/performance/reportor.ts +43 -1
  75. package/test/unit/data-structures/binary-tree/overall.test.ts +23 -21
  76. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +168 -105
  77. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +311 -192
  78. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
  79. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +10 -10
  80. package/test/unit/data-structures/linked-list/skip-list.test.ts +4 -4
  81. package/test/unit/data-structures/queue/deque.test.ts +26 -26
  82. 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.addLast('1');
43
- dList.addLast('6');
44
- dList.addLast('2');
45
- dList.addLast('0');
46
- dList.addLast('5');
47
- dList.addLast('9');
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.pollLast()).toBe(2);
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.pollFirst()).toBe(2);
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.addFirst(2);
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.addLast('1');
354
- sList.addLast('6');
355
- sList.addLast('2');
356
- sList.addLast('0');
357
- sList.addLast('5');
358
- sList.addLast('9');
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.addLast(1);
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('getFirst() should return the getFirst element', () => {
68
+ it('first() should return the first element', () => {
69
69
  expect(skipList.first).toBe('One');
70
70
  });
71
71
 
72
- it('getLast() should return the getLast element', () => {
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 getFirst element greater than the given key', () => {
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 getLast element less than the given key', () => {
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.addLast('1');
56
- deque.addLast('6');
57
- deque.addLast('2');
58
- deque.addLast('0');
59
- deque.addLast('5');
60
- deque.addLast('9');
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.addLast('8');
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('addLast should add an element to the end', () => {
243
- deque.addLast(1);
244
- deque.addLast(2);
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('pollLast should remove and return the last element', () => {
250
- deque.addLast(1);
251
- deque.addLast(2);
252
- expect(deque.pollLast()).toBe(2);
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('addFirst should add an element to the beginning', () => {
257
- deque.addFirst(1);
258
- deque.addFirst(2);
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('pollFirst should remove and return the first element', () => {
264
- deque.addFirst(1);
265
- deque.addFirst(2);
266
- expect(deque.pollFirst()).toBe(2);
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.addFirst(1);
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.addLast(1);
279
- deque.addLast(2);
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.addLast(1);
287
- deque.addLast(2);
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.enqueue(2);
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.dequeue()).toBeUndefined();
32
+ expect(queue.shift()).toBeUndefined();
33
33
  });
34
34
 
35
- test('peek should return the first element without removing it', () => {
35
+ test('first should return the first element without removing it', () => {
36
36
  queue.push(1);
37
37
  queue.push(2);
38
- expect(queue.peek()).toBe(1);
38
+ expect(queue.first).toBe(1);
39
39
  expect(queue.size).toBe(2);
40
40
  });
41
41
 
42
- test('peek should return undefined if queue is empty', () => {
43
- expect(queue.peek()).toBeUndefined();
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.peekLast()).toBe(2);
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.peekLast()).toBeUndefined();
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 enqueue elements to the end of the queue', () => {
243
- queue.enqueue('A');
244
- queue.enqueue('B');
245
- expect(queue.peek()).toBe('A');
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 dequeue elements from the front of the queue', () => {
250
- queue.enqueue('A');
251
- queue.enqueue('B');
252
- const dequeued = queue.dequeue();
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.peek()).toBe('B');
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.enqueue('A');
260
- queue.enqueue('B');
261
- expect(queue.peek()).toBe('A');
259
+ queue.push('A');
260
+ queue.push('B');
261
+ expect(queue.first).toBe('A');
262
262
  });
263
263
  });