min-heap-typed 1.39.3 → 1.39.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -1
  2. package/dist/data-structures/binary-tree/avl-tree.js +4 -2
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +5 -13
  4. package/dist/data-structures/binary-tree/binary-tree.js +17 -25
  5. package/dist/data-structures/binary-tree/bst.d.ts +1 -1
  6. package/dist/data-structures/binary-tree/bst.js +6 -6
  7. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  8. package/dist/data-structures/binary-tree/tree-multiset.js +2 -2
  9. package/dist/data-structures/graph/abstract-graph.d.ts +88 -88
  10. package/dist/data-structures/graph/abstract-graph.js +41 -41
  11. package/dist/data-structures/graph/directed-graph.d.ts +63 -63
  12. package/dist/data-structures/graph/directed-graph.js +36 -36
  13. package/dist/data-structures/graph/map-graph.d.ts +10 -10
  14. package/dist/data-structures/graph/map-graph.js +7 -7
  15. package/dist/data-structures/graph/undirected-graph.d.ts +38 -38
  16. package/dist/data-structures/graph/undirected-graph.js +21 -21
  17. package/dist/data-structures/queue/queue.d.ts +1 -1
  18. package/dist/data-structures/queue/queue.js +3 -3
  19. package/dist/interfaces/graph.d.ts +3 -3
  20. package/package.json +2 -2
  21. package/src/data-structures/binary-tree/avl-tree.ts +3 -2
  22. package/src/data-structures/binary-tree/binary-tree.ts +19 -28
  23. package/src/data-structures/binary-tree/bst.ts +6 -6
  24. package/src/data-structures/binary-tree/tree-multiset.ts +2 -2
  25. package/src/data-structures/graph/abstract-graph.ts +135 -133
  26. package/src/data-structures/graph/directed-graph.ts +92 -87
  27. package/src/data-structures/graph/map-graph.ts +17 -20
  28. package/src/data-structures/graph/undirected-graph.ts +56 -54
  29. package/src/data-structures/queue/queue.ts +1 -1
  30. package/src/interfaces/graph.ts +3 -3
@@ -11,7 +11,7 @@ export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
11
11
  */
12
12
  constructor(key: VertexKey, val?: V);
13
13
  }
14
- export declare class UndirectedEdge<V = number> extends AbstractEdge<V> {
14
+ export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
15
15
  /**
16
16
  * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
17
17
  * value.
@@ -19,21 +19,21 @@ export declare class UndirectedEdge<V = number> extends AbstractEdge<V> {
19
19
  * @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
20
20
  * graph edge.
21
21
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
22
- * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store a value associated
22
+ * @param {E} [val] - The "val" parameter is an optional parameter of type E. It is used to store a value associated
23
23
  * with the edge.
24
24
  */
25
- constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: V);
25
+ constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: E);
26
26
  private _vertices;
27
27
  get vertices(): [VertexKey, VertexKey];
28
28
  set vertices(v: [VertexKey, VertexKey]);
29
29
  }
