bst-typed 1.48.4 → 1.48.5

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 (38) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +6 -6
  2. package/dist/data-structures/base/iterable-base.js +3 -3
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -3
  4. package/dist/data-structures/binary-tree/avl-tree.js +6 -4
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -15
  6. package/dist/data-structures/binary-tree/binary-tree.js +16 -13
  7. package/dist/data-structures/binary-tree/bst.d.ts +15 -11
  8. package/dist/data-structures/binary-tree/bst.js +17 -13
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +19 -13
  10. package/dist/data-structures/binary-tree/rb-tree.js +20 -14
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +21 -14
  12. package/dist/data-structures/binary-tree/tree-multimap.js +25 -18
  13. package/dist/data-structures/graph/abstract-graph.d.ts +52 -52
  14. package/dist/data-structures/graph/abstract-graph.js +78 -78
  15. package/dist/data-structures/graph/directed-graph.d.ts +47 -47
  16. package/dist/data-structures/graph/directed-graph.js +56 -56
  17. package/dist/data-structures/graph/map-graph.d.ts +5 -5
  18. package/dist/data-structures/graph/map-graph.js +8 -8
  19. package/dist/data-structures/graph/undirected-graph.d.ts +29 -29
  20. package/dist/data-structures/graph/undirected-graph.js +57 -57
  21. package/dist/data-structures/hash/hash-map.d.ts +8 -8
  22. package/dist/data-structures/hash/hash-map.js +2 -2
  23. package/dist/interfaces/binary-tree.d.ts +1 -1
  24. package/dist/types/data-structures/base/base.d.ts +3 -3
  25. package/package.json +2 -2
  26. package/src/data-structures/base/iterable-base.ts +6 -6
  27. package/src/data-structures/binary-tree/avl-tree.ts +8 -5
  28. package/src/data-structures/binary-tree/binary-tree.ts +23 -19
  29. package/src/data-structures/binary-tree/bst.ts +19 -14
  30. package/src/data-structures/binary-tree/rb-tree.ts +20 -14
  31. package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
  32. package/src/data-structures/graph/abstract-graph.ts +82 -82
  33. package/src/data-structures/graph/directed-graph.ts +56 -56
  34. package/src/data-structures/graph/map-graph.ts +8 -8
  35. package/src/data-structures/graph/undirected-graph.ts +59 -59
  36. package/src/data-structures/hash/hash-map.ts +8 -8
  37. package/src/interfaces/binary-tree.ts +1 -1
  38. package/src/types/data-structures/base/base.ts +3 -3
@@ -12,7 +12,7 @@ export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
12
12
  constructor(key: VertexKey, value?: V);
13
13
  }
14
14
  export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
15
- vertices: [VertexKey, VertexKey];
15
+ vertexMap: [VertexKey, VertexKey];
16
16
  /**
17
17
  * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
18
18
  * value.
@@ -27,11 +27,11 @@ export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
27
27
  }
28
28
  export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
29
29
  /**
30
- * The constructor initializes a new Map object to store edges.
30
+ * The constructor initializes a new Map object to store edgeMap.
31
31
  */
32
32
  constructor();
33
- protected _edges: Map<VO, EO[]>;
34
- get edges(): Map<VO, EO[]>;
33
+ protected _edgeMap: Map<VO, EO[]>;
34
+ get edgeMap(): Map<VO, EO[]>;
35
35
  /**
36
36
  * The function creates a new vertex with an optional value and returns it.
37
37
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
@@ -43,7 +43,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
43
43
  */
44
44
  createVertex(key: VertexKey, value?: VO['value']): VO;
45
45
  /**
46
- * The function creates an undirected edge between two vertices with an optional weight and value.
46
+ * The function creates an undirected edge between two vertexMap with an optional weight and value.
47
47
  * @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
48
48
  * @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
49
49
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
@@ -54,14 +54,14 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
54
54
  */
55
55
  createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
56
56
  /**
57
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
57
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
58
58
  * Space Complexity: O(1)
59
59
  */
60
60
  /**
61
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
61
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
62
62
  * Space Complexity: O(1)
63
63
  *
64
- * The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
64
+ * The function `getEdge` returns the first edge that connects two vertexMap, or undefined if no such edge exists.
65
65
  * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
66
66
  * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
67
67
  * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
@@ -70,29 +70,29 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
70
70
  */
71
71
  getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
