data-structure-typed 1.49.3 → 1.49.4

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 (42) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +69 -66
  3. package/README_zh-CN.md +43 -48
  4. package/benchmark/report.html +16 -16
  5. package/benchmark/report.json +187 -187
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -10
  10. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -17
  11. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/directed-graph.js +4 -0
  13. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  16. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  17. package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
  18. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -10
  19. package/dist/mjs/data-structures/graph/abstract-graph.js +0 -17
  20. package/dist/mjs/data-structures/graph/directed-graph.js +4 -0
  21. package/dist/umd/data-structure-typed.js +5 -18
  22. package/dist/umd/data-structure-typed.min.js +2 -2
  23. package/dist/umd/data-structure-typed.min.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/data-structures/binary-tree/binary-tree.ts +1 -1
  26. package/src/data-structures/graph/abstract-graph.ts +1 -13
  27. package/src/data-structures/graph/directed-graph.ts +7 -3
  28. package/src/data-structures/graph/undirected-graph.ts +1 -1
  29. package/src/data-structures/linked-list/singly-linked-list.ts +1 -2
  30. package/test/performance/data-structures/comparison/comparison.test.ts +12 -12
  31. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -27
  32. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
  33. package/test/performance/data-structures/queue/deque.test.ts +8 -8
  34. package/test/performance/data-structures/queue/queue.test.ts +5 -5
  35. package/test/performance/data-structures/stack/stack.test.ts +11 -11
  36. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +15 -0
  37. package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
  38. package/test/unit/data-structures/graph/directed-graph.test.ts +15 -2
  39. package/test/unit/data-structures/graph/undirected-graph.test.ts +13 -0
  40. package/test/unit/data-structures/hash/hash-map.test.ts +21 -0
  41. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +27 -0
  42. package/test/utils/big-o.ts +14 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.49.3",
3
+ "version": "1.49.4",
4
4
  "description": "Data Structures of Javascript & TypeScript. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/mjs/index.js",
@@ -1957,7 +1957,7 @@ export class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = Bi
1957
1957
  }
1958
1958
  }
1959
1959
 
1960
- protected _defaultOneParamCallback = (node: N) => node.key;
1960
+ protected _defaultOneParamCallback = (node: N | null | undefined) => node ? node.key : undefined;
1961
1961
 
1962
1962
  /**
1963
1963
  * Swap the data of two nodes in the binary tree.
@@ -173,19 +173,7 @@ export abstract class AbstractGraph<
173
173
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
174
174
  */
175
175
 
176
- /**
177
- * Time Complexity: O(1) - Constant time for Map operations.
178
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
179
- *
180
- * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
181
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
182
- * (`VertexKey`).
183
- * @returns The method is returning a boolean value.
184
- */
185
- deleteVertex(vertexOrKey: VO | VertexKey): boolean {
186
- const vertexKey = this._getVertexKey(vertexOrKey);
187
- return this._vertexMap.delete(vertexKey);
188
- }
176
+ abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
189
177
 
190
178
  /**
191
179
  * Time Complexity: O(K), where K is the number of vertexMap to be removed.
@@ -240,7 +240,7 @@ export class DirectedGraph<
240
240
  * (`VertexKey`).
241
241
  * @returns The method is returning a boolean value.
242
242
  */
