data-structure-typed 1.39.4 → 1.39.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 (111) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js +13 -13
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +17 -17
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
  9. package/dist/cjs/data-structures/binary-tree/bst.js +13 -13
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
  12. package/dist/cjs/data-structures/binary-tree/rb-tree.js +4 -4
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
  15. package/dist/cjs/data-structures/binary-tree/segment-tree.js +16 -16
  16. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  18. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +18 -18
  19. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +96 -96
  21. package/dist/cjs/data-structures/graph/abstract-graph.js +64 -64
  22. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/directed-graph.d.ts +68 -68
  24. package/dist/cjs/data-structures/graph/directed-graph.js +48 -48
  25. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/map-graph.d.ts +13 -13
  27. package/dist/cjs/data-structures/graph/map-graph.js +15 -15
  28. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +42 -42
  30. package/dist/cjs/data-structures/graph/undirected-graph.js +32 -32
  31. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/hash/hash-table.d.ts +4 -4
  33. package/dist/cjs/data-structures/hash/hash-table.js +8 -8
  34. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  35. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
  36. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +54 -54
  37. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
  39. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +52 -52
  40. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  41. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  42. package/dist/cjs/data-structures/queue/queue.js +4 -4
  43. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  44. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  45. package/dist/cjs/interfaces/graph.d.ts +3 -3
  46. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
  47. package/dist/mjs/data-structures/binary-tree/avl-tree.js +13 -13
  48. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
  49. package/dist/mjs/data-structures/binary-tree/binary-tree.js +18 -18
  50. package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
  51. package/dist/mjs/data-structures/binary-tree/bst.js +13 -13
  52. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
  53. package/dist/mjs/data-structures/binary-tree/rb-tree.js +4 -4
  54. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
  55. package/dist/mjs/data-structures/binary-tree/segment-tree.js +16 -16
  56. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  57. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +18 -18
  58. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +96 -96
  59. package/dist/mjs/data-structures/graph/abstract-graph.js +66 -66
  60. package/dist/mjs/data-structures/graph/directed-graph.d.ts +68 -68
  61. package/dist/mjs/data-structures/graph/directed-graph.js +48 -48
  62. package/dist/mjs/data-structures/graph/map-graph.d.ts +13 -13
  63. package/dist/mjs/data-structures/graph/map-graph.js +15 -15
  64. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +42 -42
  65. package/dist/mjs/data-structures/graph/undirected-graph.js +32 -32
  66. package/dist/mjs/data-structures/hash/hash-table.d.ts +4 -4
  67. package/dist/mjs/data-structures/hash/hash-table.js +9 -9
  68. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
  69. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +55 -55
  70. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
  71. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +53 -53
  72. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  73. package/dist/mjs/data-structures/queue/queue.js +4 -4
  74. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  75. package/dist/mjs/interfaces/graph.d.ts +3 -3
  76. package/dist/umd/data-structure-typed.min.js +1 -1
  77. package/dist/umd/data-structure-typed.min.js.map +1 -1
  78. package/package.json +5 -5
  79. package/src/data-structures/binary-tree/avl-tree.ts +13 -13
  80. package/src/data-structures/binary-tree/binary-tree.ts +18 -18
  81. package/src/data-structures/binary-tree/bst.ts +16 -16
  82. package/src/data-structures/binary-tree/rb-tree.ts +6 -6
  83. package/src/data-structures/binary-tree/segment-tree.ts +15 -15
  84. package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
  85. package/src/data-structures/graph/abstract-graph.ts +156 -154
  86. package/src/data-structures/graph/directed-graph.ts +99 -94
  87. package/src/data-structures/graph/map-graph.ts +22 -25
  88. package/src/data-structures/graph/undirected-graph.ts +62 -60
  89. package/src/data-structures/hash/hash-table.ts +9 -9
  90. package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
  91. package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
  92. package/src/data-structures/queue/queue.ts +2 -2
  93. package/src/interfaces/binary-tree.ts +2 -2
  94. package/src/interfaces/graph.ts +3 -3
  95. package/test/integration/bst.test.ts +2 -2
  96. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
  97. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +3 -3
  98. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +8 -8
  99. package/test/unit/data-structures/binary-tree/bst.test.ts +4 -4
  100. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
  101. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
  102. package/test/unit/data-structures/graph/abstract-graph.test.ts +99 -2
  103. package/test/unit/data-structures/graph/directed-graph.test.ts +38 -23
  104. package/test/unit/data-structures/graph/map-graph.test.ts +23 -23
  105. package/test/unit/data-structures/graph/undirected-graph.test.ts +10 -2
  106. package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
  107. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
  108. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  109. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +15 -15
  110. package/test/unit/data-structures/queue/queue.test.ts +8 -8
  111. package/test/utils/big-o.ts +7 -7