72
72
  /**
73
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
73
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
74
74
  * Space Complexity: O(1)
75
75
  */
76
76
  /**
77
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
77
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
78
78
  * Space Complexity: O(1)
79
79
  *
80
- * The function removes an edge between two vertices in a graph and returns the removed edge.
80
+ * The function removes an edge between two vertexMap in a graph and returns the removed edge.
81
81
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
82
82
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
83
83
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
84
- * @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
84
+ * @returns the removed edge (EO) if it exists, or undefined if either of the vertexMap (VO) does not exist.
85
85
  */
86
86
  deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined;
87
87
  /**
88
- * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
88
+ * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
89
89
  * Space Complexity: O(1)
90
90
  */
91
91
  /**
92
- * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
92
+ * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
93
93
  * Space Complexity: O(1)
94
94
  *
95
- * The function `deleteEdge` deletes an edge between two vertices in a graph.
95
+ * The function `deleteEdge` deletes an edge between two vertexMap in a graph.
96
96
  * @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
97
97
  * either an edge object or a vertex key.
98
98
  * @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
@@ -124,11 +124,11 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
124
124
  * Time Complexity: O(1)
125
125
  * Space Complexity: O(1)
126
126
  *
127
- * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
127
+ * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
128
128
  * vertex.
129
129
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
130
130
  * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
131
- * edges connected to that vertex.
131
+ * edgeMap connected to that vertex.
132
132
  */
133
133
  degreeOf(vertexOrKey: VertexKey | VO): number;
134
134
  /**
@@ -139,36 +139,36 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
139
139
  * Time Complexity: O(1)
140
140
  * Space Complexity: O(1)
141
141
  *
142
- * The function returns the edges of a given vertex or vertex ID.
142
+ * The function returns the edgeMap of a given vertex or vertex ID.
143
143
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
144
144
  * unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
145
- * @returns an array of edges.
145
+ * @returns an array of edgeMap.
146
146
  */
147
147
  edgesOf(vertexOrKey: VertexKey | VO): EO[];
148
148
  /**
149
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
149
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
150
150
  * Space Complexity: O(|E|)
151
151
  */
152
152
  /**
153
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
153
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
154
154
  * Space Complexity: O(|E|)
155
155
  *
156
- * The function "edgeSet" returns an array of unique edges from a set of edges.
156
+ * The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
157
157
  * @returns The method `edgeSet()` returns an array of type `EO[]`.
158
158
  */
159
159
  edgeSet(): EO[];
160
160
  /**
161
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
161
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
162
162
  * Space Complexity: O(|E|)
163
163
  */
164
164
  /**
165
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
165
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
166
166
  * Space Complexity: O(|E|)
167
167
  *
168
- * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
168
+ * The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
169
169
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
170
170
  * (`VertexKey`).
171
- * @returns an array of vertices (VO[]).
171
+ * @returns an array of vertexMap (VO[]).
172
172
  */
173
173
  getNeighbors(vertexOrKey: VO | VertexKey): VO[];
174
174
  /**
@@ -179,10 +179,10 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
179
179
  * Time Complexity: O(1)
180
180
  * Space Complexity: O(1)
181
181
  *
182
- * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
182
+ * The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
183
183
  * it returns undefined.
184
184
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
185
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
185
+ * @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
186
186
  * graph. If the edge does not exist, it returns `undefined`.
187
187
  */
188
188
  getEndsOfEdge(edge: EO): [VO, VO] | undefined;
@@ -194,7 +194,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
194
194
  * Time Complexity: O(1)
195
195
  * Space Complexity: O(1)
196
196
  *
197
- * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
197
+ * The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
198
198
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
199
199
  * @returns a boolean value.
200
200
  */
@@ -36,20 +36,20 @@ class UndirectedEdge extends abstract_graph_1.AbstractEdge {
36
36
  */
37
37
  constructor(v1, v2, weight, value) {
38
38
  super(weight, value);
39
- this.vertices = [v1, v2];
39
+ this.vertexMap = [v1, v2];
40
40
  }
41
41
  }
42
42
  exports.UndirectedEdge = UndirectedEdge;
