data-structure-typed 1.18.8 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +185 -184
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +182 -148
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +288 -316
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +22 -14
  5. package/dist/data-structures/binary-tree/avl-tree.js +23 -17
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
  7. package/dist/data-structures/binary-tree/binary-tree.js +11 -26
  8. package/dist/data-structures/binary-tree/bst.d.ts +62 -74
  9. package/dist/data-structures/binary-tree/bst.js +72 -96
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -14
  11. package/dist/data-structures/binary-tree/rb-tree.js +5 -17
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +186 -17
  13. package/dist/data-structures/binary-tree/tree-multiset.js +712 -28
  14. package/dist/data-structures/graph/abstract-graph.d.ts +107 -49
  15. package/dist/data-structures/graph/abstract-graph.js +104 -55
  16. package/dist/data-structures/graph/directed-graph.d.ts +95 -94
  17. package/dist/data-structures/graph/directed-graph.js +95 -95
  18. package/dist/data-structures/graph/undirected-graph.d.ts +62 -61
  19. package/dist/data-structures/graph/undirected-graph.js +62 -61
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +10 -15
  21. package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
  22. package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
  23. package/dist/data-structures/interfaces/bst.d.ts +3 -4
  24. package/dist/data-structures/interfaces/rb-tree.d.ts +1 -2
  25. package/dist/data-structures/interfaces/tree-multiset.d.ts +3 -3
  26. package/dist/data-structures/types/abstract-binary-tree.d.ts +1 -1
  27. package/dist/data-structures/types/tree-multiset.d.ts +3 -3
  28. package/dist/utils/index.d.ts +1 -0
  29. package/dist/utils/index.js +1 -0
  30. package/dist/utils/types/index.d.ts +1 -0
  31. package/dist/utils/types/index.js +1 -0
  32. package/dist/utils/types/utils.d.ts +0 -18
  33. package/dist/utils/types/validate-type.d.ts +19 -0
  34. package/dist/utils/types/validate-type.js +2 -0
  35. package/dist/utils/utils.d.ts +3 -8
  36. package/dist/utils/utils.js +1 -83
  37. package/dist/utils/validate-type.d.ts +45 -0
  38. package/dist/utils/validate-type.js +58 -0
  39. package/package.json +4 -1
@@ -4,10 +4,10 @@ import { IDirectedGraph } from '../interfaces';
4
4
  export declare class DirectedVertex<T = number> extends AbstractVertex<T> {
5
5
  /**
6
6
  * The constructor function initializes a vertex with an optional value.
7
- * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
8
- * typically a unique identifier for each vertex in a graph.
9
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to specify the value
10
- * associated with the vertex.
7
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
8
+ * used to uniquely identify the vertex within a graph or data structure.
9
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
10
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
11
11
  */
12
12
  constructor(id: VertexId, val?: T);
13
13
  }
