data-structure-typed 1.18.8 → 1.19.1
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/README.md +169 -168
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +182 -148
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +288 -316
- package/dist/data-structures/binary-tree/avl-tree.d.ts +22 -14
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +11 -26
- package/dist/data-structures/binary-tree/bst.d.ts +62 -74
- package/dist/data-structures/binary-tree/bst.js +72 -96
- package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -14
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +186 -17
- package/dist/data-structures/binary-tree/tree-multiset.js +712 -28
- package/dist/data-structures/graph/abstract-graph.d.ts +107 -49
- package/dist/data-structures/graph/abstract-graph.js +104 -55
- package/dist/data-structures/graph/directed-graph.d.ts +95 -94
- package/dist/data-structures/graph/directed-graph.js +95 -95
- package/dist/data-structures/graph/undirected-graph.d.ts +62 -61
- package/dist/data-structures/graph/undirected-graph.js +62 -61
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +10 -15
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +3 -4
- package/dist/data-structures/interfaces/rb-tree.d.ts +1 -2
- package/dist/data-structures/interfaces/tree-multiset.d.ts +3 -3
- package/dist/data-structures/types/abstract-binary-tree.d.ts +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/utils.d.ts +0 -18
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +3 -8
- package/dist/utils/utils.js +1 -83
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +6 -2
- package/tsconfig.json +0 -17
|
@@ -65,8 +65,8 @@ var UndirectedVertex = /** @class */ (function (_super) {
|
|
|
65
65
|
__extends(UndirectedVertex, _super);
|
|
66
66
|
/**
|
|
67
67
|
* The constructor function initializes a vertex with an optional value.
|
|
68
|
-
* @param {VertexId} id - The `id` parameter is the identifier
|
|
69
|
-
*
|
|
68
|
+
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
69
|
+
* used to uniquely identify the vertex within a graph or network.
|
|
70
70
|
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
|
|
71
71
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
72
72
|
*/
|
|
@@ -79,14 +79,14 @@ exports.UndirectedVertex = UndirectedVertex;
|
|
|
79
79
|
var UndirectedEdge = /** @class */ (function (_super) {
|
|
80
80
|
__extends(UndirectedEdge, _super);
|
|
81
81
|
/**
|
|
82
|
-
* The constructor function
|
|
82
|
+
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
83
83
|
* value.
|
|
84
|
-
* @param {VertexId} v1 - The
|
|
84
|
+
* @param {VertexId} v1 - The first vertex ID of the edge.
|
|
85
85
|
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
|
|
86
86
|
* graph edge.
|
|
87
87
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
88
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It
|
|
89
|
-
* the edge.
|
|
88
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
|
|
89
|
+
* with the edge.
|
|
90
90
|
*/
|
|
91
91
|
function UndirectedEdge(v1, v2, weight, val) {
|
|
92
92
|
var _this = _super.call(this, weight, val) || this;
|
|
@@ -108,6 +108,9 @@ var UndirectedEdge = /** @class */ (function (_super) {
|
|
|
108
108
|
exports.UndirectedEdge = UndirectedEdge;
|
|
109
109
|
var UndirectedGraph = /** @class */ (function (_super) {
|
|
110
110
|
__extends(UndirectedGraph, _super);
|
|
111
|
+
/**
|
|
112
|
+
* The constructor initializes a new Map object to store edges.
|
|
113
|
+
*/
|
|
111
114
|
function UndirectedGraph() {
|
|
112
115
|
var _this = _super.call(this) || this;
|
|
113
116
|
_this._edges = new Map();
|
|
@@ -121,37 +124,37 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
121
124
|
configurable: true
|
|
122
125
|
});
|
|
123
126
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @param val
|
|
127
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
128
|
+
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
129
|
+
* vertex from another in the graph.
|
|
130
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
131
|
+
* it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
|
|
132
|
+
* the vertex.
|
|
133
|
+
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
|
|
128
134
|
*/
|
|
129
135
|
UndirectedGraph.prototype.createVertex = function (id, val) {
|
|
130
136
|
return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
131
137
|
};
|
|
132
138
|
/**
|
|
133
|
-
* The function
|
|
134
|
-
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
135
|
-
*
|
|
136
|
-
* @param {
|
|
137
|
-
*
|
|
138
|
-
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
139
|
-
* weight is provided, the default value is 1.
|
|
139
|
+
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
140
|
+
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
141
|
+
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
142
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
143
|
+
* no weight is provided, it defaults to 1.
|
|
140
144
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
141
145
|
* is used to store additional information or data associated with the edge.
|
|
142
|
-
* @returns
|
|
146
|
+
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
|
|
143
147
|
*/
|
|
144
148
|
UndirectedGraph.prototype.createEdge = function (v1, v2, weight, val) {
|
|
145
149
|
return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
146
150
|
};
|
|
147
151
|
/**
|
|
148
|
-
* The function `getEdge` returns the first
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* @returns an instance of `E` or `null`.
|
|
152
|
+
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
153
|
+
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
154
|
+
* object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
|
|
155
|
+
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
156
|
+
* object), `null`, or `VertexId` (vertex ID).
|
|
157
|
+
* @returns an edge (E) or null.
|
|
155
158
|
*/
|
|
156
159
|
UndirectedGraph.prototype.getEdge = function (v1, v2) {
|
|
157
160
|
var _a;
|
|
@@ -166,15 +169,11 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
166
169
|
return edges ? edges[0] || null : null;
|
|
167
170
|
};
|
|
168
171
|
/**
|
|
169
|
-
* The function removes an edge between two vertices in
|
|
170
|
-
* @param {V | VertexId} v1 - The parameter `v1` represents either
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* removed.
|
|
175
|
-
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
|
|
176
|
-
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
|
|
177
|
-
* between them, the function returns `null`.
|
|
172
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
173
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
174
|
+
* @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
|
|
175
|
+
* (VertexId). It represents the second vertex of the edge that needs to be removed.
|
|
176
|
+
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
178
177
|
*/
|
|
179
178
|
UndirectedGraph.prototype.removeEdgeBetween = function (v1, v2) {
|
|
180
179
|
var vertex1 = this._getVertex(v1);
|
|
@@ -194,19 +193,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
194
193
|
return removed;
|
|
195
194
|
};
|
|
196
195
|
/**
|
|
197
|
-
* The removeEdge function removes an edge between two vertices in
|
|
198
|
-
* @param edge -
|
|
199
|
-
*
|
|
200
|
-
* @returns The method is returning an UndirectedEdge object or null.
|
|
196
|
+
* The removeEdge function removes an edge between two vertices in a graph.
|
|
197
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
198
|
+
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
|
|
201
199
|
*/
|
|
202
200
|
UndirectedGraph.prototype.removeEdge = function (edge) {
|
|
203
201
|
return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
204
202
|
};
|
|
205
203
|
/**
|
|
206
|
-
* The function
|
|
207
|
-
*
|
|
208
|
-
* `V`.
|
|
209
|
-
* @returns the degree of
|
|
204
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
205
|
+
* vertex.
|
|
206
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
207
|
+
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
208
|
+
* edges connected to that vertex.
|
|
210
209
|
*/
|
|
211
210
|
UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
|
|
212
211
|
var _a;
|
|
@@ -219,10 +218,10 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
219
218
|
}
|
|
220
219
|
};
|
|
221
220
|
/**
|
|
222
|
-
* The function
|
|
223
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
224
|
-
* `V
|
|
225
|
-
* @returns an array of
|
|
221
|
+
* The function returns the edges of a given vertex or vertex ID.
|
|
222
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
|
|
223
|
+
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
|
|
224
|
+
* @returns an array of edges.
|
|
226
225
|
*/
|
|
227
226
|
UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
|
|
228
227
|
var vertex = this._getVertex(vertexOrId);
|
|
@@ -234,8 +233,8 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
234
233
|
}
|
|
235
234
|
};
|
|
236
235
|
/**
|
|
237
|
-
* The function "edgeSet" returns an array of unique
|
|
238
|
-
* @returns The method `edgeSet()` returns an array of `E
|
|
236
|
+
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
237
|
+
* @returns The method `edgeSet()` returns an array of type `E[]`.
|
|
239
238
|
*/
|
|
240
239
|
UndirectedGraph.prototype.edgeSet = function () {
|
|
241
240
|
var edgeSet = new Set();
|
|
@@ -247,10 +246,10 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
247
246
|
return __spreadArray([], __read(edgeSet), false);
|
|
248
247
|
};
|
|
249
248
|
/**
|
|
250
|
-
* The function
|
|
251
|
-
* @param {V | VertexId} vertexOrId - The `vertexOrId`
|
|
252
|
-
* `
|
|
253
|
-
* @returns an array of
|
|
249
|
+
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
250
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
251
|
+
* (`VertexId`).
|
|
252
|
+
* @returns an array of vertices (V[]).
|
|
254
253
|
*/
|
|
255
254
|
UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
256
255
|
var e_1, _a;
|
|
@@ -278,12 +277,11 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
278
277
|
return neighbors;
|
|
279
278
|
};
|
|
280
279
|
/**
|
|
281
|
-
* The function "getEndsOfEdge" returns the
|
|
282
|
-
*
|
|
283
|
-
* @param edge -
|
|
284
|
-
* array containing two vertices
|
|
285
|
-
*
|
|
286
|
-
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
280
|
+
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
281
|
+
* it returns null.
|
|
282
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
283
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
284
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
287
285
|
*/
|
|
288
286
|
UndirectedGraph.prototype.getEndsOfEdge = function (edge) {
|
|
289
287
|
if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
|
|
@@ -299,9 +297,8 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
299
297
|
}
|
|
300
298
|
};
|
|
301
299
|
/**
|
|
302
|
-
* The function adds an
|
|
303
|
-
* @param edge -
|
|
304
|
-
* array of two vertices connected by the edge.
|
|
300
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
301
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
305
302
|
* @returns a boolean value.
|
|
306
303
|
*/
|
|
307
304
|
UndirectedGraph.prototype._addEdgeOnly = function (edge) {
|
|
@@ -332,6 +329,10 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
332
329
|
}
|
|
333
330
|
return true;
|
|
334
331
|
};
|
|
332
|
+
/**
|
|
333
|
+
* The function sets the edges of a graph.
|
|
334
|
+
* @param v - A map where the keys are of type V and the values are arrays of type E.
|
|
335
|
+
*/
|
|
335
336
|
UndirectedGraph.prototype._setEdges = function (v) {
|
|
336
337
|
this._edges = v;
|
|
337
338
|
};
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
|
|
2
2
|
import { AbstractBinaryTreeNode } from '../binary-tree';
|
|
3
|
-
export interface IAbstractBinaryTreeNode<T,
|
|
4
|
-
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
3
|
+
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
|
5
4
|
get id(): BinaryTreeNodeId;
|
|
6
5
|
set id(v: BinaryTreeNodeId);
|
|
7
6
|
get val(): T | undefined;
|
|
8
7
|
set val(v: T | undefined);
|
|
9
|
-
get left():
|
|
10
|
-
set left(v:
|
|
11
|
-
get right():
|
|
12
|
-
set right(v:
|
|
13
|
-
get parent():
|
|
14
|
-
set parent(v:
|
|
8
|
+
get left(): NEIGHBOR | null | undefined;
|
|
9
|
+
set left(v: NEIGHBOR | null | undefined);
|
|
10
|
+
get right(): NEIGHBOR | null | undefined;
|
|
11
|
+
set right(v: NEIGHBOR | null | undefined);
|
|
12
|
+
get parent(): NEIGHBOR | null | undefined;
|
|
13
|
+
set parent(v: NEIGHBOR | null | undefined);
|
|
15
14
|
get familyPosition(): FamilyPosition;
|
|
16
|
-
get count(): number;
|
|
17
|
-
set count(v: number);
|
|
18
15
|
get height(): number;
|
|
19
16
|
set height(v: number);
|
|
20
|
-
swapLocation(swapNode: FAMILY): FAMILY;
|
|
21
|
-
clone(): FAMILY | null;
|
|
22
17
|
}
|
|
23
18
|
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
24
19
|
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
|
|
@@ -33,7 +28,7 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
|
|
|
33
28
|
get isMergeDuplicatedVal(): boolean;
|
|
34
29
|
get root(): N | null;
|
|
35
30
|
get size(): number;
|
|
36
|
-
|
|
31
|
+
swapLocation(srcNode: N, destNode: N): N;
|
|
37
32
|
clear(): void;
|
|
38
33
|
isEmpty(): boolean;
|
|
39
34
|
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
|
|
@@ -44,7 +39,7 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
|
|
|
44
39
|
getDepth(node: N): number;
|
|
45
40
|
getHeight(beginRoot?: N | null): number;
|
|
46
41
|
getMinHeight(beginRoot?: N | null): number;
|
|
47
|
-
|
|
42
|
+
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
48
43
|
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
49
44
|
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
50
45
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
@@ -57,7 +52,7 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
|
|
|
57
52
|
getRightMost(node?: N | null): N | null;
|
|
58
53
|
isBSTByRooted(node: N | null): boolean;
|
|
59
54
|
isBST(node?: N | null): boolean;
|
|
60
|
-
|
|
55
|
+
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
|
61
56
|
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
62
57
|
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
63
58
|
BFS(): BinaryTreeNodeId[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AVLTreeNode } from '../binary-tree';
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
3
|
import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
4
|
-
export interface IAVLTreeNode<T,
|
|
4
|
+
export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
5
5
|
}
|
|
6
6
|
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
-
add(id: BinaryTreeNodeId, val?: N['val'] | null
|
|
7
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null): N | null | undefined;
|
|
8
8
|
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
9
9
|
balanceFactor(node: N): number;
|
|
10
10
|
updateHeight(node: N): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BinaryTreeNode } from '../binary-tree';
|
|
2
2
|
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
3
|
-
export interface IBinaryTreeNode<T,
|
|
3
|
+
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> extends IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
|
4
4
|
}
|
|
5
5
|
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
|
|
6
6
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { BSTNode } from '../binary-tree';
|
|
2
2
|
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
|
|
3
3
|
import { BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName } from '../types';
|
|
4
|
-
export interface IBSTNode<T,
|
|
5
|
-
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
4
|
+
export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {
|
|
6
5
|
}
|
|
7
6
|
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
8
7
|
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
9
|
-
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null;
|
|
8
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null | undefined;
|
|
10
9
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
11
10
|
lastKey(): BinaryTreeNodeId;
|
|
12
11
|
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
13
12
|
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
14
13
|
lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
|
|
15
14
|
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
16
|
-
|
|
15
|
+
perfectlyBalance(): boolean;
|
|
17
16
|
isAVLBalanced(): boolean;
|
|
18
17
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { RBTreeNode } from '../binary-tree';
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
3
|
import { BinaryTreeNodeId } from '../types';
|
|
4
|
-
export interface IRBTreeNode<T,
|
|
5
|
-
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
4
|
+
export interface IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
6
5
|
}
|
|
7
6
|
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
|
|
8
7
|
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TreeMultisetNode } from '../binary-tree';
|
|
2
2
|
import { IBSTNode } from './bst';
|
|
3
3
|
import { IAVLTree } from './avl-tree';
|
|
4
|
-
export interface
|
|
4
|
+
export interface ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> extends IAVLTree<N> {
|
|
7
7
|
}
|
|
@@ -18,7 +18,7 @@ export declare enum FamilyPosition {
|
|
|
18
18
|
ISOLATED = "ISOLATED",
|
|
19
19
|
MAL_NODE = "MAL_NODE"
|
|
20
20
|
}
|
|
21
|
-
export type BinaryTreeNodePropertyName = 'id' | 'val'
|
|
21
|
+
export type BinaryTreeNodePropertyName = 'id' | 'val';
|
|
22
22
|
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
23
23
|
export type DFSOrderPattern = 'in' | 'pre' | 'post';
|
|
24
24
|
export type BinaryTreeNodeId = number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TreeMultisetNode } from '../binary-tree';
|
|
2
2
|
import { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
3
|
+
export type TreeMultisetNodeNested<T> = TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, TreeMultisetNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
+
export type TreeMultisetOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedVal'> & {
|
|
5
5
|
isMergeDuplicatedVal: true;
|
|
6
6
|
};
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./utils"), exports);
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./validate-type"), exports);
|
|
@@ -5,21 +5,3 @@ export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
|
5
5
|
export type TrlFn = (...args: any[]) => any;
|
|
6
6
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
7
7
|
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
-
export type KeyValueObject = {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
};
|
|
11
|
-
export type KeyValueObjectWithId = {
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
id: string | number | symbol;
|
|
14
|
-
};
|
|
15
|
-
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
16
|
-
export type ObjectWithoutId = Omit<KeyValueObject, 'id'>;
|
|
17
|
-
export type ObjectWithNonNumberId = {
|
|
18
|
-
[key: string]: any;
|
|
19
|
-
id: string | boolean | symbol | null | object | undefined;
|
|
20
|
-
};
|
|
21
|
-
export type ObjectWithNumberId = {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
id: number;
|
|
24
|
-
};
|
|
25
|
-
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | Function | never;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type KeyValueObject = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type KeyValueObjectWithId = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
id: string | number | symbol;
|
|
7
|
+
};
|
|
8
|
+
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
9
|
+
export type ObjectWithoutId = Omit<KeyValueObject, 'id'>;
|
|
10
|
+
export type ObjectWithNonNumberId = {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
id: string | boolean | symbol | null | object | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type ObjectWithNumberId = {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
id: number;
|
|
17
|
+
};
|
|
18
|
+
export type RestrictValById = NonNumberNonObjectButDefined | ObjectWithoutId | ObjectWithNonNumberId | ObjectWithNumberId;
|
|
19
|
+
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | Function | never;
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare const uuidV4: () => string;
|
|
2
|
-
export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
3
1
|
/**
|
|
4
2
|
* data-structure-typed
|
|
5
3
|
*
|
|
@@ -7,7 +5,9 @@ export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: nu
|
|
|
7
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
8
6
|
* @license MIT License
|
|
9
7
|
*/
|
|
10
|
-
import type {
|
|
8
|
+
import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
|
|
9
|
+
export declare const uuidV4: () => string;
|
|
10
|
+
export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
11
11
|
export declare const THUNK_SYMBOL: unique symbol;
|
|
12
12
|
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
13
13
|
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
@@ -17,8 +17,3 @@ export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>
|
|
|
17
17
|
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
18
18
|
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
19
19
|
};
|
|
20
|
-
export declare function isNonNumberNonObjectButDefined(val: any): val is NonNumberNonObjectButDefined;
|
|
21
|
-
export declare function isObjectWithoutId(val: any): val is ObjectWithoutId;
|
|
22
|
-
export declare function isObjectWithNonNumberId(val: any): val is ObjectWithNonNumberId;
|
|
23
|
-
export declare function isObjectWithNumberId(val: any): val is ObjectWithNumberId;
|
|
24
|
-
export declare function isNumber(val: any): val is number;
|
package/dist/utils/utils.js
CHANGED
|
@@ -61,7 +61,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
61
61
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
62
|
};
|
|
63
63
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
exports.
|
|
64
|
+
exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
|
|
65
65
|
var uuidV4 = function () {
|
|
66
66
|
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
|
67
67
|
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
@@ -149,85 +149,3 @@ var trampolineAsync = function (fn) {
|
|
|
149
149
|
}, { cont: cont });
|
|
150
150
|
};
|
|
151
151
|
exports.trampolineAsync = trampolineAsync;
|
|
152
|
-
// export class AutoPruneMap<K, V> extends Map<K, V> {
|
|
153
|
-
//
|
|
154
|
-
// private _proxySet: Set<V>;
|
|
155
|
-
// get proxySet(): Set<V> {
|
|
156
|
-
// return this._proxySet;
|
|
157
|
-
// }
|
|
158
|
-
//
|
|
159
|
-
// set proxySet(value: Set<V>) {
|
|
160
|
-
// this._proxySet = value;
|
|
161
|
-
// }
|
|
162
|
-
//
|
|
163
|
-
// private _isEmptyArrayAllowed: boolean;
|
|
164
|
-
//
|
|
165
|
-
// get isEmptyArrayAllowed(): boolean {
|
|
166
|
-
// return this._isEmptyArrayAllowed;
|
|
167
|
-
// }
|
|
168
|
-
//
|
|
169
|
-
// set isEmptyArrayAllowed(value: boolean) {
|
|
170
|
-
// this._isEmptyArrayAllowed = value;
|
|
171
|
-
// }
|
|
172
|
-
//
|
|
173
|
-
// constructor(isEmptyArrayAllowed: boolean = false) {
|
|
174
|
-
// super();
|
|
175
|
-
// this._isEmptyArrayAllowed = isEmptyArrayAllowed;
|
|
176
|
-
// this._proxySet = new Set<V>();
|
|
177
|
-
// }
|
|
178
|
-
//
|
|
179
|
-
// set(key: K, value: V): this {
|
|
180
|
-
// if (Array.isArray(value) && !this.proxySet.has(value)) {
|
|
181
|
-
// if(!this.isEmptyArrayAllowed && value.length === 0) return this;
|
|
182
|
-
// value = this.createArrayProxy(value, key);
|
|
183
|
-
// if (!this.proxySet.has(value)) this.proxySet.add(value);
|
|
184
|
-
// }
|
|
185
|
-
// super.set(key, value);
|
|
186
|
-
// return this;
|
|
187
|
-
// }
|
|
188
|
-
//
|
|
189
|
-
// private createArrayProxy(array: V & any[], key: K) {
|
|
190
|
-
// const that = this;
|
|
191
|
-
// const proxyHandler: ProxyHandler<V & any[]> = {
|
|
192
|
-
// set(target: any, property: PropertyKey, value: any): boolean {
|
|
193
|
-
// const result = Reflect.set(target, property, value);
|
|
194
|
-
// that.checkAndDeleteEmptyArray(key);
|
|
195
|
-
// return result;
|
|
196
|
-
// },
|
|
197
|
-
// deleteProperty(target: any, property: PropertyKey): boolean {
|
|
198
|
-
// const result = Reflect.deleteProperty(target, property);
|
|
199
|
-
// that.checkAndDeleteEmptyArray(key);
|
|
200
|
-
// return result;
|
|
201
|
-
// },
|
|
202
|
-
// }
|
|
203
|
-
// return new Proxy(array, proxyHandler);
|
|
204
|
-
// }
|
|
205
|
-
//
|
|
206
|
-
// private checkAndDeleteEmptyArray(key: K): void {
|
|
207
|
-
// const value = this.get(key);
|
|
208
|
-
//
|
|
209
|
-
// if (Array.isArray(value) && value.length === 0) {
|
|
210
|
-
// super.delete(key);
|
|
211
|
-
// }
|
|
212
|
-
// }
|
|
213
|
-
// }
|
|
214
|
-
function isNonNumberNonObjectButDefined(val) {
|
|
215
|
-
return typeof val !== 'number' && typeof val !== 'object' && val !== undefined;
|
|
216
|
-
}
|
|
217
|
-
exports.isNonNumberNonObjectButDefined = isNonNumberNonObjectButDefined;
|
|
218
|
-
function isObjectWithoutId(val) {
|
|
219
|
-
return typeof val === 'object' && !('id' in val);
|
|
220
|
-
}
|
|
221
|
-
exports.isObjectWithoutId = isObjectWithoutId;
|
|
222
|
-
function isObjectWithNonNumberId(val) {
|
|
223
|
-
return typeof val === 'object' && 'id' in val && typeof val.id !== 'number';
|
|
224
|
-
}
|
|
225
|
-
exports.isObjectWithNonNumberId = isObjectWithNonNumberId;
|
|
226
|
-
function isObjectWithNumberId(val) {
|
|
227
|
-
return typeof val === 'object' && 'id' in val && typeof val.id === 'number';
|
|
228
|
-
}
|
|
229
|
-
exports.isObjectWithNumberId = isObjectWithNumberId;
|
|
230
|
-
function isNumber(val) {
|
|
231
|
-
return typeof val === 'number';
|
|
232
|
-
}
|
|
233
|
-
exports.isNumber = isNumber;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { NonNumberNonObjectButDefined, ObjectWithNonNumberId, ObjectWithNumberId, ObjectWithoutId } from './types';
|
|
3
|
+
export declare const nonNumberNonObjectButDefinedSchema: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny]>>;
|
|
4
|
+
export declare const keyValueObjectSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
5
|
+
export declare const objectWithoutIdSchema: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>, Record<string, unknown>>;
|
|
6
|
+
export declare const keyValueObjectWithIdSchema: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
|
|
7
|
+
id: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodAny]>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
id?: any;
|
|
10
|
+
}, {
|
|
11
|
+
id?: any;
|
|
12
|
+
}>>;
|
|
13
|
+
export declare const objectWithNonNumberIdSchema: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
|
|
14
|
+
id: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny, z.ZodAny, z.ZodUndefined]>>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
id?: any;
|
|
17
|
+
}, {
|
|
18
|
+
id?: any;
|
|
19
|
+
}>>;
|
|
20
|
+
export declare const objectWithNumberIdSchema: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
|
|
21
|
+
id: z.ZodNumber;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
id: number;
|
|
24
|
+
}, {
|
|
25
|
+
id: number;
|
|
26
|
+
}>>;
|
|
27
|
+
export declare const binaryTreeNodeValWithId: z.ZodUnion<[z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny]>>, z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>, Record<string, unknown>>, z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
|
|
28
|
+
id: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodAny, z.ZodAny, z.ZodUndefined]>>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
id?: any;
|
|
31
|
+
}, {
|
|
32
|
+
id?: any;
|
|
33
|
+
}>>, z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
|
|
34
|
+
id: z.ZodNumber;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
id: number;
|
|
37
|
+
}, {
|
|
38
|
+
id: number;
|
|
39
|
+
}>>]>;
|
|
40
|
+
export declare function parseBySchema(schema: z.Schema, val: any): boolean;
|
|
41
|
+
export declare function isNonNumberNonObjectButDefined(val: any): val is NonNumberNonObjectButDefined;
|
|
42
|
+
export declare function isObjectWithoutId(val: any): val is ObjectWithoutId;
|
|
43
|
+
export declare function isObjectWithNonNumberId(val: any): val is ObjectWithNonNumberId;
|
|
44
|
+
export declare function isObjectWithNumberId(val: any): val is ObjectWithNumberId;
|
|
45
|
+
export declare function isNumber(val: any): val is number;
|