data-structure-typed 1.48.3 → 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.
- package/CHANGELOG.md +1 -1
- package/README.md +6 -6
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -6
- package/dist/cjs/data-structures/base/iterable-base.js +3 -3
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +16 -13
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/cjs/data-structures/binary-tree/bst.js +17 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +53 -52
- package/dist/cjs/data-structures/graph/abstract-graph.js +82 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +70 -52
- package/dist/cjs/data-structures/graph/directed-graph.js +111 -65
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/cjs/data-structures/graph/map-graph.js +8 -8
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +51 -32
- package/dist/cjs/data-structures/graph/undirected-graph.js +117 -54
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/cjs/data-structures/hash/hash-map.js +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +3 -3
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -6
- package/dist/mjs/data-structures/base/iterable-base.js +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +17 -14
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +53 -52
- package/dist/mjs/data-structures/graph/abstract-graph.js +83 -79
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +70 -52
- package/dist/mjs/data-structures/graph/directed-graph.js +111 -65
- package/dist/mjs/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/mjs/data-structures/graph/map-graph.js +8 -8
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +51 -32
- package/dist/mjs/data-structures/graph/undirected-graph.js +119 -56
- package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/mjs/data-structures/hash/hash-map.js +3 -3
- package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/base/base.d.ts +3 -3
- package/dist/umd/data-structure-typed.js +413 -285
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree.ts +8 -5
- package/src/data-structures/binary-tree/binary-tree.ts +23 -19
- package/src/data-structures/binary-tree/bst.ts +19 -14
- package/src/data-structures/binary-tree/rb-tree.ts +20 -14
- package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
- package/src/data-structures/graph/abstract-graph.ts +87 -82
- package/src/data-structures/graph/directed-graph.ts +114 -65
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +124 -56
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/base/base.ts +3 -3
- package/test/integration/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +3 -3
- package/test/unit/data-structures/graph/directed-graph.test.ts +52 -15
- package/test/unit/data-structures/graph/map-graph.test.ts +3 -3
- package/test/unit/data-structures/graph/undirected-graph.test.ts +42 -5
|
@@ -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
|
-
|
|
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
|
|
30
|
+
* The constructor initializes a new Map object to store edgeMap.
|
|
31
31
|
*/
|
|
32
32
|
constructor();
|
|
33
|
-
protected
|
|
34
|
-
get
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,33 +70,52 @@ 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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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 deleteEdge
|
|
96
|
-
* @param {EO}
|
|
97
|
-
*
|
|
95
|
+
* The function `deleteEdge` deletes an edge between two vertexMap in a graph.
|
|
96
|
+
* @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
|
|
97
|
+
* either an edge object or a vertex key.
|
|
98
|
+
* @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
|
|
99
|
+
* parameter that represents the key of the vertex on the other side of the edge. It is used when the
|
|
100
|
+
* `edgeOrOneSideVertexKey` parameter is a vertex key, and it specifies the key of the vertex on the
|
|
101
|
+
* other side of the
|
|
102
|
+
* @returns The `deleteEdge` function returns either the deleted edge object (EO) or `undefined`.
|
|
103
|
+
*/
|
|
104
|
+
deleteEdge(edgeOrOneSideVertexKey: EO | VertexKey, otherSideVertexKey?: VertexKey): EO | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
107
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
111
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
112
|
+
*
|
|
113
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
114
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
115
|
+
* (`VertexKey`).
|
|
116
|
+
* @returns The method is returning a boolean value.
|
|
98
117
|
*/
|
|
99
|
-
|
|
118
|
+
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
100
119
|
/**
|
|
101
120
|
* Time Complexity: O(1)
|
|
102
121
|
* Space Complexity: O(1)
|
|
@@ -105,11 +124,11 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
105
124
|
* Time Complexity: O(1)
|
|
106
125
|
* Space Complexity: O(1)
|
|
107
126
|
*
|
|
108
|
-
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of
|
|
127
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
|
|
109
128
|
* vertex.
|
|
110
129
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
111
130
|
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
112
|
-
*
|
|
131
|
+
* edgeMap connected to that vertex.
|
|
113
132
|
*/
|
|
114
133
|
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
115
134
|
/**
|
|
@@ -120,36 +139,36 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
120
139
|
* Time Complexity: O(1)
|
|
121
140
|
* Space Complexity: O(1)
|
|
122
141
|
*
|
|
123
|
-
* The function returns the
|
|
142
|
+
* The function returns the edgeMap of a given vertex or vertex ID.
|
|
124
143
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
125
144
|
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
126
|
-
* @returns an array of
|
|
145
|
+
* @returns an array of edgeMap.
|
|
127
146
|
*/
|
|
128
147
|
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
129
148
|
/**
|
|
130
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
149
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
131
150
|
* Space Complexity: O(|E|)
|
|
132
151
|
*/
|
|
133
152
|
/**
|
|
134
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
153
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
135
154
|
* Space Complexity: O(|E|)
|
|
136
155
|
*
|
|
137
|
-
* The function "edgeSet" returns an array of unique
|
|
156
|
+
* The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
|
|
138
157
|
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
139
158
|
*/
|
|
140
159
|
edgeSet(): EO[];
|
|
141
160
|
/**
|
|
142
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
161
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
143
162
|
* Space Complexity: O(|E|)
|
|
144
163
|
*/
|
|
145
164
|
/**
|
|
146
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
165
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
147
166
|
* Space Complexity: O(|E|)
|
|
148
167
|
*
|
|
149
|
-
* The function "getNeighbors" returns an array of neighboring
|
|
168
|
+
* The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
|
|
150
169
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
151
170
|
* (`VertexKey`).
|
|
152
|
-
* @returns an array of
|
|
171
|
+
* @returns an array of vertexMap (VO[]).
|
|
153
172
|
*/
|
|
154
173
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
155
174
|
/**
|
|
@@ -160,10 +179,10 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
160
179
|
* Time Complexity: O(1)
|
|
161
180
|
* Space Complexity: O(1)
|
|
162
181
|
*
|
|
163
|
-
* The function "getEndsOfEdge" returns the
|
|
182
|
+
* The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
|
|
164
183
|
* it returns undefined.
|
|
165
184
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
166
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
185
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
167
186
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
168
187
|
*/
|
|
169
188
|
getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
@@ -175,7 +194,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
175
194
|
* Time Complexity: O(1)
|
|
176
195
|
* Space Complexity: O(1)
|
|
177
196
|
*
|
|
178
|
-
* The function adds an edge to the graph by updating the adjacency list with the
|
|
197
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
|
|
179
198
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
180
199
|
* @returns a boolean value.
|
|
181
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.
|
|
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
|
|
45
|
+
* The constructor initializes a new Map object to store edgeMap.
|
|
46
46
|
*/
|
|
47
47
|
constructor() {
|
|
48
48
|
super();
|
|
49
|
-
this.
|
|
49
|
+
this._edgeMap = new Map();
|
|
50
50
|
}
|
|
51
|
-
get
|
|
52
|
-
return this.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
104
|
+
return edgeMap ? edgeMap[0] || undefined : undefined;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
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
|
|
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
|
|
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
|
|
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,31 +123,94 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
123
123
|
if (!vertex1 || !vertex2) {
|
|
124
124
|
return undefined;
|
|
125
125
|
}
|
|
126
|
-
const v1Edges = this.
|
|
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.
|
|
129
|
+
removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertexMap.includes(vertex2.key))[0] || undefined;
|
|
130
130
|
}
|
|
131
|
-
const v2Edges = this.
|
|
131
|
+
const v2Edges = this._edgeMap.get(vertex2);
|
|
132
132
|
if (v2Edges) {
|
|
133
|
-
(0, utils_1.arrayRemove)(v2Edges, (e) => e.
|
|
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(
|
|
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(
|
|
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 deleteEdge
|
|
146
|
-
* @param {EO}
|
|
147
|
-
*
|
|
145
|
+
* The function `deleteEdge` deletes an edge between two vertexMap in a graph.
|
|
146
|
+
* @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
|
|
147
|
+
* either an edge object or a vertex key.
|
|
148
|
+
* @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
|
|
149
|
+
* parameter that represents the key of the vertex on the other side of the edge. It is used when the
|
|
150
|
+
* `edgeOrOneSideVertexKey` parameter is a vertex key, and it specifies the key of the vertex on the
|
|
151
|
+
* other side of the
|
|
152
|
+
* @returns The `deleteEdge` function returns either the deleted edge object (EO) or `undefined`.
|
|
153
|
+
*/
|
|
154
|
+
deleteEdge(edgeOrOneSideVertexKey, otherSideVertexKey) {
|
|
155
|
+
let oneSide, otherSide;
|
|
156
|
+
if (this.isVertexKey(edgeOrOneSideVertexKey)) {
|
|
157
|
+
if (this.isVertexKey(otherSideVertexKey)) {
|
|
158
|
+
oneSide = this._getVertex(edgeOrOneSideVertexKey);
|
|
159
|
+
otherSide = this._getVertex(otherSideVertexKey);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
oneSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[0]);
|
|
167
|
+
otherSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[1]);
|
|
168
|
+
}
|
|
169
|
+
if (oneSide && otherSide) {
|
|
170
|
+
return this.deleteEdgeBetween(oneSide, otherSide);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
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.
|
|
148
179
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
182
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
183
|
+
*
|
|
184
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
185
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
186
|
+
* (`VertexKey`).
|
|
187
|
+
* @returns The method is returning a boolean value.
|
|
188
|
+
*/
|
|
189
|
+
deleteVertex(vertexOrKey) {
|
|
190
|
+
let vertexKey;
|
|
191
|
+
let vertex;
|
|
192
|
+
if (this.isVertexKey(vertexOrKey)) {
|
|
193
|
+
vertex = this.getVertex(vertexOrKey);
|
|
194
|
+
vertexKey = vertexOrKey;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
vertex = vertexOrKey;
|
|
198
|
+
vertexKey = this._getVertexKey(vertexOrKey);
|
|
199
|
+
}
|
|
200
|
+
const neighbors = this.getNeighbors(vertexOrKey);
|
|
201
|
+
if (vertex) {
|
|
202
|
+
neighbors.forEach(neighbor => {
|
|
203
|
+
const neighborEdges = this._edgeMap.get(neighbor);
|
|
204
|
+
if (neighborEdges) {
|
|
205
|
+
const restEdges = neighborEdges.filter(edge => {
|
|
206
|
+
return !edge.vertexMap.includes(vertexKey);
|
|
207
|
+
});
|
|
208
|
+
this._edgeMap.set(neighbor, restEdges);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
this._edgeMap.delete(vertex);
|
|
212
|
+
}
|
|
213
|
+
return this._vertexMap.delete(vertexKey);
|
|
151
214
|
}
|
|
152
215
|
/**
|
|
153
216
|
* Time Complexity: O(1)
|
|
@@ -157,17 +220,17 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
157
220
|
* Time Complexity: O(1)
|
|
158
221
|
* Space Complexity: O(1)
|
|
159
222
|
*
|
|
160
|
-
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of
|
|
223
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
|
|
161
224
|
* vertex.
|
|
162
225
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
163
226
|
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
164
|
-
*
|
|
227
|
+
* edgeMap connected to that vertex.
|
|
165
228
|
*/
|
|
166
229
|
degreeOf(vertexOrKey) {
|
|
167
230
|
var _a;
|
|
168
231
|
const vertex = this._getVertex(vertexOrKey);
|
|
169
232
|
if (vertex) {
|
|
170
|
-
return ((_a = this.
|
|
233
|
+
return ((_a = this._edgeMap.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
171
234
|
}
|
|
172
235
|
else {
|
|
173
236
|
return 0;
|
|
@@ -181,52 +244,52 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
181
244
|
* Time Complexity: O(1)
|
|
182
245
|
* Space Complexity: O(1)
|
|
183
246
|
*
|
|
184
|
-
* The function returns the
|
|
247
|
+
* The function returns the edgeMap of a given vertex or vertex ID.
|
|
185
248
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
186
249
|
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
187
|
-
* @returns an array of
|
|
250
|
+
* @returns an array of edgeMap.
|
|
188
251
|
*/
|
|
189
252
|
edgesOf(vertexOrKey) {
|
|
190
253
|
const vertex = this._getVertex(vertexOrKey);
|
|
191
254
|
if (vertex) {
|
|
192
|
-
return this.
|
|
255
|
+
return this._edgeMap.get(vertex) || [];
|
|
193
256
|
}
|
|
194
257
|
else {
|
|
195
258
|
return [];
|
|
196
259
|
}
|
|
197
260
|
}
|
|
198
261
|
/**
|
|
199
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
262
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
200
263
|
* Space Complexity: O(|E|)
|
|
201
264
|
*/
|
|
202
265
|
/**
|
|
203
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
266
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
204
267
|
* Space Complexity: O(|E|)
|
|
205
268
|
*
|
|
206
|
-
* The function "edgeSet" returns an array of unique
|
|
269
|
+
* The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
|
|
207
270
|
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
208
271
|
*/
|
|
209
272
|
edgeSet() {
|
|
210
273
|
const edgeSet = new Set();
|
|
211
|
-
this.
|
|
212
|
-
|
|
274
|
+
this._edgeMap.forEach(edgeMap => {
|
|
275
|
+
edgeMap.forEach(edge => {
|
|
213
276
|
edgeSet.add(edge);
|
|
214
277
|
});
|
|
215
278
|
});
|
|
216
279
|
return [...edgeSet];
|
|
217
280
|
}
|
|
218
281
|
/**
|
|
219
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
282
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
220
283
|
* Space Complexity: O(|E|)
|
|
221
284
|
*/
|
|
222
285
|
/**
|
|
223
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
286
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
224
287
|
* Space Complexity: O(|E|)
|
|
225
288
|
*
|
|
226
|
-
* The function "getNeighbors" returns an array of neighboring
|
|
289
|
+
* The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
|
|
227
290
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
228
291
|
* (`VertexKey`).
|
|
229
|
-
* @returns an array of
|
|
292
|
+
* @returns an array of vertexMap (VO[]).
|
|
230
293
|
*/
|
|
231
294
|
getNeighbors(vertexOrKey) {
|
|
232
295
|
const neighbors = [];
|
|
@@ -234,7 +297,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
234
297
|
if (vertex) {
|
|
235
298
|
const neighborEdges = this.edgesOf(vertex);
|
|
236
299
|
for (const edge of neighborEdges) {
|
|
237
|
-
const neighbor = this._getVertex(edge.
|
|
300
|
+
const neighbor = this._getVertex(edge.vertexMap.filter(e => e !== vertex.key)[0]);
|
|
238
301
|
if (neighbor) {
|
|
239
302
|
neighbors.push(neighbor);
|
|
240
303
|
}
|
|
@@ -250,18 +313,18 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
250
313
|
* Time Complexity: O(1)
|
|
251
314
|
* Space Complexity: O(1)
|
|
252
315
|
*
|
|
253
|
-
* The function "getEndsOfEdge" returns the
|
|
316
|
+
* The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
|
|
254
317
|
* it returns undefined.
|
|
255
318
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
256
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
319
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
257
320
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
258
321
|
*/
|
|
259
322
|
getEndsOfEdge(edge) {
|
|
260
|
-
if (!this.hasEdge(edge.
|
|
323
|
+
if (!this.hasEdge(edge.vertexMap[0], edge.vertexMap[1])) {
|
|
261
324
|
return undefined;
|
|
262
325
|
}
|
|
263
|
-
const v1 = this._getVertex(edge.
|
|
264
|
-
const v2 = this._getVertex(edge.
|
|
326
|
+
const v1 = this._getVertex(edge.vertexMap[0]);
|
|
327
|
+
const v2 = this._getVertex(edge.vertexMap[1]);
|
|
265
328
|
if (v1 && v2) {
|
|
266
329
|
return [v1, v2];
|
|
267
330
|
}
|
|
@@ -277,22 +340,22 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
277
340
|
* Time Complexity: O(1)
|
|
278
341
|
* Space Complexity: O(1)
|
|
279
342
|
*
|
|
280
|
-
* The function adds an edge to the graph by updating the adjacency list with the
|
|
343
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
|
|
281
344
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
282
345
|
* @returns a boolean value.
|
|
283
346
|
*/
|
|
284
347
|
_addEdgeOnly(edge) {
|
|
285
|
-
for (const end of edge.
|
|
348
|
+
for (const end of edge.vertexMap) {
|
|
286
349
|
const endVertex = this._getVertex(end);
|
|
287
350
|
if (endVertex === undefined)
|
|
288
351
|
return false;
|
|
289
352
|
if (endVertex) {
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
|
|
353
|
+
const edgeMap = this._edgeMap.get(endVertex);
|
|
354
|
+
if (edgeMap) {
|
|
355
|
+
edgeMap.push(edge);
|
|
293
356
|
}
|
|
294
357
|
else {
|
|
295
|
-
this.
|
|
358
|
+
this._edgeMap.set(endVertex, [edge]);
|
|
296
359
|
}
|
|
297
360
|
}
|
|
298
361
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undirected-graph.js","sourceRoot":"","sources":["../../../../src/data-structures/graph/undirected-graph.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,uCAA0C;AAC1C,qDAA+E;AAI/E,MAAa,gBAA0B,SAAQ,+BAAiB;IAC9D;;;;;;OAMG;IACH,YAAY,GAAc,EAAE,KAAS;QACnC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,CAAC;CACF;AAXD,4CAWC;AAED,MAAa,cAA2B,SAAQ,6BAAe;IAG7D;;;;;;;;;OASG;IACH,YAAY,EAAa,EAAE,EAAa,EAAE,MAAe,EAAE,KAAS;QAClE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"undirected-graph.js","sourceRoot":"","sources":["../../../../src/data-structures/graph/undirected-graph.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,uCAA0C;AAC1C,qDAA+E;AAI/E,MAAa,gBAA0B,SAAQ,+BAA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@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { HashMapLinkedNode, HashMapOptions, HashMapStoreItem
|
|
9
|
-
import {
|
|
10
|
-
export declare class HashMap<K = any, V = any> extends
|
|
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:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
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.
|
|
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.
|
|
233
|
+
class LinkedHashMap extends base_1.IterableEntryBase {
|
|
234
234
|
constructor(elements, options = {
|
|
235
235
|
hashFn: (key) => String(key),
|
|
236
236
|
objHashFn: (key) => key
|