30
- export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IGraph<V, E> {
30
+ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
31
31
  /**
32
32
  * The constructor initializes a new Map object to store edges.
33
33
  */
34
34
  constructor();
35
- protected _edges: Map<V, E[]>;
36
- get edges(): Map<V, E[]>;
35
+ protected _edges: Map<VO, EO[]>;
36
+ get edges(): Map<VO, EO[]>;
37
37
  /**
38
38
  * The function creates a new vertex with an optional value and returns it.
39
39
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
@@ -41,9 +41,9 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
41
41
  * @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
42
42
  * it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
43
43
  * the vertex.
44
- * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
44
+ * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
45
45
  */
46
- createVertex(key: VertexKey, val?: V['val']): V;
46
+ createVertex(key: VertexKey, val?: VO['val']): VO;
47
47
  /**
48
48
  * The function creates an undirected edge between two vertices with an optional weight and value.
49
49
  * @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
@@ -52,76 +52,76 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
52
52
  * no weight is provided, it defaults to 1.
53
53
  * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
54
54
  * is used to store additional information or data associated with the edge.
55
- * @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
55
+ * @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
56
56
  */
57
- createEdge(v1: VertexKey, v2: VertexKey, weight?: number, val?: E['val']): E;
57
+ createEdge(v1: VertexKey, v2: VertexKey, weight?: number, val?: EO['val']): EO;
58
58
  /**
59
59
  * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
60
- * @param {V | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
60
+ * @param {VO | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
61
61
  * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
62
- * @param {V | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
62
+ * @param {VO | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
63
63
  * object), `null`, or `VertexKey` (vertex ID).
64
- * @returns an edge (E) or null.
64
+ * @returns an edge (EO) or null.
65
65
  */
66
- getEdge(v1: V | null | VertexKey, v2: V | null | VertexKey): E | null;
66
+ getEdge(v1: VO | null | VertexKey, v2: VO | null | VertexKey): EO | null;
67
67
  /**
68
68
  * The function removes an edge between two vertices in a graph and returns the removed edge.
69
- * @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
70
- * @param {V | VertexKey} v2 - V | VertexKey - This parameter can be either a vertex object (V) or a vertex ID
69
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
70
+ * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
71
71
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
72
- * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
72
+ * @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
73
73
  */
74
- deleteEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
74
+ deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | null;
75
75
  /**
76
76
  * The deleteEdge function removes an edge between two vertices in a graph.
77
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
78
- * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
77
+ * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
78
+ * @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
79
79
  */
80
- deleteEdge(edge: E): E | null;
80
+ deleteEdge(edge: EO): EO | null;
81
81
  /**
82
82
  * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
83
83
  * vertex.
84
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
84
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
85
85
  * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
86
86
  * edges connected to that vertex.
87
87
  */
88
- degreeOf(vertexOrKey: VertexKey | V): number;
88
+ degreeOf(vertexOrKey: VertexKey | VO): number;
89
89
  /**
90
90
  * The function returns the edges of a given vertex or vertex ID.
91
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`. A `VertexKey` is a
92
- * unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
91
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
92
+ * unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
93
93
  * @returns an array of edges.
94
94
  */
95
- edgesOf(vertexOrKey: VertexKey | V): E[];
95
+ edgesOf(vertexOrKey: VertexKey | VO): EO[];
96
96
  /**
97
97
  * The function "edgeSet" returns an array of unique edges from a set of edges.
98
- * @returns The method `edgeSet()` returns an array of type `E[]`.
98
+ * @returns The method `edgeSet()` returns an array of type `EO[]`.
99
99
  */
100
- edgeSet(): E[];
100
+ edgeSet(): EO[];
101
101
  /**
102
102
  * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
103
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
103
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
104
104
  * (`VertexKey`).
105
- * @returns an array of vertices (V[]).
105
+ * @returns an array of vertices (VO[]).
106
106
  */
107
- getNeighbors(vertexOrKey: V | VertexKey): V[];
107
+ getNeighbors(vertexOrKey: VO | VertexKey): VO[];
108
108
  /**
109
109
  * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
110
110
  * it returns null.
111
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
112
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
111
+ * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
112
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
113
113
  * graph. If the edge does not exist, it returns `null`.
114
114
  */
115
- getEndsOfEdge(edge: E): [V, V] | null;
115
+ getEndsOfEdge(edge: EO): [VO, VO] | null;
116
116
  /**
117
117
  * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
118
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
118
+ * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
119
119
  * @returns a boolean value.
120
120
  */
121
- protected _addEdgeOnly(edge: E): boolean;
121
+ protected _addEdgeOnly(edge: EO): boolean;
122
122
  /**
123
123
  * The function sets the edges of a graph.
124
- * @param v - A map where the keys are of type V and the values are arrays of type E.
124
+ * @param v - A map where the keys are of type VO and the values are arrays of type EO.
125
125
  */
126
- protected _setEdges(v: Map<V, E[]>): void;
126
+ protected _setEdges(v: Map<VO, EO[]>): void;
127
127
  }