243
- override deleteVertex(vertexOrKey: VO | VertexKey): boolean {
243
+ deleteVertex(vertexOrKey: VO | VertexKey): boolean {
244
244
  let vertexKey: VertexKey;
245
245
  let vertex: VO | undefined;
246
246
  if (this.isVertexKey(vertexOrKey)) {
@@ -252,8 +252,12 @@ export class DirectedGraph<
252
252
  }
253
253
 
254
254
  if (vertex) {
255
- this._outEdgeMap.delete(vertex)
256
- this._inEdgeMap.delete(vertex)
255
+ const neighbors = this.getNeighbors(vertex);
256
+ for (const neighbor of neighbors) {
257
+ this._inEdgeMap.delete(neighbor);
258
+ }
259
+ this._outEdgeMap.delete(vertex);
260
+ this._inEdgeMap.delete(vertex);
257
261
  }
258
262
 
259
263
  return this._vertexMap.delete(vertexKey);
@@ -212,7 +212,7 @@ export class UndirectedGraph<
212
212
  * (`VertexKey`).
213
213
  * @returns The method is returning a boolean value.
214
214
  */
215
- override deleteVertex(vertexOrKey: VO | VertexKey): boolean {
215
+ deleteVertex(vertexOrKey: VO | VertexKey): boolean {
216
216
  let vertexKey: VertexKey;
217
217
  let vertex: VO | undefined;
218
218
  if (this.isVertexKey(vertexOrKey)) {
@@ -33,8 +33,7 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
33
33
  this._tail = undefined;
34
34
  this._size = 0;
35
35
  if (elements) {
36
- for (const el of elements)
37
- this.push(el);
36
+ for (const el of elements) this.push(el);
38
37
  }
39
38
  }
40
39
 
@@ -16,7 +16,7 @@ import { getRandomIntArray, magnitude } from '../../../utils';
16
16
  import { isCompetitor } from '../../../config';
17
17
 
18
18
  const suite = new Benchmark.Suite();
19
- const { TEN_THOUSAND, HUNDRED_THOUSAND, LINEAR } = magnitude;
19
+ const { TEN_THOUSAND, HUNDRED_THOUSAND, MILLION } = magnitude;
20
20
  const cOrderedMap = new OrderedMap<number, number>();
21
21
  const arrHundredThousand = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true);
22
22
 
@@ -96,10 +96,10 @@ if (isCompetitor) {
96
96
  hm.getElementByKey(i);
97
97
  }
98
98
  })
99
- .add(`CPT LL ${LINEAR.toLocaleString()} unshift`, () => {
99
+ .add(`CPT LL ${MILLION.toLocaleString()} unshift`, () => {
100
100
  const list = new CLinkedList<number>();
101
101
 
102
- for (let i = 0; i < LINEAR; i++) {
102
+ for (let i = 0; i < MILLION; i++) {
103
103
  list.pushFront(i);
104
104
  }
105
105
  })
@@ -114,33 +114,33 @@ if (isCompetitor) {
114
114
  pq.pop();
115
115
  }
116
116
  })
117
- .add(`CPT DQ ${LINEAR.toLocaleString()} push`, () => {
117
+ .add(`CPT DQ ${MILLION.toLocaleString()} push`, () => {
118
118
  const deque = new CDeque<number>();
119
- for (let i = 0; i < LINEAR; i++) {
119
+ for (let i = 0; i < MILLION; i++) {
120
120
  deque.pushBack(i);
121
121
  }
122
122
  })
123
- .add(`CPT Q ${LINEAR.toLocaleString()} push`, () => {
123
+ .add(`CPT Q ${MILLION.toLocaleString()} push`, () => {
124
124
  const queue = new CQueue<number>();
125
125
 
126
- for (let i = 0; i < LINEAR; i++) {
126
+ for (let i = 0; i < MILLION; i++) {
127
127
  queue.push(i);
128
128
  }
129
129
  })
130
- .add(`CPT ST ${LINEAR.toLocaleString()} push`, () => {
130
+ .add(`CPT ST ${MILLION.toLocaleString()} push`, () => {
131
131
  const queue = new CStack<number>();
132
132
 
133
- for (let i = 0; i < LINEAR; i++) {
133
+ for (let i = 0; i < MILLION; i++) {
134
134
  queue.push(i);
135
135
  }
136
136
  })
137
- .add(`CPT ST ${LINEAR.toLocaleString()} push & pop`, () => {
137
+ .add(`CPT ST ${MILLION.toLocaleString()} push & pop`, () => {
138
138
  const queue = new CStack<number>();
139
139
 
140
- for (let i = 0; i < LINEAR; i++) {
140
+ for (let i = 0; i < MILLION; i++) {
141
141
  queue.push(i);
142
142
  }
143
- for (let i = 0; i < LINEAR; i++) {
143
+ for (let i = 0; i < MILLION; i++) {
144
144
  queue.pop();
145
145
  }
146
146
  });
@@ -5,61 +5,50 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const { LINEAR } = magnitude;
8
+ const { MILLION } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const list = new DoublyLinkedList<number>();
12
12
 
13
- for (let i = 0; i < LINEAR; i++) {
14
- list.push(i);
15
- }
13
+ for (let i = 0; i < MILLION; i++) list.push(i);
16
14
  });
17
15
 
18
16
 
19
17
  if (isCompetitor) {
20
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
18
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
21
19
  const list = new CLinkedList<number>();
22
20
 
23
- for (let i = 0; i < LINEAR; i++) {
24
- list.pushBack(i);
25
- }
21
+ for (let i = 0; i < MILLION; i++) list.pushBack(i);
26
22
  });
27
23
  }
28
24
 
29
- suite.add(`${LINEAR.toLocaleString()} unshift`, () => {
25
+ suite.add(`${MILLION.toLocaleString()} unshift`, () => {
30
26
  const list = new DoublyLinkedList<number>();
31
27
 
32
- for (let i = 0; i < LINEAR; i++) {
33
- list.unshift(i);
34
- }
28
+ for (let i = 0; i < MILLION; i++) list.unshift(i);
35
29
  });
36
30
 
37
31
  if (isCompetitor) {
38
- suite.add(`CPT ${LINEAR.toLocaleString()} unshift`, () => {
32
+ suite.add(`CPT ${MILLION.toLocaleString()} unshift`, () => {
39
33
  const list = new CLinkedList<number>();
40
34
 
41
- for (let i = 0; i < LINEAR; i++) {
42
- list.pushFront(i);
43
- }
35
+ for (let i = 0; i < MILLION; i++) list.pushFront(i);
44
36
  });
45
37
  }
46
38
 
47
39
  suite
48
- .add(`${LINEAR.toLocaleString()} unshift & shift`, () => {
40
+ .add(`${MILLION.toLocaleString()} unshift & shift`, () => {
49
41
  const list = new DoublyLinkedList<number>();
50
42
 
51
- for (let i = 0; i < LINEAR; i++) {
52
- list.unshift(i);
53
- }
54
- for (let i = 0; i < LINEAR; i++) {
55
- list.shift();
56
- }
43
+ for (let i = 0; i < MILLION; i++) list.unshift(i);
44
+
45
+ for (let i = 0; i < MILLION; i++) list.shift();
57
46
  })
58
- .add(`${LINEAR.toLocaleString()} addBefore`, () => {
47
+ .add(`${MILLION.toLocaleString()} addBefore`, () => {
59
48
  const doublyList = new DoublyLinkedList<number>();
60
49
  let midNode: DoublyLinkedListNode | undefined;
61
- const midIndex = Math.floor(LINEAR / 2);
62
- for (let i = 0; i < LINEAR; i++) {
50
+ const midIndex = Math.floor(MILLION / 2);
51
+ for (let i = 0; i < MILLION; i++) {
63
52
  doublyList.push(i);
64
53
  if (i === midIndex) {
65
54
  midNode = doublyList.getNode(i);
@@ -9,24 +9,16 @@ suite
9
9
  .add(`${MILLION.toLocaleString()} push & shift`, () => {
10
10
  const list = new SinglyLinkedList<number>();
11
11
 
12
- for (let i = 0; i < MILLION; i++) {
13
- list.push(i);
14
- }
12
+ for (let i = 0; i < MILLION; i++) list.push(i);
15
13
 
16
- for (let i = 0; i < MILLION; i++) {
17
- list.shift();
18
- }
14
+ for (let i = 0; i < MILLION; i++) list.shift();
19
15
  })
20
16
  .add(`${TEN_THOUSAND.toLocaleString()} push & pop`, () => {
21
17
  const list = new SinglyLinkedList<number>();
22
18
 
23
- for (let i = 0; i < TEN_THOUSAND; i++) {
24
- list.push(i);
25
- }
19
+ for (let i = 0; i < TEN_THOUSAND; i++) list.push(i);
26
20
 
27
- for (let i = 0; i < TEN_THOUSAND; i++) {
28
- list.pop();
29
- }
21
+ for (let i = 0; i < TEN_THOUSAND; i++) list.pop();
30
22
  })
31
23
  .add(`${TEN_THOUSAND.toLocaleString()} addBefore`, () => {
32
24
  const singlyList = new SinglyLinkedList<number>();
@@ -5,26 +5,26 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  export const suite = new Benchmark.Suite();
8
- const { LINEAR, HUNDRED_THOUSAND } = magnitude;
8
+ const { MILLION, HUNDRED_THOUSAND } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const deque = new Deque<number>();
12
- for (let i = 0; i < LINEAR; i++) deque.push(i);
12
+ for (let i = 0; i < MILLION; i++) deque.push(i);
13
13
  });
14
14
 
15
15
  if (isCompetitor) {
16
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
16
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
17
17
  const _deque = new CDeque<number>();
18
- for (let i = 0; i < LINEAR; i++) _deque.pushBack(i);
18
+ for (let i = 0; i < MILLION; i++) _deque.pushBack(i);
19
19
  });
20
20
  }
21
21
 
22
22
 
23
- suite.add(`${LINEAR.toLocaleString()} push & pop`, () => {
23
+ suite.add(`${MILLION.toLocaleString()} push & pop`, () => {
24
24
  const _deque = new Deque<number>();
25
25
 
26
- for (let i = 0; i < LINEAR; i++) _deque.push(i);
27
- for (let i = 0; i < LINEAR; i++) _deque.pop();
26
+ for (let i = 0; i < MILLION; i++) _deque.push(i);
27
+ for (let i = 0; i < MILLION; i++) _deque.pop();
28
28
 
29
29
  })
30
30
  .add(`${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
@@ -5,20 +5,20 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const { LINEAR, HUNDRED_THOUSAND } = magnitude;
8
+ const { MILLION, HUNDRED_THOUSAND } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const queue = new Queue<number>();
12
12
 
13
- for (let i = 0; i < LINEAR; i++) {
13
+ for (let i = 0; i < MILLION; i++) {
14
14
  queue.push(i);
15
15
  }
16
16
  });
17
17
  if (isCompetitor) {
18
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
18
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
19
19
  const queue = new CQueue<number>();
20
20
 
21
- for (let i = 0; i < LINEAR; i++) {
21
+ for (let i = 0; i < MILLION; i++) {
22
22
  queue.push(i);
23
23
  }
24
24
  });
@@ -5,42 +5,42 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const { LINEAR } = magnitude;
8
+ const { MILLION } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const stack = new Stack<number>();
12
12
 
13
- for (let i = 0; i < LINEAR; i++) {
13
+ for (let i = 0; i < MILLION; i++) {
14
14
  stack.push(i);
15
15
  }
16
16
  });
17
17
  if (isCompetitor) {
18
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
18
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
19
19
  const queue = new CStack<number>();
20
20
 
21
- for (let i = 0; i < LINEAR; i++) {
21
+ for (let i = 0; i < MILLION; i++) {
22
22
  queue.push(i);
23
23
  }
24
24
  });
25
25
  }
26
- suite.add(`${LINEAR.toLocaleString()} push & pop`, () => {
26
+ suite.add(`${MILLION.toLocaleString()} push & pop`, () => {
27
27
  const queue = new Stack<number>();
28
28
 
29
- for (let i = 0; i < LINEAR; i++) {
29
+ for (let i = 0; i < MILLION; i++) {
30
30
  queue.push(i);
31
31
  }
32
- for (let i = 0; i < LINEAR; i++) {
32
+ for (let i = 0; i < MILLION; i++) {
33
33
  queue.pop();
34
34
  }
35
35
  });
36
36
  if (isCompetitor) {
37
- suite.add(`CPT ${LINEAR.toLocaleString()} push & pop`, () => {
37
+ suite.add(`CPT ${MILLION.toLocaleString()} push & pop`, () => {
38
38
  const queue = new CStack<number>();
39
39
 
40
- for (let i = 0; i < LINEAR; i++) {
40
+ for (let i = 0; i < MILLION; i++) {
41
41
  queue.push(i);
42
42
  }
43
- for (let i = 0; i < LINEAR; i++) {
43
+ for (let i = 0; i < MILLION; i++) {
44
44
  queue.pop();
45
45
  }
46
46
  });
@@ -639,4 +639,19 @@ describe('BinaryTree iterative methods test', () => {
639
639
  const values = binaryTree.values();
640
640
  expect([...values]).toEqual(['b', 'a', 'c']);
641
641
  });
642
+
643
+ test('should iterative method return undefined when the node is null', () => {
644
+ const tree = new BinaryTree()
645
+ tree.addMany([-10, -10, -10, 9, 9, 20, null, null, 15, 7, 8, null, 2, null, 6, null, null, 8, 8, 8]);
646
+ const bfsResult = tree.bfs(undefined, undefined, undefined, true);
647
+ expect(bfsResult).toEqual([
648
+ -10, 9,
649
+ 20, undefined,
650
+ undefined, 15,
651
+ 7, 8,
652
+ undefined, 2,
653
+ undefined, 6,
654
+ undefined, undefined
655
+ ]);
656
+ })
642
657
  });
@@ -66,6 +66,17 @@ class MyGraph<
66
66
  return edge ? undefined : undefined;
67
67
  }
68
68
 
69
+ deleteVertex(vertexOrKey: VertexKey | VO): boolean {
70
+ let vertexKey: VertexKey;
71
+ if (this.isVertexKey(vertexOrKey)) {
72
+ vertexKey = vertexOrKey;
73
+ } else {
74
+ vertexKey = vertexOrKey.key;
75
+ }
76
+ this._vertexMap.delete(vertexKey);
77
+ return true;
78
+ }
79
+
69
80
  protected _addEdge(edge: EO): boolean {
70
81
  return edge ? true : true;
71
82
  }
@@ -635,7 +635,7 @@ describe('DirectedGraph iterative Methods', () => {
635
635
  expect(concatenated).toBe(vertexMap.join(''));
636
636
  });
637
637
 
638
- test('Removing an edge of a DirectedGraph should not delete additional edges', () => {
638
+ test('Removing an edge of a DirectedGraph should delete additional edges', () => {
639
639
  const dg = new DirectedGraph();
640
640
  dg.addVertex('hello')
641
641
  dg.addVertex('hi')
@@ -649,9 +649,22 @@ describe('DirectedGraph iterative Methods', () => {
649
649
  dg.deleteEdge('hello', 'hi')
650
650
  expect(dg.getEdge('hello', 'hi')).toBe(undefined)
651
651
  expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(DirectedEdge)
652
+ expect(dg.incomingEdgesOf("Hi")).toEqual([])
652
653
  });
653
654
 
654
- test('Removing a vertex from a UndirectedGraph should remove its edges', () => {
655
+ test('Removing a vertex of a DirectedGraph should delete additional edges', () => {
656
+ const graph = new DirectedGraph();
657
+
658
+ graph.addVertex("Hello");
659
+ graph.addVertex("Hi");
660
+
661
+ graph.addEdge("Hello", "Hi");
662
+ graph.deleteVertex("Hello");
663
+
664
+ expect(graph.incomingEdgesOf("Hi")).toEqual([]);
665
+ })
666
+
667
+ test('Removing a vertex from a DirectedGraph should remove its edges', () => {
655
668
  const dg = new DirectedGraph();
656
669
  dg.addVertex('hello')
657
670
  dg.addVertex('world')
@@ -190,6 +190,19 @@ describe('UndirectedGraph', () => {
190
190
  expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge)
191
191
  });
192
192
 
193
+
194
+ test('Removing a vertex of a DirectedGraph should delete additional edges', () => {
195
+ const graph = new UndirectedGraph();
196
+
197
+ graph.addVertex("Hello");
198
+ graph.addVertex("Hi");
199
+
200
+ graph.addEdge("Hello", "Hi");
201
+ graph.deleteVertex("Hello");
202
+
203
+ expect(graph.edgesOf("Hi")).toEqual([]);
204
+ })
205
+
193
206
  test('Removing a vertex from a UndirectedGraph should remove its edges', () => {
194
207
  const dg = new UndirectedGraph();
195
208
  dg.addVertex('hello')
@@ -554,4 +554,25 @@ describe('LinkedHashMap setMany, keys, values', () => {
554
554
  test('values', () => {
555
555
  expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
556
556
  });
557
+
558
+ test('entries', () => {
559
+ expect([...hm.entries()]).toEqual([[2, 2], [3, 3], [4, 4], [5, 5], [6, 6]])
560
+ });
561
+
562
+ test('every', () => {
563
+ expect(hm.every(value => value > 4)).toBe(false)
564
+ });
565
+
566
+ test('some', () => {
567
+ expect(hm.some(value => value > 6)).toBe(false)
568
+ });
569
+
570
+ test('hasValue', () => {
571
+ expect(hm.hasValue(3)).toBe(true)
572
+ expect(hm.hasValue(7)).toBe(false)
573
+ });
574
+
575
+ test('print', () => {
576
+ hm.print();
577
+ });
557
578
  });
@@ -424,4 +424,31 @@ describe('iterable methods', () => {
424
424
  expect([...dl.map(element => element * 2)]).toEqual([2, 4, 6]);
425
425
  expect(dl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
426
426
  });
427
+
428
+ test('values', () => {
429
+ const dl = new DoublyLinkedList<number>()
430
+ dl.push(1);
431
+ dl.push(2);
432
+ dl.push(3);
433
+ dl.delete(2);
434
+ dl.unshift(0);
435
+ dl.shift();
436
+ dl.pop();
437
+ dl.unshift(3);
438
+ expect([...dl.values()]).toEqual([3, 1])
439
+ })
440
+
441
+ test('some', () => {
442
+ const dl = new DoublyLinkedList<number>()
443
+ dl.push(1);
444
+ dl.push(2);
445
+ dl.push(3);
446
+ dl.delete(2);
447
+ dl.unshift(0);
448
+ dl.shift();
449
+ dl.pop();
450
+ dl.unshift(3);
451
+ expect(dl.some(value => value > 1)).toBe(true)
452
+ expect(dl.some(value => value > 100)).toBe(false)
453
+ })
427
454
  });
@@ -2,16 +2,16 @@ import { AnyFunction } from '../types';
2
2
  import { isDebugTest } from '../config';
3
3
 
4
4
  const isDebug = isDebugTest;
5
- const orderReducedBy = 1; // reduction of bigO's order compared to the baseline bigO
5
+ // const orderReducedBy = 1; // reduction of bigO's order compared to the baseline bigO
6
6
 
7
7
  export const magnitude = {
8
- CONSTANT: Math.pow(10, 9),
9
- LOG_N: Math.pow(10, 8 - orderReducedBy),
10
- LINEAR: Math.pow(10, 7 - orderReducedBy),
11
- N_LOG_N: Math.pow(10, 4 - orderReducedBy),
12
- SQUARED: Math.pow(10, 3 - orderReducedBy),
13
- CUBED: Math.pow(10, 2 - orderReducedBy),
14
- FACTORIAL: 20 - orderReducedBy,
8
+ // CONSTANT: Math.pow(10, 9),
9
+ // LOG_N: Math.pow(10, 8 - orderReducedBy),
10
+ // LINEAR: Math.pow(10, 7 - orderReducedBy),
11
+ // N_LOG_N: Math.pow(10, 4 - orderReducedBy),
12
+ // SQUARED: Math.pow(10, 3 - orderReducedBy),
13
+ // CUBED: Math.pow(10, 2 - orderReducedBy),
14
+ // FACTORIAL: 20 - orderReducedBy,
15
15
  THOUSAND: 1000,
16
16
  TEN_THOUSAND: 10000,
17
17
  HUNDRED_THOUSAND: 100000,
@@ -21,12 +21,12 @@ export const magnitude = {
21
21
  };
22
22
 
23
23
  export const bigO = {
24
- CONSTANT: magnitude.CONSTANT / 100000,
25
- LOG_N: Math.log2(magnitude.LOG_N) / 1000,
26
- LINEAR: magnitude.LINEAR / 1000,
27
- N_LOG_N: (magnitude.N_LOG_N * Math.log2(magnitude.LOG_N)) / 1000,
28
- SQUARED: Math.pow(magnitude.SQUARED, 2) / 1000,
29
- CUBED: Math.pow(magnitude.SQUARED, 3) / 1000,
24
+ // CONSTANT: magnitude.CONSTANT / 100000,
25
+ // LOG_N: Math.log2(magnitude.LOG_N) / 1000,
26
+ // LINEAR: magnitude.LINEAR / 1000,
27
+ // N_LOG_N: (magnitude.N_LOG_N * Math.log2(magnitude.LOG_N)) / 1000,
28
+ // SQUARED: Math.pow(magnitude.SQUARED, 2) / 1000,
29
+ // CUBED: Math.pow(magnitude.SQUARED, 3) / 1000,
30
30
  FACTORIAL: 10000
31
31
  };
32
32