43
43
  class UndirectedGraph extends abstract_graph_1.AbstractGraph {
44
44
  /**
45
- * The constructor initializes a new Map object to store edges.
45
+ * The constructor initializes a new Map object to store edgeMap.
46
46
  */
47
47
  constructor() {
48
48
  super();
49
- this._edges = new Map();
49
+ this._edgeMap = new Map();
50
50
  }
51
- get edges() {
52
- return this._edges;
51
+ get edgeMap() {
52
+ return this._edgeMap;
53
53
  }
54
54
  /**
55
55
  * The function creates a new vertex with an optional value and returns it.
@@ -64,7 +64,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
64
64
  return new UndirectedVertex(key, value !== null && value !== void 0 ? value : key);
65
65
  }
66
66
  /**
67
- * The function creates an undirected edge between two vertices with an optional weight and value.
67
+ * The function creates an undirected edge between two vertexMap with an optional weight and value.
68
68
  * @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
69
69
  * @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
70
70
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
@@ -77,14 +77,14 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
77
77
  return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, value);
78
78
  }
79
79
  /**
80
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
80
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
81
81
  * Space Complexity: O(1)
82
82
  */
83
83
  /**
84
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
84
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
85
85
  * Space Complexity: O(1)
86
86
  *
87
- * The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
87
+ * The function `getEdge` returns the first edge that connects two vertexMap, or undefined if no such edge exists.
88
88
  * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
89
89
  * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
90
90
  * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
@@ -93,29 +93,29 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
93
93
  */
94
94
  getEdge(v1, v2) {
95
95
  var _a;
96
- let edges = [];
96
+ let edgeMap = [];
97
97
  if (v1 !== undefined && v2 !== undefined) {
98
98
  const vertex1 = this._getVertex(v1);
99
99
  const vertex2 = this._getVertex(v2);
100
100
  if (vertex1 && vertex2) {
101
- edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.key));
101
+ edgeMap = (_a = this._edgeMap.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertexMap.includes(vertex2.key));
102
102
  }
103
103
  }
104
- return edges ? edges[0] || undefined : undefined;
104
+ return edgeMap ? edgeMap[0] || undefined : undefined;
105
105
  }
106
106
  /**
107
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
107
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
108
108
  * Space Complexity: O(1)
109
109
  */
110
110
  /**
111
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
111
+ * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
112
112
  * Space Complexity: O(1)
113
113
  *
114
- * The function removes an edge between two vertices in a graph and returns the removed edge.
114
+ * The function removes an edge between two vertexMap in a graph and returns the removed edge.
115
115
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
116
116
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
117
117
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
118
- * @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
118
+ * @returns the removed edge (EO) if it exists, or undefined if either of the vertexMap (VO) does not exist.
119
119
  */
120
120
  deleteEdgeBetween(v1, v2) {
121
121
  const vertex1 = this._getVertex(v1);
@@ -123,26 +123,26 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
123
123
  if (!vertex1 || !vertex2) {
124
124
  return undefined;
125
125
  }
126
- const v1Edges = this._edges.get(vertex1);
126
+ const v1Edges = this._edgeMap.get(vertex1);
127
127
  let removed = undefined;
128
128
  if (v1Edges) {
129
- removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertices.includes(vertex2.key))[0] || undefined;
129
+ removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertexMap.includes(vertex2.key))[0] || undefined;
130
130
  }
131
- const v2Edges = this._edges.get(vertex2);
131
+ const v2Edges = this._edgeMap.get(vertex2);
132
132
  if (v2Edges) {
133
- (0, utils_1.arrayRemove)(v2Edges, (e) => e.vertices.includes(vertex1.key));
133
+ (0, utils_1.arrayRemove)(v2Edges, (e) => e.vertexMap.includes(vertex1.key));
134
134
  }
135
135
  return removed;
136
136
  }
137
137
  /**
138
- * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
138
+ * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
139
139
  * Space Complexity: O(1)
140
140
  */