@@ -17,11 +17,10 @@ export declare class DirectedEdge<T = number> extends AbstractEdge<T> {
17
17
  * and value.
18
18
  * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
19
19
  * a graph.
20
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
21
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
22
- * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
23
- * If the weight is not provided, it will default to `undefined`.
24
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
20
+ * @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
21
+ * `VertexId`, which is likely a unique identifier for a vertex in a graph.
22
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
23
+ * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value associated with
25
24
  * the edge.
26
25
  */
27
26
  constructor(src: VertexId, dest: VertexId, weight?: number, val?: T);
@@ -33,6 +32,9 @@ export declare class DirectedEdge<T = number> extends AbstractEdge<T> {
33
32
  set dest(v: VertexId);
34
33
  }
35
34
  export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
35
+ /**
36
+ * The constructor function initializes an instance of a class.
37
+ */
36
38
  constructor();
37
39
  private _outEdgeMap;
38
40
  get outEdgeMap(): Map<V, E[]>;
@@ -41,118 +43,119 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
41
43
  /**
42
44
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
43
45
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
44
- * @param id
45
- * @param val
46
+ */
47
+ /**
48
+ * The function creates a new vertex with an optional value and returns it.
49
+ * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
50
+ * could be a number or a string depending on how you want to identify your vertices.
51
+ * @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
52
+ * it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
53
+ * assigned the same value as the 'id' parameter
54
+ * @returns a new instance of a DirectedVertex object, casted as type V.
46
55
  */
47
56
  createVertex(id: VertexId, val?: V['val']): V;
48
57
  /**
49
58
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
50
59
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
51
- * @param src
52
- * @param dest
53
- * @param weight
54
- * @param val
60
+ */
61
+ /**
62
+ * The function creates a directed edge between two vertices with an optional weight and value.
63
+ * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
64
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
65
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
66
+ * weight is provided, it defaults to 1.
67
+ * @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
68
+ * is used to store additional information or data associated with the edge.
69
+ * @returns a new instance of a DirectedEdge object, casted as type E.
55
70
  */
56
71
  createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
57
72
  /**
58
- * The function `getEdge` returns the directed edge between two vertices, given their source and destination.
59
- * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
60
- * DirectedVertex object or a VertexId.
61
- * @param {V | null | VertexId} destOrId - The `destOrId` parameter is the destination vertex or its
62
- * ID. It can be either a `DirectedVertex` object or a `VertexId` value.
63
- * @returns a E object or null.
73
+ * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
74
+ * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
75
+ * @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
76
+ * destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
77
+ * destination is not specified.
78
+ * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
64
79
  */
65
80
  getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
66
81
  /**
67
- * The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
68
- * edge, or null if the edge was not found.
69
- * @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
70
- * object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
71
- * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
72
- * edge that you want to remove. It can be either a `V` object or a `VertexId` value.
73
- * @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
74
- * the edge does not exist.
82
+ * The function removes an edge between two vertices in a graph and returns the removed edge.
83
+ * @param {V | VertexId} srcOrId - The source vertex or its ID.
84
+ * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
85
+ * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
75
86
  */
76
87
  removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
77
88
  /**
78
- * The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
79
- * not found.
80
- * @param edge - The `edge` parameter is an object of type `E`, which represents a directed edge in a
81
- * graph. It has two properties:
82
- * @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
83
- * if no edge is removed.
89
+ * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
90
+ * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
91
+ * and `dest`, which represent the source and destination vertices of the edge, respectively.
92
+ * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
84
93
  */
85
94
  removeEdge(edge: E): E | null;
86
95
  /**
87
- * The function removes all edges between two vertices and returns the removed edges.
88
- * @param {VertexId | V} v1 - The parameter `v1` represents either a `VertexId` or a `V` object. It is used to identify
89
- * the first vertex in the graph.
90
- * @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V`. It is used to identify the
91
- * second vertex involved in the edges that need to be removed.
92
- * @returns The function `removeEdgesBetween` returns an array of removed edges (`E[]`).
96
+ * The function removes edges between two vertices and returns the removed edges.
97
+ * @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
98
+ * unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
99
+ * @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
100
+ * the second vertex in the edge that needs to be removed.
101
+ * @returns an array of removed edges (E[]).
93
102
  */
94
103
  removeEdgesBetween(v1: VertexId | V, v2: VertexId | V): E[];
95
104
  /**
96
- * The function returns an array of incoming edges of a given vertex or vertex ID.
97
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
98
- * object or a `VertexId`.
99
- * @returns The method `incomingEdgesOf` returns an array of `E` objects.
105
+ * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
106
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
107
+ * (`VertexId`).
108
+ * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
100
109
  */
101
110
  incomingEdgesOf(vertexOrId: V | VertexId): E[];
102
111
  /**
103
- * The function `outgoingEdgesOf` returns an array of outgoing directed edges from a given vertex or vertex ID.
104
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
105
- * object or a `VertexId`.
106
- * @returns The method `outgoingEdgesOf` returns an array of `E` objects.
112
+ * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
113
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
114
+ * (`VertexId`).
115
+ * @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
107
116
  */
108
117
  outgoingEdgesOf(vertexOrId: V | VertexId): E[];
109
118
  /**
110
- * The function "degreeOf" returns the total degree of a vertex in a directed graph, which is the sum of its out-degree
111
- * and in-degree.
112
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
113
- * `V`.
114
- * @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
119
+ * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
120
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
121
+ * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
115
122
  */
116
123
  degreeOf(vertexOrId: VertexId | V): number;
117
124
  /**
118
- * The function "inDegreeOf" returns the number of incoming edges for a given vertex or vertex ID in a directed graph.
119
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
120
- * `V`.
125
+ * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
126
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
121
127
  * @returns The number of incoming edges of the specified vertex or vertex ID.
122
128
  */
123
129
  inDegreeOf(vertexOrId: VertexId | V): number;
124
130
  /**
125
- * The function "outDegreeOf" returns the number of outgoing edges from a given vertex.
126
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
127
- * `V`.
131
+ * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
132
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
128
133
  * @returns The number of outgoing edges from the specified vertex or vertex ID.
129
134
  */
130
135
  outDegreeOf(vertexOrId: VertexId | V): number;
131
136
  /**
132
- * The function "edgesOf" returns an array of both outgoing and incoming directed edges of a given vertex or vertex ID.
133
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
134
- * `V`.
135
- * @returns an array of directed edges.
137
+ * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
138
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
139
+ * @returns The function `edgesOf` returns an array of edges.
136
140
  */
137
141
  edgesOf(vertexOrId: VertexId | V): E[];
138
142
  /**
139
- * The function "getEdgeSrc" returns the source vertex of a directed edge, or null if the edge does not exist.
140
- * @param e - A directed edge object of type E.
141
- * @returns either a DirectedVertex object or null.
143
+ * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
144
+ * @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
145
+ * @returns either a vertex object (V) or null.
142
146
  */
143
147
  getEdgeSrc(e: E): V | null;
144
148
  /**
145
- * The function "getEdgeDest" returns the destination vertex of a directed edge.
146
- * @param e - E - This is an object representing a directed edge in a graph. It contains information
147
- * about the source vertex, destination vertex, and any associated data.
148
- * @returns either a DirectedVertex object or null.
149
+ * The function "getEdgeDest" returns the destination vertex of an edge.
150
+ * @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
151
+ * @returns either a vertex object of type V or null.
149
152
  */
150
153
  getEdgeDest(e: E): V | null;
151
154
  /**
152
- * The function `getDestinations` returns an array of directed vertices that are the destinations of outgoing edges
153
- * from a given vertex.
154
- * @param {V | VertexId | null} vertex - The `vertex` parameter can be one of the following:
155
- * @returns an array of DirectedVertex objects.
155
+ * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
156
+ * @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
157
+ * find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
158
+ * @returns an array of vertices (V[]).
156
159
  */
157
160
  getDestinations(vertex: V | VertexId | null): V[];
158
161
  /**
@@ -161,37 +164,35 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
161
164
  * @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
162
165
  * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
163
166
  * specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
164
- * @returns an array of vertices or vertex IDs in topological order, or null if there is a cycle in the graph.
167
+ * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
165
168
  */
166
169
  topologicalSort(propertyName?: 'vertex' | 'id'): Array<V | VertexId> | null;
167
170
  /**
168
- * The `edgeSet` function returns an array of all directed edges in the graph.
169
- * @returns The `edgeSet()` method returns an array of `E` objects.
171
+ * The `edgeSet` function returns an array of all the edges in the graph.
172
+ * @returns The `edgeSet()` method returns an array of edges (`E[]`).
170
173
  */
171
174
  edgeSet(): E[];
172
175
  /**
173
- * The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
174
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
175
- * object or a `VertexId`.
176
- * @returns an array of DirectedVertex objects.
176
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
177
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
178
+ * (`VertexId`).
179
+ * @returns an array of vertices (V[]).
177
180
  */
178
181
  getNeighbors(vertexOrId: V | VertexId): V[];
179
- /**--- start find cycles --- */
180
182
  /**
181
- * The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
182
- * graph, otherwise it returns null.
183
- * @param edge - A directed edge object with a generic type E.
184
- * @returns an array containing the starting and ending vertices of the given directed edge, or null if the edge does
185
- * not exist in the graph.
183
+ * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
184
+ * otherwise it returns null.
185
+ * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
186
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
187
+ * graph. If the edge does not exist, it returns `null`.
186
188
  */
187
189
  getEndsOfEdge(edge: E): [V, V] | null;
188
- /**--- end find cycles --- */
189
190
  /**
190
- * The `_addEdgeOnly` function adds a directed edge to a graph if the source and destination vertices exist.
191
- * @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
192
- * contains two properties:
193
- * @returns The method `_addEdgeOnly` returns a boolean value. It returns `true` if the edge was successfully added to the
194
- * graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
191
+ * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
192
+ * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
193
+ * needs to be added to the graph.
194
+ * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
195
+ * source or destination vertex does not exist in the graph.
195
196
  */
196
197
  protected _addEdgeOnly(edge: E): boolean;
197
198
  protected _setOutEdgeMap(value: Map<V, E[]>): void;