@@ -92,52 +92,65 @@ describe('DirectedGraph Operation Test', () => {
92
92
  });
93
93
  });
94
94
 
95
- class MyVertex<V extends string> extends DirectedVertex<V> {
96
- constructor(key: VertexKey, val?: V) {
97
- super(key, val);
98
- this._data = val;
95
+ class MyVertex<V = any> extends DirectedVertex<V> {
96
+ constructor(key: VertexKey, value?: V) {
97
+ super(key, value);
98
+ this._data = value;
99
99
  }
100
100
 
101
- private _data: string | undefined;
101
+ private _data: V | undefined;
102
102
 
103
- get data(): string | undefined {
103
+ get data(): V | undefined {
104
104
  return this._data;
105
105
  }
106
106
 
107
- set data(value: string | undefined) {
107
+ set data(value: V | undefined) {
108
108
  this._data = value;
109
109
  }
110
110
  }
111
111
 
112
- class MyEdge<E extends string> extends DirectedEdge<E> {
113
- constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: E) {
114
- super(v1, v2, weight, val);
115
- this._data = val;
112
+ class MyEdge<E = any> extends DirectedEdge<E> {
113
+ constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E) {
114
+ super(v1, v2, weight, value);
115
+ this._data = value;
116
116
  }
117
117
 
118
- private _data: string | undefined;
118
+ private _data: E | undefined;
119
119
 
120
- get data(): string | undefined {
120
+ get data(): E | undefined {
121
121
  return this._data;
122
122
  }
123
123
 
124
- set data(value: string | undefined) {
124
+ set data(value: E | undefined) {
125
125
  this._data = value;
126
126
  }
127
127
  }
128
128
 
129
- class MyDirectedGraph<V extends MyVertex<string>, E extends MyEdge<string>> extends DirectedGraph<V, E> {
130
- createVertex(key: VertexKey, val: V['val']): V {
131
- return new MyVertex(key, val) as V;
129
+ class MyDirectedGraph<
130
+ V = any,
131
+ E = any,
132
+ VO extends MyVertex<V> = MyVertex<V>,
133
+ EO extends MyEdge<E> = MyEdge<E>
134
+ > extends DirectedGraph<V, E, VO, EO> {
135
+ createVertex(key: VertexKey, value: V): VO {
136
+ return new MyVertex(key, value) as VO;
137
+ }
138
+
139
+ createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO {
140
+ return new MyEdge(src, dest, weight ?? 1, value) as EO;
141
+ }
142
+
143
+ setInEdgeMap(value: Map<VO, EO[]>) {
144
+ super._setInEdgeMap(value);
132
145
  }
133
146
 
134
- createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E {
135
- return new MyEdge(src, dest, weight ?? 1, val) as E;
147
+ setOutEdgeMap(value: Map<VO, EO[]>) {
148
+ super._setOutEdgeMap(value);
136
149
  }
137
150
  }
138
151
 
139
152
  describe('Inherit from DirectedGraph and perform operations', () => {
140
- let myGraph = new MyDirectedGraph<MyVertex<string>, MyEdge<string>>();
153
+ let myGraph = new MyDirectedGraph<string, string>();
141
154
  beforeEach(() => {
142
155
  myGraph = new MyDirectedGraph();
143
156
  });
@@ -159,6 +172,8 @@ describe('Inherit from DirectedGraph and perform operations', () => {
159
172
  myGraph.addVertex(2, 'data2');
160
173
  myGraph.addEdge(1, 2, 10, 'edge-data1-2');
161
174
  myGraph.addEdge(new MyEdge(2, 1, 20, 'edge-data2-1'));
175
+ myGraph.setInEdgeMap(myGraph.inEdgeMap);
176
+ myGraph.setOutEdgeMap(myGraph.outEdgeMap);
162
177
 
163
178
  expect(myGraph.edgeSet().length).toBe(2);
164
179
  // TODO
@@ -177,7 +192,7 @@ describe('Inherit from DirectedGraph and perform operations', () => {
177
192
  expect(edge1).toBeInstanceOf(MyEdge);
178
193
  if (edge1) {
179
194
  expect(edge1.data).toBe('val1');
180
- expect(edge1?.val).toBe('val1');
195
+ expect(edge1?.value).toBe('val1');
181
196
  expect(edge1).toBeInstanceOf(MyEdge);
182
197
  expect(edge1.src).toBe(1);
183
198
  expect(edge1).toEqual(edge2);
@@ -199,7 +214,7 @@ describe('Inherit from DirectedGraph and perform operations', () => {
199
214
 
200
215
  expect(removedEdge).toBeInstanceOf(MyEdge);
201
216
  if (removedEdge) {
202
- removedEdge && expect(removedEdge.val).toBe('edge-data1-2');
217
+ removedEdge && expect(removedEdge.value).toBe('edge-data1-2');
203
218
  removedEdge && expect(removedEdge.src).toBe(1);
204
219
  }
205
220
  expect(edgeAfterRemoval).toBeNull();
@@ -234,7 +249,7 @@ describe('Inherit from DirectedGraph and perform operations', () => {
234
249
  });
235
250
 
236
251
  describe('Inherit from DirectedGraph and perform operations test2.', () => {
237
- const myGraph = new MyDirectedGraph<MyVertex<string>, MyEdge<string>>();
252
+ const myGraph = new MyDirectedGraph<string, string>();
238
253
 
239
254
  it('should test graph operations', () => {
240
255
  const vertex1 = new MyVertex(1, 'data1');
@@ -4,17 +4,17 @@ describe('MapGraph Operation Test', () => {
4
4
  it('dijkstra shortest path', () => {
5
5
  const mapGraph = new MapGraph([5.500338, 100.173665]);
6
6
 
7
- mapGraph.addVertex(new MapVertex('Surin', 5.466724, 100.274805));
8
- mapGraph.addVertex(new MapVertex('Batu Feringgi Beach', 5.475141, 100.27667));
9
- mapGraph.addVertex(new MapVertex('Lotus', 5.459044, 100.308767));
10
- mapGraph.addVertex(new MapVertex('The Breeza', 5.454197, 100.307859));
11
- mapGraph.addVertex(new MapVertex('Hard Rock Hotel', 5.46785, 100.241876));
12
- mapGraph.addVertex(new MapVertex('Mira', 5.456749, 100.28665));
13
- mapGraph.addVertex(new MapVertex('Penang Bible Church', 5.428683, 100.314825));
14
- mapGraph.addVertex(new MapVertex('Queensbay', 5.33276, 100.306651));
15
- mapGraph.addVertex(new MapVertex('Saanen Goat Farm', 5.405738, 100.207699));
16
- mapGraph.addVertex(new MapVertex('Trinity Auto', 5.401126, 100.303739));
17
- mapGraph.addVertex(new MapVertex('Penang Airport', 5.293185, 100.265772));
7
+ mapGraph.addVertex(new MapVertex('Surin', '', 5.466724, 100.274805));
8
+ mapGraph.addVertex(new MapVertex('Batu Feringgi Beach', '', 5.475141, 100.27667));
9
+ mapGraph.addVertex(new MapVertex('Lotus', '', 5.459044, 100.308767));
10
+ mapGraph.addVertex(new MapVertex('The Breeza', '', 5.454197, 100.307859));
11
+ mapGraph.addVertex(new MapVertex('Hard Rock Hotel', '', 5.46785, 100.241876));
12
+ mapGraph.addVertex(new MapVertex('Mira', '', 5.456749, 100.28665));
13
+ mapGraph.addVertex(new MapVertex('Penang Bible Church', '', 5.428683, 100.314825));
14
+ mapGraph.addVertex(new MapVertex('Queensbay', '', 5.33276, 100.306651));
15
+ mapGraph.addVertex(new MapVertex('Saanen Goat Farm', '', 5.405738, 100.207699));
16
+ mapGraph.addVertex(new MapVertex('Trinity Auto', '', 5.401126, 100.303739));
17
+ mapGraph.addVertex(new MapVertex('Penang Airport', '', 5.293185, 100.265772));
18
18
  mapGraph.addEdge('Surin', 'Lotus', 4.7);
19
19
  mapGraph.addEdge('Lotus', 'The Breeza', 1);
20
20
  mapGraph.addEdge('Batu Feringgi Beach', 'Hard Rock Hotel', 5.2);
@@ -45,17 +45,17 @@ describe('MapGraph Operation Test', () => {
45
45
  });
46
46
 
47
47
  describe('MapGraph', () => {
48
- let mapGraph: MapGraph;
48
+ let mapGraph: MapGraph<string, string>;
49
49
 
50
50
  beforeEach(() => {
51
51
  // Create a new MapGraph instance before each test
52
- mapGraph = new MapGraph([0, 0], [100, 100]);
52
+ mapGraph = new MapGraph<string, string>([0, 0], [100, 100]);
53
53
  });
54
54
 
55
55
  // Test adding vertices to the graph
56
56
  it('should add vertices to the graph', () => {
57
- const locationA = new MapVertex('A', 10, 20, 'Location A');
58
- const locationB = new MapVertex('B', 30, 40, 'Location B');
57
+ const locationA = new MapVertex('A', 'Location A', 10, 20);
58
+ const locationB = new MapVertex('B', 'Location B', 30, 40);
59
59
 
60
60
  mapGraph.addVertex(locationA);
61
61
  mapGraph.addVertex(locationB);
@@ -66,8 +66,8 @@ describe('MapGraph', () => {
66
66
 
67
67
  // Test adding edges to the graph
68
68
  it('should add edges to the graph', () => {
69
- const locationA = new MapVertex('A', 10, 20, 'Location A');
70
- const locationB = new MapVertex('B', 30, 40, 'Location B');
69
+ const locationA = new MapVertex('A', 'Location A', 10, 20);
70
+ const locationB = new MapVertex('B', 'Location B', 30, 40);
71
71
  const edgeAB = new MapEdge('A', 'B', 50, 'Edge from A to B');
72
72
 
73
73
  mapGraph.addVertex(locationA);
@@ -79,12 +79,12 @@ describe('MapGraph', () => {
79
79
 
80
80
  // Test getting neighbors of a vertex
81
81
  it('should return the neighbors of a vertex', () => {
82
- const locationA = new MapVertex('A', 10, 20, 'Location A');
82
+ const locationA = new MapVertex('A', 'Location A', 10, 20);
83
83
  locationA.lat = locationA.lat;
84
84
  locationA.long = locationA.long;
85
- const locationB = mapGraph.createVertex('B', 30, 40, 'Location B');
85
+ const locationB = mapGraph.createVertex('B', 'Location B', 30, 40);
86
86
 
87
- const locationC = new MapVertex('C', 50, 60, 'Location C');
87
+ const locationC = new MapVertex('C', 'Location C', 50, 60);
88
88
  const edgeAB = new MapEdge('A', 'B', 50, 'Edge from A to B');
89
89
  const edgeBC = new MapEdge('B', 'C', 60, 'Edge from B to C');
90
90
 
@@ -106,9 +106,9 @@ describe('MapGraph', () => {
106
106
 
107
107
  // Test finding the shortest path between locations
108
108
  it('should find the shortest path between two locations', () => {
109
- const locationA = new MapVertex('A', 10, 20, 'Location A');
110
- const locationB = new MapVertex('B', 30, 40, 'Location B');
111
- const locationC = new MapVertex('C', 50, 60, 'Location C');
109
+ const locationA = new MapVertex('A', 'Location A', 10, 20);
110
+ const locationB = new MapVertex('B', 'Location B', 30, 40);
111
+ const locationC = new MapVertex('C', 'Location C', 50, 60);
112
112
  const edgeAB = new MapEdge('A', 'B', 50, 'Edge from A to B');
113
113
  const edgeBC = new MapEdge('B', 'C', 60, 'Edge from B to C');
114
114
 
@@ -7,6 +7,14 @@ describe('UndirectedGraph Operation Test', () => {
7
7
  graph = new UndirectedGraph();
8
8
  });
9
9
 
10
+ it('should edge cases', () => {
11
+ expect(graph.deleteEdge(new UndirectedEdge('c', 'd'))).toBe(null);
12
+ expect(graph.deleteEdgeBetween('c', 'd')).toBe(null);
13
+ expect(graph.degreeOf('c')).toBe(0);
14
+ expect(graph.edgesOf('c').length).toBe(0);
15
+ expect(graph.getEndsOfEdge(new UndirectedEdge('c', 'd'))).toBe(null);
16
+ });
17
+
10
18
  it('should add vertices', () => {
11
19
  const vertex1 = new UndirectedVertex('A');
12
20
  const vertex2 = new UndirectedVertex('B');
@@ -59,11 +67,11 @@ describe('UndirectedGraph Operation Test', () => {
59
67
  });
60
68
 
61
69
  describe('UndirectedGraph', () => {
62
- let undirectedGraph: UndirectedGraph<UndirectedVertex<string>, UndirectedEdge<string>>;
70
+ let undirectedGraph: UndirectedGraph<string, string>;
63
71
 
64
72
  beforeEach(() => {
65
73
  // Create a new UndirectedGraph instance before each test
66
- undirectedGraph = new UndirectedGraph<UndirectedVertex<string>, UndirectedEdge<string>>();
74
+ undirectedGraph = new UndirectedGraph<string, string>();
67
75
  });
68
76
 
69
77
  // Test adding vertices to the graph
@@ -7,7 +7,7 @@ describe('HashNode', () => {
7
7
  const hashNode = new HashTableNode(key, value);
8
8
 
9
9
  expect(hashNode.key).toBe(key);
10
- expect(hashNode.val).toBe(value);
10
+ expect(hashNode.value).toBe(value);
11
11
  expect(hashNode.next).toBe(null);
12
12
  });
13
13
  });
@@ -4,9 +4,9 @@ import {bigO, magnitude} from '../../../utils';
4
4
  describe('DoublyLinkedListNode', () => {
5
5
  it('should DoublyLinkedListNode', () => {
6
6
  const node1 = new DoublyLinkedListNode<number>(2);
7
- expect(node1.val).toBe(2);
8
- node1.val = 1;
9
- expect(node1.val).toBe(1);
7
+ expect(node1.value).toBe(2);
8
+ node1.value = 1;
9
+ expect(node1.value).toBe(1);
10
10
  });
11
11
  });
12
12
 
@@ -33,13 +33,13 @@ describe('DoublyLinkedList Operation Test', () => {
33
33
 
34
34
  it('should delete tail', () => {
35
35
  expect(list.delete(list.tail)).toBe(true);
36
- expect(list.tail?.val).toBe(4);
36
+ expect(list.tail?.value).toBe(4);
37
37
  expect(list.delete(6)).toBe(false);
38
- expect(list.tail?.val).toBe(4);
38
+ expect(list.tail?.value).toBe(4);
39
39
  });
40
40
 
41
41
  it('should find null', () => {
42
- expect(list.find(val => val === 6)).toBe(null);
42
+ expect(list.find(value => value === 6)).toBe(null);
43
43
  });
44
44
 
45
45
  it('should indexOf -1', () => {
@@ -47,7 +47,7 @@ describe('DoublyLinkedList Operation Test', () => {
47
47
  });
48
48
 
49
49
  it('should findBackward null', () => {
50
- expect(list.findBackward(val => val === 0)).toBe(null);
50
+ expect(list.findBackward(value => value === 0)).toBe(null);
51
51
  });
52
52
 
53
53
  it('should insertAfter tail', () => {
@@ -80,8 +80,8 @@ describe('DoublyLinkedList Operation Test', () => {
80
80
  list.push(2);
81
81
  list.push(3);
82
82
  expect(list.length).toBe(3);
83
- expect(list.head!.val).toBe(1);
84
- expect(list.tail!.val).toBe(3);
83
+ expect(list.head!.value).toBe(1);
84
+ expect(list.tail!.value).toBe(3);
85
85
  });
86
86
 
87
87
  it('should pop elements from the end of the list', () => {
@@ -90,8 +90,8 @@ describe('DoublyLinkedList Operation Test', () => {
90
90
  const poppedValue = list.pop();
91
91
  expect(poppedValue).toBe(2);
92
92
  expect(list.length).toBe(1);
93
- expect(list.head!.val).toBe(1);
94
- expect(list.tail!.val).toBe(1);
93
+ expect(list.head!.value).toBe(1);
94
+ expect(list.tail!.value).toBe(1);
95
95
  });
96
96
  it('should insert elements at specific positions', () => {
97
97
  list.push(1);
@@ -114,7 +114,7 @@ describe('DoublyLinkedList Operation Test', () => {
114
114
  list.insertAt(5, 4);
115
115
  expect(list.length).toBe(6);
116
116
  expect(list.getAt(5)).toBe(4);
117
- expect(list.tail!.val).toBe(4);
117
+ expect(list.tail!.value).toBe(4);
118
118
  });
119
119
 
120
120
  it('should delete elements at specific positions', () => {
@@ -126,12 +126,12 @@ describe('DoublyLinkedList Operation Test', () => {
126
126
  const deletedValue = list.deleteAt(0);
127
127
  expect(deletedValue).toBe(1);
128
128
  expect(list.length).toBe(2);
129
- expect(list.head!.val).toBe(2);
129
+ expect(list.head!.value).toBe(2);
130
130
 
131
131
  // Deleting from the middle
132
132
  list.deleteAt(0); // Deleting the second element
133
133
  expect(list.length).toBe(1);
134
- expect(list.head!.val).toBe(3);
134
+ expect(list.head!.value).toBe(3);
135
135
 
136
136
  // Deleting from the end
137
137
  list.deleteAt(0);
@@ -147,12 +147,12 @@ describe('DoublyLinkedList Operation Test', () => {
147
147
 
148
148
  list.delete(2);
149
149
  expect(list.length).toBe(2);
150
- expect(list.head!.val).toBe(1);
151
- expect(list.tail!.val).toBe(3);
150
+ expect(list.head!.value).toBe(1);
151
+ expect(list.tail!.value).toBe(3);
152
152
 
153
153
  list.delete(1);
154
154
  expect(list.length).toBe(1);
155
- expect(list.head!.val).toBe(3);
155
+ expect(list.head!.value).toBe(3);
156
156
 
157
157
  list.delete(3);
158
158
  expect(list.length).toBe(0);
@@ -176,7 +176,7 @@ describe('DoublyLinkedList Operation Test', () => {
176
176
  list.push(2);
177
177
  list.push(3);
178
178
 
179
- const mappedList = list.map(val => val * 2);
179
+ const mappedList = list.map(value => value * 2);
180
180
 
181
181
  expect(mappedList.toArray()).toEqual([2, 4, 6]);
182
182
  });
@@ -187,7 +187,7 @@ describe('DoublyLinkedList Operation Test', () => {
187
187
  list.push(3);
188
188
  list.push(4);
189
189
 
190
- const filteredList = list.filter(val => val % 2 === 0);
190
+ const filteredList = list.filter(value => value % 2 === 0);
191
191
 
192
192
  expect(filteredList.toArray()).toEqual([2, 4]);
193
193
  });
@@ -198,7 +198,7 @@ describe('DoublyLinkedList Operation Test', () => {
198
198
  list.push(3);
199
199
  list.push(4);
200
200
 
201
- const sum = list.reduce((acc, val) => acc + val, 0);
201
+ const sum = list.reduce((acc, value) => acc + value, 0);
202
202
 
203
203
  expect(sum).toBe(10);
204
204
  });
@@ -227,7 +227,7 @@ describe('DoublyLinkedList Operation Test', () => {
227
227
  list.push(2);
228
228
  list.push(3);
229
229
 
230
- const found = list.find(val => val % 2 === 0);
230
+ const found = list.find(value => value % 2 === 0);
231
231
 
232
232
  expect(found).toBe(2);
233
233
  });
@@ -248,7 +248,7 @@ describe('DoublyLinkedList Operation Test', () => {
248
248
  list.push(3);
249
249
  list.push(4);
250
250
 
251
- const lastEven = list.findBackward(val => val % 2 === 0);
251
+ const lastEven = list.findBackward(value => value % 2 === 0);
252
252
 
253
253
  expect(lastEven).toBe(4);
254
254
  });
@@ -283,8 +283,8 @@ describe('DoublyLinkedList Operation Test', () => {
283
283
  list.reverse();
284
284
 
285
285
  expect(list.toArray()).toEqual([3, 2, 1]);
286
- expect(list.head?.val).toBe(3);
287
- expect(list.tail?.val).toBe(1);
286
+ expect(list.head?.value).toBe(3);
287
+ expect(list.tail?.value).toBe(1);
288
288
  });
289
289
 
290
290
  it('should iterate over each element and apply a callback', () => {
@@ -293,8 +293,8 @@ describe('DoublyLinkedList Operation Test', () => {
293
293
  list.push(3);
294
294
 
295
295
  const result: number[] = [];
296
- list.forEach(val => {
297
- result.push(val * 2);
296
+ list.forEach(value => {
297
+ result.push(value * 2);
298
298
  });
299
299
 
300
300
  expect(result).toEqual([2, 4, 6]);
@@ -305,7 +305,7 @@ describe('DoublyLinkedList Operation Test', () => {
305
305
  list.push(2);
306
306
  list.push(3);
307
307
 
308
- const mappedList = list.map(val => val * 2);
308
+ const mappedList = list.map(value => value * 2);
309
309
 
310
310
  expect(mappedList.toArray()).toEqual([2, 4, 6]);
311
311
  });
@@ -316,7 +316,7 @@ describe('DoublyLinkedList Operation Test', () => {
316
316
  list.push(3);
317
317
  list.push(4);
318
318
 
319
- const filteredList = list.filter(val => val % 2 === 0);
319
+ const filteredList = list.filter(value => value % 2 === 0);
320
320
 
321
321
  expect(filteredList.toArray()).toEqual([2, 4]);
322
322
  });
@@ -326,7 +326,7 @@ describe('DoublyLinkedList Operation Test', () => {
326
326
  list.push(2);
327
327
  list.push(3);
328
328
 
329
- const sum = list.reduce((acc, val) => acc + val, 0);
329
+ const sum = list.reduce((acc, value) => acc + value, 0);
330
330
 
331
331
  expect(sum).toBe(6);
332
332
  });
@@ -387,7 +387,7 @@ describe('DoublyLinkedList Operation Test', () => {
387
387
  expect(insertSuccess).toBe(true);
388
388
 
389
389
  const getNode = objectList.getNode(newObj); // Use newObj instead of obj2
390
- expect(getNode?.val).toEqual(newObj);
390
+ expect(getNode?.value).toEqual(newObj);
391
391
 
392
392
  const deleted = objectList.delete(newObj); // Use newObj instead of obj2
393
393
  expect(deleted).toBe(true);
@@ -26,7 +26,7 @@ describe('LinkedList Performance Test', () => {
26
26
  if (i === midIndex) {
27
27
  midSinglyNode = singlyList.getNode(i);
28
28
  } else if (i > midIndex && midSinglyNode) {
29
- singlyList.insertBefore(midSinglyNode.val, i);
29
+ singlyList.insertBefore(midSinglyNode.value, i);
30
30
  }
31
31
  }
32
32
 
@@ -4,9 +4,9 @@ import {bigO, magnitude} from '../../../utils';
4
4
  describe('SinglyLinkedListNode', () => {
5
5
  it('should SinglyLinkedList', () => {
6
6
  const node1 = new SinglyLinkedListNode<number>(2);
7
- expect(node1.val).toBe(2);
8
- node1.val = 1;
9
- expect(node1.val).toBe(1);
7
+ expect(node1.value).toBe(2);
8
+ node1.value = 1;
9
+ expect(node1.value).toBe(1);
10
10
  });
11
11
  });
12
12
 
@@ -75,7 +75,7 @@ describe('SinglyLinkedList Operation Test', () => {
75
75
  list.push(3);
76
76
  const element = list.getAt(1);
77
77
  expect(element).toBe(2);
78
- expect(list.getNodeAt(2)?.val).toBe(3);
78
+ expect(list.getNodeAt(2)?.value).toBe(3);
79
79
  });
80
80
 
81
81
  it('should return undefined for an out-of-bounds index', () => {
@@ -382,7 +382,7 @@ describe('SinglyLinkedList Operation Test', () => {
382
382
  expect(insertSuccess).toBe(true);
383
383
 
384
384
  const getNode = objectList.getNode(newObj); // Use newObj instead of obj2
385
- expect(getNode?.val).toEqual(newObj);
385
+ expect(getNode?.value).toEqual(newObj);
386
386
 
387
387
  const deleted = objectList.delete(newObj); // Use newObj instead of obj2
388
388
  expect(deleted).toBe(true);
@@ -431,8 +431,8 @@ describe('SinglyLinkedList', () => {
431
431
  it('should push elements to the end of the list', () => {
432
432
  list.push(1);
433
433
  list.push(2);
434
- expect(list.head!.val).toBe(1);
435
- expect(list.tail!.val).toBe(2);
434
+ expect(list.head!.value).toBe(1);
435
+ expect(list.tail!.value).toBe(2);
436
436
  expect(list.length).toBe(2);
437
437
  });
438
438
 
@@ -441,8 +441,8 @@ describe('SinglyLinkedList', () => {
441
441
  list.push(2);
442
442
  const popped = list.pop();
443
443
  expect(popped).toBe(2);
444
- expect(list.head!.val).toBe(1);
445
- expect(list.tail!.val).toBe(1);
444
+ expect(list.head!.value).toBe(1);
445
+ expect(list.tail!.value).toBe(1);
446
446
  expect(list.length).toBe(1);
447
447
  });
448
448
 
@@ -451,8 +451,8 @@ describe('SinglyLinkedList', () => {
451
451
  list.push(2);
452
452
  list.push(3);
453
453
  list.reverse();
454
- expect(list.head!.val).toBe(3);
455
- expect(list.tail!.val).toBe(1);
454
+ expect(list.head!.value).toBe(3);
455
+ expect(list.tail!.value).toBe(1);
456
456
  // Add more assertions for reversed order.
457
457
  });
458
458
 
@@ -470,14 +470,14 @@ describe('SinglyLinkedList', () => {
470
470
  list.push(1);
471
471
  list.push(2);
472
472
  list.push(3);
473
- expect(list.filter(val => val !== 2).toArray()).toEqual([1, 3]);
473
+ expect(list.filter(value => value !== 2).toArray()).toEqual([1, 3]);
474
474
  });
475
475
 
476
476
  it('should forEach the list', () => {
477
477
  list.push(1);
478
478
  list.push(2);
479
479
  list.push(3);
480
- list.forEach(val => val++);
480
+ list.forEach(value => value++);
481
481
  expect(list.toArray()).toEqual([1, 2, 3]);
482
482
  });
483
483
 
@@ -485,11 +485,11 @@ describe('SinglyLinkedList', () => {
485
485
  list.addLast(1);
486
486
  list.push(2);
487
487
  list.push(3);
488
- expect(list.map(val => val * 2).toArray()).toEqual([2, 4, 6]);
488
+ expect(list.map(value => value * 2).toArray()).toEqual([2, 4, 6]);
489
489
  });
490
490
 
491
491
  it('should reduce the list', () => {
492
492
  const list1 = SinglyLinkedList.fromArray([1, 2, 3]);
493
- expect(list1.reduce((acc, val) => acc + val, 0)).toEqual(6);
493
+ expect(list1.reduce((acc, value) => acc + value, 0)).toEqual(6);
494
494
  });
495
495
  });
@@ -1,4 +1,4 @@
1
- import {LinkedListQueue, Queue} from '../../../../src';
1
+ import {SkipQueue, Queue} from '../../../../src';
2
2
  import {bigO, magnitude} from '../../../utils';
3
3
  import {isDebugTest} from '../../../config';
4
4
 
@@ -168,11 +168,11 @@ describe('Queue', () => {
168
168
  expect(values).toEqual([1, 2, 3]);
169
169
  });
170
170
  });
171
- describe('LinkedListQueue', () => {
172
- let queue: LinkedListQueue<string>;
171
+ describe('SkipQueue', () => {
172
+ let queue: SkipQueue<string>;
173
173
 
174
174
  beforeEach(() => {
175
- queue = new LinkedListQueue<string>();
175
+ queue = new SkipQueue<string>();
176
176
  });
177
177
 
178
178
  it('should enqueue elements to the end of the queue', () => {
@@ -197,7 +197,7 @@ describe('LinkedListQueue', () => {
197
197
  expect(queue.peek()).toBe('A');
198
198
  });
199
199
 
200
- // Add more test cases for other methods of LinkedListQueue.
200
+ // Add more test cases for other methods of SkipQueue.
201
201
  });
202
202
 
203
203
  describe('Queue Performance Test', () => {
@@ -228,16 +228,16 @@ describe('Queue Performance Test', () => {
228
228
  expect(performance.now() - startTime2).toBeLessThan(bigO.CUBED * 100);
229
229
  });
230
230
 
231
- it('should numeric LinkedListQueue be efficient', function () {
231
+ it('should numeric SkipQueue be efficient', function () {
232
232
  const startTime = performance.now();
233
- const queue = new LinkedListQueue<number>();
233
+ const queue = new SkipQueue<number>();
234
234
  for (let i = 0; i < dataSize; i++) {
235
235
  queue.enqueue(i);
236
236
  }
237
237
  for (let i = 0; i < dataSize; i++) {
238
238
  queue.dequeue();
239
239
  }
240
- console.log(`LinkedListQueue Performance Test: ${performance.now() - startTime} ms`);
240
+ console.log(`SkipQueue Performance Test: ${performance.now() - startTime} ms`);
241
241
  expect(performance.now() - startTime).toBeLessThan(bigO.LINEAR * 100);
242
242
  });
243
243
  });
@@ -59,19 +59,19 @@ function findPotentialN(input: any): number {
59
59
  function linearRegression(x: number[], y: number[]) {
60
60
  const n = x.length;
61
61
 
62
- const sumX = x.reduce((acc, val) => acc + val, 0);
63
- const sumY = y.reduce((acc, val) => acc + val, 0);
62
+ const sumX = x.reduce((acc, value) => acc + value, 0);
63
+ const sumY = y.reduce((acc, value) => acc + value, 0);
64
64
 
65
- const sumXSquared = x.reduce((acc, val) => acc + val ** 2, 0);
66
- const sumXY = x.reduce((acc, val, i) => acc + val * y[i], 0);
65
+ const sumXSquared = x.reduce((acc, value) => acc + value ** 2, 0);
66
+ const sumXY = x.reduce((acc, value, i) => acc + value * y[i], 0);
67
67
 
68
68
  const slope = (n * sumXY - sumX * sumY) / (n * sumXSquared - sumX ** 2);
69
69
  const intercept = (sumY - slope * sumX) / n;
70
70
 
71
- const yHat = x.map(val => slope * val + intercept);
71
+ const yHat = x.map(value => slope * value + intercept);
72
72
 
73
- const totalVariation = y.map((val, i) => (val - yHat[i]) ** 2).reduce((acc, val) => acc + val, 0);
74
- const explainedVariation = y.map(val => (val - sumY / n) ** 2).reduce((acc, val) => acc + val, 0);
73
+ const totalVariation = y.map((value, i) => (value - yHat[i]) ** 2).reduce((acc, value) => acc + value, 0);
74
+ const explainedVariation = y.map(value => (value - sumY / n) ** 2).reduce((acc, value) => acc + value, 0);
75
75
 
76
76
  const rSquared = 1 - totalVariation / explainedVariation;
77
77