data-structure-typed 1.48.2 → 1.48.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +22 -22
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +184 -184
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +89 -87
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +67 -58
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/cjs/data-structures/binary-tree/bst.js +54 -57
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js +4 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +25 -7
- package/dist/cjs/data-structures/graph/directed-graph.js +58 -12
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +25 -6
- package/dist/cjs/data-structures/graph/undirected-graph.js +70 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +6 -6
- package/dist/cjs/types/common.d.ts +11 -8
- package/dist/cjs/types/common.js +6 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +89 -87
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +67 -58
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/mjs/data-structures/binary-tree/bst.js +55 -57
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/mjs/data-structures/graph/abstract-graph.js +4 -0
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +25 -7
- package/dist/mjs/data-structures/graph/directed-graph.js +58 -12
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +25 -6
- package/dist/mjs/data-structures/graph/undirected-graph.js +70 -7
- package/dist/mjs/interfaces/binary-tree.d.ts +6 -6
- package/dist/mjs/types/common.d.ts +11 -8
- package/dist/mjs/types/common.js +5 -0
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/umd/data-structure-typed.js +276 -158
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +20 -21
- package/src/data-structures/binary-tree/binary-tree.ts +147 -136
- package/src/data-structures/binary-tree/bst.ts +86 -82
- package/src/data-structures/binary-tree/rb-tree.ts +25 -26
- package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
- package/src/data-structures/graph/abstract-graph.ts +5 -0
- package/src/data-structures/graph/directed-graph.ts +61 -12
- package/src/data-structures/graph/undirected-graph.ts +75 -7
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/test/integration/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/bst.test.ts +10 -9
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +5 -5
- package/test/unit/data-structures/graph/directed-graph.test.ts +37 -0
- package/test/unit/data-structures/graph/undirected-graph.test.ts +37 -0
- package/test/unit/unrestricted-interconversion.test.ts +1 -1
|
@@ -96,19 +96,37 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
96
96
|
*/
|
|
97
97
|
deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
98
98
|
/**
|
|
99
|
-
* Time Complexity: O(
|
|
99
|
+
* Time Complexity: O(E) where E is the number of edges
|
|
100
100
|
* Space Complexity: O(1)
|
|
101
101
|
*/
|
|
102
102
|
/**
|
|
103
|
-
* Time Complexity: O(
|
|
103
|
+
* Time Complexity: O(E) where E is the number of edges
|
|
104
104
|
* Space Complexity: O(1)
|
|
105
105
|
*
|
|
106
|
-
* The function removes an edge from a graph and returns the removed edge
|
|
107
|
-
* @param {EO}
|
|
108
|
-
*
|
|
109
|
-
* @
|
|
106
|
+
* The `deleteEdge` function removes an edge from a graph and returns the removed edge.
|
|
107
|
+
* @param {EO | VertexKey} edgeOrSrcVertexKey - The `edge` parameter can be either an `EO` object (edge object) or
|
|
108
|
+
* a `VertexKey` (key of a vertex).
|
|
109
|
+
* @param {VertexKey} [destVertexKey] - The `destVertexKey` parameter is an optional parameter that
|
|
110
|
+
* represents the key of the destination vertex of the edge. It is used to specify the destination
|
|
111
|
+
* vertex when the `edge` parameter is a vertex key. If `destVertexKey` is not provided, the function
|
|
112
|
+
* assumes that the `edge`
|
|
113
|
+
* @returns the removed edge (EO) or undefined if no edge was removed.
|
|
114
|
+
*/
|
|
115
|
+
deleteEdge(edgeOrSrcVertexKey: EO | VertexKey, destVertexKey?: VertexKey): EO | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
118
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
122
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
123
|
+
*
|
|
124
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
125
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
126
|
+
* (`VertexKey`).
|
|
127
|
+
* @returns The method is returning a boolean value.
|
|
110
128
|
*/
|
|
111
|
-
|
|
129
|
+
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
112
130
|
/**
|
|
113
131
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
114
132
|
* Space Complexity: O(1)
|
|
@@ -147,34 +147,80 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
147
147
|
return removed;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
* Time Complexity: O(
|
|
150
|
+
* Time Complexity: O(E) where E is the number of edges
|
|
151
151
|
* Space Complexity: O(1)
|
|
152
152
|
*/
|
|
153
153
|
/**
|
|
154
|
-
* Time Complexity: O(
|
|
154
|
+
* Time Complexity: O(E) where E is the number of edges
|
|
155
155
|
* Space Complexity: O(1)
|
|
156
156
|
*
|
|
157
|
-
* The function removes an edge from a graph and returns the removed edge
|
|
158
|
-
* @param {EO}
|
|
159
|
-
*
|
|
160
|
-
* @
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
* The `deleteEdge` function removes an edge from a graph and returns the removed edge.
|
|
158
|
+
* @param {EO | VertexKey} edgeOrSrcVertexKey - The `edge` parameter can be either an `EO` object (edge object) or
|
|
159
|
+
* a `VertexKey` (key of a vertex).
|
|
160
|
+
* @param {VertexKey} [destVertexKey] - The `destVertexKey` parameter is an optional parameter that
|
|
161
|
+
* represents the key of the destination vertex of the edge. It is used to specify the destination
|
|
162
|
+
* vertex when the `edge` parameter is a vertex key. If `destVertexKey` is not provided, the function
|
|
163
|
+
* assumes that the `edge`
|
|
164
|
+
* @returns the removed edge (EO) or undefined if no edge was removed.
|
|
165
|
+
*/
|
|
166
|
+
deleteEdge(edgeOrSrcVertexKey, destVertexKey) {
|
|
163
167
|
let removed = undefined;
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
let src, dest;
|
|
169
|
+
if (this.isVertexKey(edgeOrSrcVertexKey)) {
|
|
170
|
+
if (this.isVertexKey(destVertexKey)) {
|
|
171
|
+
src = this._getVertex(edgeOrSrcVertexKey);
|
|
172
|
+
dest = this._getVertex(destVertexKey);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
src = this._getVertex(edgeOrSrcVertexKey.src);
|
|
180
|
+
dest = this._getVertex(edgeOrSrcVertexKey.dest);
|
|
181
|
+
}
|
|
166
182
|
if (src && dest) {
|
|
167
183
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
168
184
|
if (srcOutEdges && srcOutEdges.length > 0) {
|
|
169
|
-
arrayRemove(srcOutEdges, (edge) => edge.src === src.key);
|
|
185
|
+
arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === dest?.key);
|
|
170
186
|
}
|
|
171
187
|
const destInEdges = this._inEdgeMap.get(dest);
|
|
172
188
|
if (destInEdges && destInEdges.length > 0) {
|
|
173
|
-
removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.key)[0];
|
|
189
|
+
removed = arrayRemove(destInEdges, (edge) => edge.src === src.key && edge.dest === dest.key)[0];
|
|
174
190
|
}
|
|
175
191
|
}
|
|
176
192
|
return removed;
|
|
177
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
196
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
200
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
201
|
+
*
|
|
202
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
203
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
204
|
+
* (`VertexKey`).
|
|
205
|
+
* @returns The method is returning a boolean value.
|
|
206
|
+
*/
|
|
207
|
+
deleteVertex(vertexOrKey) {
|
|
208
|
+
let vertexKey;
|
|
209
|
+
let vertex;
|
|
210
|
+
if (this.isVertexKey(vertexOrKey)) {
|
|
211
|
+
vertex = this.getVertex(vertexOrKey);
|
|
212
|
+
vertexKey = vertexOrKey;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
vertex = vertexOrKey;
|
|
216
|
+
vertexKey = this._getVertexKey(vertexOrKey);
|
|
217
|
+
}
|
|
218
|
+
if (vertex) {
|
|
219
|
+
this._outEdgeMap.delete(vertex);
|
|
220
|
+
this._inEdgeMap.delete(vertex);
|
|
221
|
+
}
|
|
222
|
+
return this._vertices.delete(vertexKey);
|
|
223
|
+
}
|
|
178
224
|
/**
|
|
179
225
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
180
226
|
* Space Complexity: O(1)
|
|
@@ -85,18 +85,37 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
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 edges 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 edges 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 vertices 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)
|
|
@@ -131,19 +131,82 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
131
131
|
return removed;
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
-
* Time Complexity: O(
|
|
134
|
+
* Time Complexity: O(E), where E is the number of edges incident to the given vertex.
|
|
135
135
|
* Space Complexity: O(1)
|
|
136
136
|
*/
|
|
137
137
|
/**
|
|
138
|
-
* Time Complexity: O(
|
|
138
|
+
* Time Complexity: O(E), where E is the number of edges incident to the given vertex.
|
|
139
139
|
* Space Complexity: O(1)
|
|
140
140
|
*
|
|
141
|
-
* The deleteEdge
|
|
142
|
-
* @param {EO}
|
|
143
|
-
*
|
|
141
|
+
* The function `deleteEdge` deletes an edge between two vertices in a graph.
|
|
142
|
+
* @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
|
|
143
|
+
* either an edge object or a vertex key.
|
|
144
|
+
* @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
|
|
145
|
+
* parameter that represents the key of the vertex on the other side of the edge. It is used when the
|
|
146
|
+
* `edgeOrOneSideVertexKey` parameter is a vertex key, and it specifies the key of the vertex on the
|
|
147
|
+
* other side of the
|
|
148
|
+
* @returns The `deleteEdge` function returns either the deleted edge object (EO) or `undefined`.
|
|
149
|
+
*/
|
|
150
|
+
deleteEdge(edgeOrOneSideVertexKey, otherSideVertexKey) {
|
|
151
|
+
let oneSide, otherSide;
|
|
152
|
+
if (this.isVertexKey(edgeOrOneSideVertexKey)) {
|
|
153
|
+
if (this.isVertexKey(otherSideVertexKey)) {
|
|
154
|
+
oneSide = this._getVertex(edgeOrOneSideVertexKey);
|
|
155
|
+
otherSide = this._getVertex(otherSideVertexKey);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
oneSide = this._getVertex(edgeOrOneSideVertexKey.vertices[0]);
|
|
163
|
+
otherSide = this._getVertex(edgeOrOneSideVertexKey.vertices[1]);
|
|
164
|
+
}
|
|
165
|
+
if (oneSide && otherSide) {
|
|
166
|
+
return this.deleteEdgeBetween(oneSide, otherSide);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
174
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
144
175
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
178
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
179
|
+
*
|
|
180
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
181
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
182
|
+
* (`VertexKey`).
|
|
183
|
+
* @returns The method is returning a boolean value.
|
|
184
|
+
*/
|
|
185
|
+
deleteVertex(vertexOrKey) {
|
|
186
|
+
let vertexKey;
|
|
187
|
+
let vertex;
|
|
188
|
+
if (this.isVertexKey(vertexOrKey)) {
|
|
189
|
+
vertex = this.getVertex(vertexOrKey);
|
|
190
|
+
vertexKey = vertexOrKey;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
vertex = vertexOrKey;
|
|
194
|
+
vertexKey = this._getVertexKey(vertexOrKey);
|
|
195
|
+
}
|
|
196
|
+
const neighbors = this.getNeighbors(vertexOrKey);
|
|
197
|
+
if (vertex) {
|
|
198
|
+
neighbors.forEach(neighbor => {
|
|
199
|
+
const neighborEdges = this._edges.get(neighbor);
|
|
200
|
+
if (neighborEdges) {
|
|
201
|
+
const restEdges = neighborEdges.filter(edge => {
|
|
202
|
+
return !edge.vertices.includes(vertexKey);
|
|
203
|
+
});
|
|
204
|
+
this._edges.set(neighbor, restEdges);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
this._edges.delete(vertex);
|
|
208
|
+
}
|
|
209
|
+
return this._vertices.delete(vertexKey);
|
|
147
210
|
}
|
|
148
211
|
/**
|
|
149
212
|
* Time Complexity: O(1)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback,
|
|
3
|
-
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>, TREE extends BinaryTree<V, N, TREE> = BinaryTreeNested<V, N>> {
|
|
4
|
-
createNode(key:
|
|
5
|
-
createTree(options?: Partial<BinaryTreeOptions
|
|
6
|
-
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>, count?: number): N | null | undefined;
|
|
7
|
-
addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (N | null | undefined)[];
|
|
2
|
+
import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback, BTNodeExemplar } from '../types';
|
|
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
|
+
createNode(key: K, value?: N['value']): N;
|
|
5
|
+
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
6
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, count?: number): N | null | undefined;
|
|
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,8 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
export type Comparator<K> = (a: K, b: K) => number;
|
|
2
|
+
export declare enum BSTVariant {
|
|
3
|
+
MIN = "MIN",
|
|
4
|
+
MAX = "MAX"
|
|
5
|
+
}
|
|
3
6
|
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
4
7
|
export type BTNCallback<N, D = any> = (node: N) => D;
|
|
5
8
|
export declare enum CP {
|
|
@@ -19,9 +22,9 @@ export type BinaryTreePrintOptions = {
|
|
|
19
22
|
isShowNull?: boolean;
|
|
20
23
|
isShowRedBlackNIL?: boolean;
|
|
21
24
|
};
|
|
22
|
-
export type BTNodeEntry<
|
|
23
|
-
export type BTNodeKeyOrNode<N> =
|
|
24
|
-
export type BTNodeExemplar<
|
|
25
|
-
export type BTNodePureExemplar<
|
|
26
|
-
export type BTNodePureKeyOrNode<N> =
|
|
27
|
-
export type BSTNodeKeyOrNode<N> =
|
|
25
|
+
export type BTNodeEntry<K, V> = [K | null | undefined, V | undefined];
|
|
26
|
+
export type BTNodeKeyOrNode<K, N> = K | null | undefined | N;
|
|
27
|
+
export type BTNodeExemplar<K, V, N> = BTNodeEntry<K, V> | BTNodeKeyOrNode<K, N>;
|
|
28
|
+
export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
29
|
+
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
30
|
+
export type BSTNodeKeyOrNode<K, N> = K | undefined | N;
|
package/dist/mjs/types/common.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
export type AVLTreeNodeNested<
|
|
4
|
-
export type AVLTreeNested<
|
|
5
|
-
export type AVLTreeOptions = BSTOptions & {};
|
|
3
|
+
export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type AVLTreeNested<K, V, N extends AVLTreeNode<K, V, N>> = AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type AVLTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -18,14 +18,14 @@ export declare enum FamilyPosition {
|
|
|
18
18
|
ISOLATED = "ISOLATED",
|
|
19
19
|
MAL_NODE = "MAL_NODE"
|
|
20
20
|
}
|
|
21
|
-
export type BTNKey = number;
|
|
22
21
|
export type BiTreeDeleteResult<N> = {
|
|
23
22
|
deleted: N | null | undefined;
|
|
24
23
|
needBalanced: N | null | undefined;
|
|
25
24
|
};
|
|
26
|
-
export type BinaryTreeNodeNested<
|
|
27
|
-
export type BinaryTreeNested<
|
|
28
|
-
export type BinaryTreeOptions = {
|
|
25
|
+
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
26
|
+
export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
27
|
+
export type BinaryTreeOptions<K> = {
|
|
29
28
|
iterationType: IterationType;
|
|
29
|
+
extractor: (key: K) => number;
|
|
30
30
|
};
|
|
31
31
|
export type NodeDisplayLayout = [string[], number, number, number];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BST, BSTNode } from '../../../data-structures';
|
|
2
|
-
import type { BinaryTreeOptions
|
|
3
|
-
import {
|
|
4
|
-
export type BSTNodeNested<
|
|
5
|
-
export type BSTNested<
|
|
6
|
-
export type BSTOptions = BinaryTreeOptions & {
|
|
7
|
-
|
|
2
|
+
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
+
import { BSTVariant } from "../../common";
|
|
4
|
+
export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type BSTNested<K, V, N extends BSTNode<K, V, N>> = BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BSTOptions<K> = BinaryTreeOptions<K> & {
|
|
7
|
+
variant: BSTVariant;
|
|
8
8
|
};
|
|
@@ -4,6 +4,6 @@ export declare enum RBTNColor {
|
|
|
4
4
|
RED = 1,
|
|
5
5
|
BLACK = 0
|
|
6
6
|
}
|
|
7
|
-
export type RedBlackTreeNodeNested<
|
|
8
|
-
export type RedBlackTreeNested<
|
|
9
|
-
export type RBTreeOptions = BSTOptions & {};
|
|
7
|
+
export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
8
|
+
export type RedBlackTreeNested<K, V, N extends RedBlackTreeNode<K, V, N>> = RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
9
|
+
export type RBTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
|
|
2
2
|
import { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
export type TreeMultimapNodeNested<
|
|
4
|
-
export type TreeMultimapNested<
|
|
5
|
-
export type TreeMultimapOptions = Omit<AVLTreeOptions
|
|
3
|
+
export type TreeMultimapNodeNested<K, V> = TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type TreeMultimapNested<K, V, N extends TreeMultimapNode<K, V, N>> = TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type TreeMultimapOptions<K> = Omit<AVLTreeOptions<K>, 'isMergeDuplicatedNodeByKey'> & {};
|