141
141
  /**
142
- * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
142
+ * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
143
143
  * Space Complexity: O(1)
144
144
  *
145
- * The function `deleteEdge` deletes an edge between two vertices in a graph.
145
+ * The function `deleteEdge` deletes an edge between two vertexMap in a graph.
146
146
  * @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
147
147
  * either an edge object or a vertex key.
148
148
  * @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
@@ -163,8 +163,8 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
163
163
  }
164
164
  }
165
165
  else {
166
- oneSide = this._getVertex(edgeOrOneSideVertexKey.vertices[0]);
167
- otherSide = this._getVertex(edgeOrOneSideVertexKey.vertices[1]);
166
+ oneSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[0]);
167
+ otherSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[1]);
168
168
  }
169
169
  if (oneSide && otherSide) {
170
170
  return this.deleteEdgeBetween(oneSide, otherSide);
@@ -200,17 +200,17 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
200
200
  const neighbors = this.getNeighbors(vertexOrKey);
201
201
  if (vertex) {
202
202
  neighbors.forEach(neighbor => {
203
- const neighborEdges = this._edges.get(neighbor);
203
+ const neighborEdges = this._edgeMap.get(neighbor);
204
204
  if (neighborEdges) {
205
205
  const restEdges = neighborEdges.filter(edge => {
206
- return !edge.vertices.includes(vertexKey);
206
+ return !edge.vertexMap.includes(vertexKey);
207
207
  });
208
- this._edges.set(neighbor, restEdges);
208
+ this._edgeMap.set(neighbor, restEdges);
209
209
  }
210
210
  });
211
- this._edges.delete(vertex);
211
+ this._edgeMap.delete(vertex);
212
212
  }
213
- return this._vertices.delete(vertexKey);
213
+ return this._vertexMap.delete(vertexKey);
214
214
  }
215
215
  /**
216
216
  * Time Complexity: O(1)
@@ -220,17 +220,17 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
220
220
  * Time Complexity: O(1)
221
221
  * Space Complexity: O(1)
222
222
  *
223
- * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
223
+ * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
224
224
  * vertex.
225
225
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
226
226
  * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
227
- * edges connected to that vertex.
227
+ * edgeMap connected to that vertex.
228
228
  */