@@ -31,7 +31,7 @@ class UndirectedEdge extends abstract_graph_1.AbstractEdge {
31
31
  * @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
32
32
  * graph edge.
33
33
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
34
- * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store a value associated
34
+ * @param {E} [val] - The "val" parameter is an optional parameter of type E. It is used to store a value associated
35
35
  * with the edge.
36
36
  */
37
37
  constructor(v1, v2, weight, val) {
@@ -64,7 +64,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
64
64
  * @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
65
65
  * it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
66
66
  * the vertex.
67
- * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
67
+ * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
68
68
  */
69
69
  createVertex(key, val) {
70
70
  return new UndirectedVertex(key, val !== null && val !== void 0 ? val : key);
@@ -77,18 +77,18 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
77
77
  * no weight is provided, it defaults to 1.
78
78
  * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
79
79
  * is used to store additional information or data associated with the edge.
80
- * @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
80
+ * @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
81
81
  */
82
82
  createEdge(v1, v2, weight, val) {
83
83
  return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
84
84
  }
85
85
  /**
86
86
  * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
87
- * @param {V | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
87
+ * @param {VO | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
88
88
  * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
89
- * @param {V | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
89
+ * @param {VO | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
90
90
  * object), `null`, or `VertexKey` (vertex ID).
91
- * @returns an edge (E) or null.
91
+ * @returns an edge (EO) or null.
92
92
  */
93
93
  getEdge(v1, v2) {
94
94
  var _a;
@@ -104,10 +104,10 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
104
104
  }
105
105
  /**
106
106
  * The function removes an edge between two vertices in a graph and returns the removed edge.
107
- * @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
108
- * @param {V | VertexKey} v2 - V | VertexKey - This parameter can be either a vertex object (V) or a vertex ID
107
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
108
+ * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
109
109
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
110
- * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
110
+ * @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
111
111
  */
112
112
  deleteEdgeBetween(v1, v2) {
113
113
  const vertex1 = this._getVertex(v1);
@@ -128,8 +128,8 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
128
128
  }
129
129
  /**
130
130
  * The deleteEdge function removes an edge between two vertices in a graph.
131
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
132
- * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
131
+ * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
132
+ * @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
133
133
  */
134
134
  deleteEdge(edge) {
135
135
  return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
@@ -137,7 +137,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
137
137
  /**
138
138
  * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
139
139
  * vertex.
140
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
140
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
141
141
  * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
142
142
  * edges connected to that vertex.
143
143
  */
@@ -153,8 +153,8 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
153
153
  }
154
154
  /**
155
155
  * The function returns the edges of a given vertex or vertex ID.
156
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`. A `VertexKey` is a
157
- * unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
156
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
157
+ * unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
158
158
  * @returns an array of edges.
159
159
  */
160
160
  edgesOf(vertexOrKey) {
@@ -168,7 +168,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
168
168
  }
169
169
  /**
170
170
  * The function "edgeSet" returns an array of unique edges from a set of edges.
171
- * @returns The method `edgeSet()` returns an array of type `E[]`.
171
+ * @returns The method `edgeSet()` returns an array of type `EO[]`.
172
172
  */
173
173
  edgeSet() {
174
174
  const edgeSet = new Set();
@@ -181,9 +181,9 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
181
181
  }
182
182
  /**
183
183
  * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
184
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
184
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
185
185
  * (`VertexKey`).
186
- * @returns an array of vertices (V[]).
186
+ * @returns an array of vertices (VO[]).
187
187
  */
188
188
  getNeighbors(vertexOrKey) {
189
189
  const neighbors = [];
@@ -202,8 +202,8 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
202
202
  /**
203
203
  * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
204
204
  * it returns null.
205
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
206
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
205
+ * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
206
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
207
207
  * graph. If the edge does not exist, it returns `null`.
208
208
  */
209
209
  getEndsOfEdge(edge) {
@@ -221,7 +221,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
221
221
  }
222
222
  /**
223
223
  * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
224
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
224
+ * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
225
225
  * @returns a boolean value.
226
226
  */
227
227
  _addEdgeOnly(edge) {
@@ -243,7 +243,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
243
243
  }
244
244
  /**
245
245
  * The function sets the edges of a graph.
246
- * @param v - A map where the keys are of type V and the values are arrays of type E.
246
+ * @param v - A map where the keys are of type VO and the values are arrays of type EO.
247
247
  */
248
248
  _setEdges(v) {
249
249
  this._edges = v;
@@ -4,7 +4,7 @@
4
4
  * @class
5
5
  */
6
6
  import { SinglyLinkedList } from '../linked-list';
7
- export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
7
+ export declare class SkipQueue<E = any> extends SinglyLinkedList<E> {
8
8
  /**
9
9
  * The enqueue function adds a value to the end of an array.
10
10
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = exports.LinkedListQueue = void 0;
3
+ exports.Queue = exports.SkipQueue = void 0;
4
4
  /**
5
5
  * @license MIT
6
6
  * @copyright Tyler Zeng <zrwusa@gmail.com>
7
7
  * @class
8
8
  */
9
9
  const linked_list_1 = require("../linked-list");
10
- class LinkedListQueue extends linked_list_1.SinglyLinkedList {
10
+ class SkipQueue extends linked_list_1.SinglyLinkedList {
11
11
  /**
12
12
  * The enqueue function adds a value to the end of an array.
13
13
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -31,7 +31,7 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
31
31
  return (_a = this.head) === null || _a === void 0 ? void 0 : _a.val;
32
32
  }
33
33
  }
34
- exports.LinkedListQueue = LinkedListQueue;
34
+ exports.SkipQueue = SkipQueue;
35
35
  class Queue {
36
36
  /**
37
37
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
@@ -1,5 +1,5 @@
1
1
  import { VertexKey } from '../types';
2
- export interface IGraph<V, E> {
3
- createVertex(key: VertexKey, val?: V): V;
4
- createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
2
+ export interface IGraph<V, E, VO, EO> {
3
+ createVertex(key: VertexKey, val?: V): VO;
4
+ createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): EO;
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.39.3",
3
+ "version": "1.39.5",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -131,6 +131,6 @@
131
131
  "typescript": "^4.9.5"
132
132
  },
133
133
  "dependencies": {
134
- "data-structure-typed": "^1.39.2"
134
+ "data-structure-typed": "^1.39.5"
135
135
  }
136
136
  }
@@ -71,13 +71,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
71
71
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
72
72
  * value. This value is compared with the `identifier` parameter to determine if the node should be
73
73
  * included in the result. The `callback` parameter has a default value of
74
- * `this._defaultCallbackByKey`
74
+ * `((node: N) => node.key)`
75
75
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
76
76
  */
77
77
  override delete<C extends BTNCallback<N>>(
78
78
  identifier: ReturnType<C>,
79
- callback: C = this._defaultCallbackByKey as C
79
+ callback: C = ((node: N) => node.key) as C
80
80
  ): BinaryTreeDeletedResult<N>[] {
81
+ if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;
81
82
  const deletedResults = super.delete(identifier, callback);
82
83
  for (const {needBalanced} of deletedResults) {
83
84
  if (needBalanced) {
@@ -217,7 +217,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
217
217
  }
218
218
 
219
219
  const key = typeof keyOrNode === 'number' ? keyOrNode : keyOrNode ? keyOrNode.key : undefined;
220
- const existNode = key !== undefined ? this.get(key, this._defaultCallbackByKey) : undefined;
220
+ const existNode = key !== undefined ? this.get(key, (node: N) => node.key) : undefined;
221
221
 
222
222
  if (this.root) {
223
223
  if (existNode) {
@@ -296,11 +296,11 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
296
296
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
297
297
  * value. This value is compared with the `identifier` parameter to determine if the node should be
298
298
  * included in the result. The `callback` parameter has a default value of
299
- * `this._defaultCallbackByKey`, which
299
+ * `((node: N) => node.key)`, which
300
300
  */
301
301
  delete<C extends BTNCallback<N>>(
302
302
  identifier: ReturnType<C> | null,
303
- callback: C = this._defaultCallbackByKey as C
303
+ callback: C = ((node: N) => node.key) as C
304
304
  ): BinaryTreeDeletedResult<N>[] {
305
305
  const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
306
306
  if (!this.root) return bstDeletedResult;
@@ -487,7 +487,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
487
487
 
488
488
  getNodes<C extends BTNCallback<N, BTNKey>>(
489
489
  identifier: BTNKey,
490
- callback: C,
490
+ callback?: C,
491
491
  onlyOne?: boolean,
492
492
  beginRoot?: N | null,
493
493
  iterationType?: IterationType
@@ -495,7 +495,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
495
495
 
496
496
  getNodes<C extends BTNCallback<N, N>>(
497
497
  identifier: N | null,
498
- callback: C,
498
+ callback?: C,
499
499
  onlyOne?: boolean,
500
500
  beginRoot?: N | null,
501
501
  iterationType?: IterationType
@@ -518,7 +518,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
518
518
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
519
519
  * value. This value is compared with the `identifier` parameter to determine if the node should be
520
520
  * included in the result. The `callback` parameter has a default value of
521
- * `this._defaultCallbackByKey`, which
521
+ * `((node: N) => node.key)`, which
522
522
  * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
523
523
  * first node that matches the identifier. If set to true, the function will return an array with
524
524
  * only one element (or an empty array if no matching node is found). If set to false (default), the
@@ -532,7 +532,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
532
532
  */
533
533
  getNodes<C extends BTNCallback<N>>(
534
534
  identifier: ReturnType<C> | null,
535
- callback: C = this._defaultCallbackByKey as C,
535
+ callback: C = ((node: N) => node.key) as C,
536
536
  onlyOne = false,
537
537
  beginRoot: N | null = this.root,
538
538
  iterationType = this.iterationType
@@ -600,7 +600,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
600
600
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
601
601
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
602
602
  * whether the node matches the criteria or not. The default callback function
603
- * `this._defaultCallbackByKey` is used if no callback function is
603
+ * `((node: N) => node.key)` is used if no callback function is
604
604
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
605
605
  * the node from which the search should begin. By default, it is set to `this.root`, which means the
606
606
  * search will start from the root node of the binary tree. However, you can provide a different node
@@ -611,7 +611,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
611
611
  */
612
612
  has<C extends BTNCallback<N>>(
613
613
  identifier: ReturnType<C> | null,
614
- callback: C = this._defaultCallbackByKey as C,
614
+ callback: C = ((node: N) => node.key) as C,
615
615
  beginRoot = this.root,
616
616
  iterationType = this.iterationType
617
617
  ): boolean {
@@ -649,7 +649,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
649
649
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
650
650
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
651
651
  * whether the node matches the criteria or not. The default callback function
652
- * (`this._defaultCallbackByKey`) is used if no callback function is
652
+ * (`((node: N) => node.key)`) is used if no callback function is
653
653
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
654
654
  * the root node from which the search should begin.
655
655
  * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
@@ -658,7 +658,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
658
658
  */
659
659
  get<C extends BTNCallback<N>>(
660
660
  identifier: ReturnType<C> | null,
661
- callback: C = this._defaultCallbackByKey as C,
661
+ callback: C = ((node: N) => node.key) as C,
662
662
  beginRoot = this.root,
663
663
  iterationType = this.iterationType
664
664
  ): N | null {
@@ -824,7 +824,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
824
824
  * @returns The function `subTreeTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
825
825
  */
826
826
  subTreeTraverse<C extends BTNCallback<N>>(
827
- callback: C = this._defaultCallbackByKey as C,
827
+ callback: C = ((node: N) => node.key) as C,
828
828
  beginRoot: BTNKey | N | null = this.root,
829
829
  iterationType = this.iterationType
830
830
  ): ReturnType<C>[] {
@@ -860,7 +860,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
860
860
  * function on each node according to a specified order pattern.
861
861
  * @param callback - The `callback` parameter is a function that will be called on each node during
862
862
  * the depth-first search traversal. It takes a node as input and returns a value. The default value
863
- * is `this._defaultCallbackByKey`, which is a callback function defined elsewhere in the code.
863
+ * is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code.
864
864
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
865
865
  * nodes are visited during the depth-first search. There are three possible values for `pattern`:
866
866
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
@@ -871,7 +871,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
871
871
  * @returns The function `dfs` returns an array of `ReturnType<BTNCallback<N>>` values.
872
872
  */
873
873
  dfs<C extends BTNCallback<N>>(
874
- callback: C = this._defaultCallbackByKey as C,
874
+ callback: C = ((node: N) => node.key) as C,
875
875
  pattern: DFSOrderPattern = 'in',
876
876
  beginRoot: N | null = this.root,
877
877
  iterationType: IterationType = IterationType.ITERATIVE
@@ -946,7 +946,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
946
946
  * function on each node.
947
947
  * @param callback - The `callback` parameter is a function that will be called for each node in the
948
948
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
949
- * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
949
+ * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key)
950
950
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
951
951
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
952
952
  * will not be performed and an empty array will be returned.
@@ -955,7 +955,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
955
955
  * @returns The function `bfs` returns an array of `ReturnType<BTNCallback<N>>[]`.
956
956
  */
957
957
  bfs<C extends BTNCallback<N>>(
958
- callback: C = this._defaultCallbackByKey as C,
958
+ callback: C = ((node: N) => node.key) as C,
959
959
  beginRoot: N | null = this.root,
960
960
  iterationType = this.iterationType
961
961
  ): ReturnType<C>[] {
@@ -1012,7 +1012,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1012
1012
  * function `C` applied to the nodes at that level.
1013
1013
  */
1014
1014
  listLevels<C extends BTNCallback<N>>(
1015
- callback: C = this._defaultCallbackByKey as C,
1015
+ callback: C = ((node: N) => node.key) as C,
1016
1016
  beginRoot: N | null = this.root,
1017
1017
  iterationType = this.iterationType
1018
1018
  ): ReturnType<C>[][] {
@@ -1071,7 +1071,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1071
1071
  * algorithm and returns an array of values obtained by applying a callback function to each node.
1072
1072
  * @param callback - The `callback` parameter is a function that will be called on each node in the
1073
1073
  * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
1074
- * default value for this parameter is `this._defaultCallbackByKey`.
1074
+ * default value for this parameter is `((node: N) => node.key)`.
1075
1075
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
1076
1076
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
1077
1077
  * following values:
@@ -1081,7 +1081,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1081
1081
  * @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
1082
1082
  */
1083
1083
  morris<C extends BTNCallback<N>>(
1084
- callback: C = this._defaultCallbackByKey as C,
1084
+ callback: C = ((node: N) => node.key) as C,
1085
1085
  pattern: DFSOrderPattern = 'in',
1086
1086
  beginRoot: N | null = this.root
1087
1087
  ): ReturnType<C>[] {
@@ -1226,15 +1226,6 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1226
1226
  return destNode;
1227
1227
  }
1228
1228
 
1229
- /**
1230
- * Time complexity is O(n)
1231
- * Space complexity of Iterative dfs equals to recursive dfs which is O(n) because of the stack
1232
- * The Morris algorithm only modifies the tree's structure during traversal; once the traversal is complete,
1233
- * the tree's structure should be restored to its original state to maintain the tree's integrity.
1234
- * This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
1235
- */
1236
- protected _defaultCallbackByKey: BTNCallback<N, BTNKey> = node => node.key;
1237
-
1238
1229
  /**
1239
1230
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
1240
1231
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
@@ -234,7 +234,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
234
234
  */
235
235
  override get<C extends BTNCallback<N>>(
236
236
  identifier: ReturnType<C> | null,
237
- callback: C = this._defaultCallbackByKey as C,
237
+ callback: C = ((node: N) => node.key) as C,
238
238
  beginRoot = this.root,
239
239
  iterationType = this.iterationType
240
240
  ): N | null {
@@ -270,7 +270,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
270
270
  * generic type `N`.
271
271
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
272
272
  * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
273
- * included in the result. The default value for `callback` is `this._defaultCallbackByKey`, which is
273
+ * included in the result. The default value for `callback` is `((node: N) => node.key)`, which is
274
274
  * a
275
275
  * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
276
276
  * the first node that matches the nodeProperty. If set to true, the function will return an array
@@ -285,7 +285,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
285
285
  */
286
286
  override getNodes<C extends BTNCallback<N>>(
287
287
  identifier: ReturnType<C> | null,
288
- callback: C = this._defaultCallbackByKey as C,
288
+ callback: C = ((node: N) => node.key) as C,
289
289
  onlyOne = false,
290
290
  beginRoot: N | null = this.root,
291
291
  iterationType = this.iterationType
@@ -303,7 +303,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
303
303
 
304
304
  if (!cur.left && !cur.right) return;
305
305
  // TODO potential bug
306
- if (callback === this._defaultCallbackByKey) {
306
+ if (callback === ((node: N) => node.key)) {
307
307
  if (this._compare(cur.key, identifier as number) === CP.gt) cur.left && _traverse(cur.left);
308
308
  if (this._compare(cur.key, identifier as number) === CP.lt) cur.right && _traverse(cur.right);
309
309
  } else {
@@ -324,7 +324,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
324
324
  if (onlyOne) return ans;
325
325
  }
326
326
  // TODO potential bug
327
- if (callback === this._defaultCallbackByKey) {
327
+ if (callback === ((node: N) => node.key)) {
328
328
  if (this._compare(cur.key, identifier as number) === CP.gt) cur.left && queue.push(cur.left);
329
329
  if (this._compare(cur.key, identifier as number) === CP.lt) cur.right && queue.push(cur.right);
330
330
  } else {
@@ -358,7 +358,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
358
358
  * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
359
359
  */
360
360
  lesserOrGreaterTraverse<C extends BTNCallback<N>>(
361
- callback: C = this._defaultCallbackByKey as C,
361
+ callback: C = ((node: N) => node.key) as C,
362
362
  lesserOrGreater: CP = CP.lt,
363
363
  targetNode: BTNKey | N | null = this.root,
364
364
  iterationType = this.iterationType
@@ -268,7 +268,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
268
268
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
269
269
  * value. This value is compared with the `identifier` parameter to determine if the node should be
270
270
  * included in the result. The `callback` parameter has a default value of
271
- * `this._defaultCallbackByKey`
271
+ * `((node: N) => node.key)`
272
272
  * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
273
273
  * being deleted. If set to true, the count of the node will not be considered and the node will be
274
274
  * deleted regardless of its count. If set to false (default), the count of the node will be
@@ -277,7 +277,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
277
277
  */
278
278
  override delete<C extends BTNCallback<N>>(
279
279
  identifier: ReturnType<C>,
280
- callback: C = this._defaultCallbackByKey as C,
280
+ callback: C = ((node: N) => node.key) as C,
281
281
  ignoreCount = false
282
282
  ): BinaryTreeDeletedResult<N>[] {
283
283
  const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];