229
229
  degreeOf(vertexOrKey) {
230
230
  var _a;
231
231
  const vertex = this._getVertex(vertexOrKey);
232
232
  if (vertex) {
233
- return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
233
+ return ((_a = this._edgeMap.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
234
234
  }
235
235
  else {
236
236
  return 0;
@@ -244,52 +244,52 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
244
244
  * Time Complexity: O(1)
245
245
  * Space Complexity: O(1)
246
246
  *
247
- * The function returns the edges of a given vertex or vertex ID.
247
+ * The function returns the edgeMap of a given vertex or vertex ID.
248
248
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
249
249
  * unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
250
- * @returns an array of edges.
250
+ * @returns an array of edgeMap.
251
251
  */
252
252
  edgesOf(vertexOrKey) {
253
253
  const vertex = this._getVertex(vertexOrKey);
254
254
  if (vertex) {
255
- return this._edges.get(vertex) || [];
255
+ return this._edgeMap.get(vertex) || [];
256
256
  }
257
257
  else {
258
258
  return [];
259
259
  }
260
260
  }
261
261
  /**
262
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
262
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
263
263
  * Space Complexity: O(|E|)
264
264
  */
265
265
  /**
266
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
266
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
267
267
  * Space Complexity: O(|E|)
268
268
  *
269
- * The function "edgeSet" returns an array of unique edges from a set of edges.
269
+ * The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
270
270
  * @returns The method `edgeSet()` returns an array of type `EO[]`.
271
271
  */
272
272
  edgeSet() {
273
273
  const edgeSet = new Set();
274
- this._edges.forEach(edges => {
275
- edges.forEach(edge => {
274
+ this._edgeMap.forEach(edgeMap => {
275
+ edgeMap.forEach(edge => {
276
276
  edgeSet.add(edge);
277
277
  });
278
278
  });
279
279
  return [...edgeSet];
280
280
  }
281
281
  /**
282
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
282
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
283
283
  * Space Complexity: O(|E|)
284
284
  */
285
285
  /**
286
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
286
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
287
287
  * Space Complexity: O(|E|)
288
288
  *
289
- * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
289
+ * The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
290
290
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
291
291
  * (`VertexKey`).
292
- * @returns an array of vertices (VO[]).
292
+ * @returns an array of vertexMap (VO[]).
293
293
  */
294
294
  getNeighbors(vertexOrKey) {
295
295
  const neighbors = [];
@@ -297,7 +297,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
297
297
  if (vertex) {
298
298
  const neighborEdges = this.edgesOf(vertex);
299
299
  for (const edge of neighborEdges) {
300
- const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.key)[0]);
300
+ const neighbor = this._getVertex(edge.vertexMap.filter(e => e !== vertex.key)[0]);
301
301
  if (neighbor) {
302
302
  neighbors.push(neighbor);
303
303
  }
@@ -313,18 +313,18 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
313
313
  * Time Complexity: O(1)
314
314
  * Space Complexity: O(1)
315
315
  *
316
- * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
316
+ * The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
317
317
  * it returns undefined.
318
318
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
319
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
319
+ * @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
320
320
  * graph. If the edge does not exist, it returns `undefined`.
321
321
  */
322
322
  getEndsOfEdge(edge) {
323
- if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
323
+ if (!this.hasEdge(edge.vertexMap[0], edge.vertexMap[1])) {
324
324
  return undefined;
325
325
  }
326
- const v1 = this._getVertex(edge.vertices[0]);
327
- const v2 = this._getVertex(edge.vertices[1]);
326
+ const v1 = this._getVertex(edge.vertexMap[0]);
327
+ const v2 = this._getVertex(edge.vertexMap[1]);
328
328
  if (v1 && v2) {
329
329
  return [v1, v2];
330
330
  }
@@ -340,22 +340,22 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
340
340
  * Time Complexity: O(1)
341
341
  * Space Complexity: O(1)
342
342
  *
343
- * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
343
+ * The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
344
344
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
345
345
  * @returns a boolean value.
346
346
  */
347
347
  _addEdgeOnly(edge) {
348
- for (const end of edge.vertices) {
348
+ for (const end of edge.vertexMap) {
349
349
  const endVertex = this._getVertex(end);
350
350
  if (endVertex === undefined)
351
351
  return false;
352
352
  if (endVertex) {
353
- const edges = this._edges.get(endVertex);
354
- if (edges) {
355
- edges.push(edge);
353
+ const edgeMap = this._edgeMap.get(endVertex);
354
+ if (edgeMap) {
355
+ edgeMap.push(edge);
356
356
  }
357
357
  else {
358
- this._edges.set(endVertex, [edge]);
358
+ this._edgeMap.set(endVertex, [edge]);
359
359
  }
360
360
  }
361
361
  }
@@ -5,9 +5,9 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { HashMapLinkedNode, HashMapOptions, HashMapStoreItem, PairCallback } from '../../types';
9
- import { IterablePairBase } from "../base";
10
- export declare class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
8
+ import { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem } from '../../types';
9
+ import { IterableEntryBase } from "../base";
10
+ export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
11
11
  protected _store: {
12
12
  [key: string]: HashMapStoreItem<K, V>;
13
13
  };
@@ -85,7 +85,7 @@ export declare class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
85
85
  * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
86
86
  * the provided callback function.
87
87
  */
88
- map<U>(callbackfn: PairCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
88
+ map<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
89
89
  /**
90
90
  * Time Complexity: O(n)
91
91
  * Space Complexity: O(n)
@@ -106,7 +106,7 @@ export declare class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
106
106
  * @returns The `filter` method is returning a new `HashMap` object that contains the key-value pairs
107
107
  * from the original `HashMap` that pass the provided `predicate` function.
108
108
  */
109
- filter(predicate: PairCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
109
+ filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
110
110
  print(): void;
111
111
  /**
112
112
  * The function returns an iterator that yields key-value pairs from both an object store and an
@@ -117,7 +117,7 @@ export declare class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
117
117
  protected _isObjKey(key: any): key is (object | ((...args: any[]) => any));
118
118
  protected _getNoObjKey(key: K): string;
119
119
  }
120
- export declare class LinkedHashMap<K = any, V = any> extends IterablePairBase<K, V> {
120
+ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
121
121
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
122
122
  protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
123
123
  protected _head: HashMapLinkedNode<K, V | undefined>;
@@ -253,7 +253,7 @@ export declare class LinkedHashMap<K = any, V = any> extends IterablePairBase<K,
253
253
  * @returns a new `LinkedHashMap` object that contains the key-value pairs from the original
254
254
  * `LinkedHashMap` object that satisfy the given predicate function.
255
255
  */
256
- filter(predicate: PairCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
256
+ filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
257
257
  /**
258
258
  * Time Complexity: O(n)
259
259
  * Space Complexity: O(n)
@@ -275,7 +275,7 @@ export declare class LinkedHashMap<K = any, V = any> extends IterablePairBase<K,
275
275
  * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
276
276
  * function.
277
277
  */
278
- map<NV>(callback: PairCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
278
+ map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
279
279
  print(): void;
280
280
  /**
281
281
  * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.LinkedHashMap = exports.HashMap = void 0;
11
11
  const utils_1 = require("../../utils");
12
12
  const base_1 = require("../base");
13
- class HashMap extends base_1.IterablePairBase {
13
+ class HashMap extends base_1.IterableEntryBase {
14
14
  /**
15
15
  * The constructor function initializes a new instance of a class with optional elements and options.
16
16
  * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
@@ -230,7 +230,7 @@ class HashMap extends base_1.IterablePairBase {
230
230
  }
231
231
  }
232
232
  exports.HashMap = HashMap;
233
- class LinkedHashMap extends base_1.IterablePairBase {
233
+ class LinkedHashMap extends base_1.IterableEntryBase {
234
234
  constructor(elements, options = {
235
235
  hashFn: (key) => String(key),
236
236
  objHashFn: (key) => key
@@ -3,7 +3,7 @@ import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDelete
3
3
  export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTreeNested<K, V, N>> {
4
4
  createNode(key: K, value?: N['value']): N;
5
5
  createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
6
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, count?: number): N | null | undefined;
6
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
7
7
  addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>): (N | null | undefined)[];
8
8
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
9
9
  }
@@ -1,5 +1,5 @@
1
- import { IterableElementBase, IterablePairBase } from "../../../data-structures";
2
- export type PairCallback<K, V, R> = (value: V, key: K, index: number, container: IterablePairBase<K, V>) => R;
1
+ import { IterableElementBase, IterableEntryBase } from "../../../data-structures";
2
+ export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
3
3
  export type ElementCallback<V, R> = (element: V, index: number, container: IterableElementBase<V>) => R;
4
- export type ReducePairCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterablePairBase<K, V>) => R;
4
+ export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
5
5
  export type ReduceElementCallback<V, R> = (accumulator: R, element: V, index: number, container: IterableElementBase<V>) => R;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bst-typed",
3
- "version": "1.48.4",
3
+ "version": "1.48.5",
4
4
  "description": "BST (Binary Search Tree). Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -144,6 +144,6 @@
144
144
  "typescript": "^4.9.5"
145
145
  },
146
146
  "dependencies": {
147
- "data-structure-typed": "^1.48.4"
147
+ "data-structure-typed": "^1.48.5"
148
148
  }
149
149
  }
@@ -1,6 +1,6 @@
1
- import { ElementCallback, PairCallback, ReduceElementCallback, ReducePairCallback } from "../../types";
1
+ import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from "../../types";
2
2
 
3
- export abstract class IterablePairBase<K = any, V = any> {
3
+ export abstract class IterableEntryBase<K = any, V = any> {
4
4
 
5
5
  /**
6
6
  * Time Complexity: O(n)
@@ -87,7 +87,7 @@ export abstract class IterablePairBase<K = any, V = any> {
87
87
  * @returns The `every` method is returning a boolean value. It returns `true` if every element in
88
88
  * the collection satisfies the provided predicate function, and `false` otherwise.
89
89
  */
90
- every(predicate: PairCallback<K, V, boolean>, thisArg?: any): boolean {
90
+ every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
91
91
  let index = 0;
92
92
  for (const item of this) {
93
93
  if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
@@ -116,7 +116,7 @@ export abstract class IterablePairBase<K = any, V = any> {
116
116
  * @returns a boolean value. It returns true if the predicate function returns true for any pair in
117
117
  * the collection, and false otherwise.
118
118
  */
119
- some(predicate: PairCallback<K, V, boolean>, thisArg?: any): boolean {
119
+ some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
120
120
  let index = 0;
121
121
  for (const item of this) {
122
122
  if (predicate.call(thisArg, item[1], item[0], index++, this)) {
@@ -143,7 +143,7 @@ export abstract class IterablePairBase<K = any, V = any> {
143
143
  * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
144
144
  * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
145
145
  */
146
- forEach(callbackfn: PairCallback<K, V, void>, thisArg?: any): void {
146
+ forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void {
147
147
  let index = 0;
148
148
  for (const item of this) {
149
149
  const [key, value] = item;
@@ -171,7 +171,7 @@ export abstract class IterablePairBase<K = any, V = any> {
171
171
  * @returns The `reduce` method is returning the final value of the accumulator after iterating over
172
172
  * all the elements in the collection.
173
173
  */
174
- reduce<U>(callbackfn: ReducePairCallback<K, V, U>, initialValue: U): U {
174
+ reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U {
175
175
  let accumulator = initialValue;
176
176
  let index = 0;
177
177
  for (const item of this) {