bst-typed 1.47.8 → 1.47.9

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.
@@ -443,6 +443,11 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
443
443
  * @returns the bridges found using the Tarjan algorithm.
444
444
  */
445
445
  getBridges(): EO[];
446
+ [Symbol.iterator](): Iterator<[VertexKey, V | undefined]>;
447
+ forEach(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => void): void;
448
+ filter(predicate: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => boolean): [VertexKey, V | undefined][];
449
+ map<T>(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T): T[];
450
+ reduce<T>(callback: (accumulator: T, entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T, initialValue: T): T;
446
451
  protected abstract _addEdgeOnly(edge: EO): boolean;
447
452
  protected _addVertexOnly(newVertex: VO): boolean;
448
453
  protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
@@ -1028,6 +1028,47 @@ class AbstractGraph {
1028
1028
  getBridges() {
1029
1029
  return this.tarjan(false, true, false, false).bridges;
1030
1030
  }
1031
+ *[Symbol.iterator]() {
1032
+ for (const vertex of this._vertices.values()) {
1033
+ yield [vertex.key, vertex.value];
1034
+ }
1035
+ }
1036
+ forEach(callback) {
1037
+ let index = 0;
1038
+ for (const vertex of this) {
1039
+ callback(vertex, index, this._vertices);
1040
+ index++;
1041
+ }
1042
+ }
1043
+ filter(predicate) {
1044
+ const filtered = [];
1045
+ let index = 0;
1046
+ for (const entry of this) {
1047
+ if (predicate(entry, index, this._vertices)) {
1048
+ filtered.push(entry);
1049
+ }
1050
+ index++;
1051
+ }
1052
+ return filtered;
1053
+ }
1054
+ map(callback) {
1055
+ const mapped = [];
1056
+ let index = 0;
1057
+ for (const entry of this) {
1058
+ mapped.push(callback(entry, index, this._vertices));
1059
+ index++;
1060
+ }
1061
+ return mapped;
1062
+ }
1063
+ reduce(callback, initialValue) {
1064
+ let accumulator = initialValue;
1065
+ let index = 0;
1066
+ for (const entry of this) {
1067
+ accumulator = callback(accumulator, entry, index, this._vertices);
1068
+ index++;
1069
+ }
1070
+ return accumulator;
1071
+ }
1031
1072
  _addVertexOnly(newVertex) {
1032
1073
  if (this.hasVertex(newVertex)) {
1033
1074
  return false;
@@ -71,7 +71,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
71
71
  * @returns a new instance of a DirectedVertex object, casted as type VO.
72
72
  */
73
73
  createVertex(key, value) {
74
- return new DirectedVertex(key, value !== null && value !== void 0 ? value : key);
74
+ return new DirectedVertex(key, value);
75
75
  }
76
76
  /**
77
77
  * 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bst-typed",
3
- "version": "1.47.8",
3
+ "version": "1.47.9",
4
4
  "description": "BST (Binary Search Tree). Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -144,6 +144,6 @@
144
144
  "typescript": "^4.9.5"
145
145
  },
146
146
  "dependencies": {
147
- "data-structure-typed": "^1.47.8"
147
+ "data-structure-typed": "^1.47.9"
148
148
  }
149
149
  }
@@ -1159,6 +1159,52 @@ export abstract class AbstractGraph<
1159
1159
  return this.tarjan(false, true, false, false).bridges;
1160
1160
  }
1161
1161
 
1162
+ * [Symbol.iterator](): Iterator<[VertexKey, V | undefined]> {
1163
+ for (const vertex of this._vertices.values()) {
1164
+ yield [vertex.key, vertex.value];
1165
+ }
1166
+ }
1167
+
1168
+ forEach(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => void): void {
1169
+ let index = 0;
1170
+ for (const vertex of this) {
1171
+ callback(vertex, index, this._vertices);
1172
+ index++;
1173
+ }
1174
+ }
1175
+
1176
+ filter(predicate: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => boolean): [VertexKey, V | undefined][] {
1177
+ const filtered: [VertexKey, V | undefined][] = [];
1178
+ let index = 0;
1179
+ for (const entry of this) {
1180
+ if (predicate(entry, index, this._vertices)) {
1181
+ filtered.push(entry);
1182
+ }
1183
+ index++;
1184
+ }
1185
+ return filtered;
1186
+ }
1187
+
1188
+ map<T>(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T): T[] {
1189
+ const mapped: T[] = [];
1190
+ let index = 0;
1191
+ for (const entry of this) {
1192
+ mapped.push(callback(entry, index, this._vertices));
1193
+ index++;
1194
+ }
1195
+ return mapped;
1196
+ }
1197
+
1198
+ reduce<T>(callback: (accumulator: T, entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T, initialValue: T): T {
1199
+ let accumulator: T = initialValue;
1200
+ let index = 0;
1201
+ for (const entry of this) {
1202
+ accumulator = callback(accumulator, entry, index, this._vertices);
1203
+ index++;
1204
+ }
1205
+ return accumulator;
1206
+ }
1207
+
1162
1208
  protected abstract _addEdgeOnly(edge: EO): boolean;
1163
1209
 
1164
1210
  protected _addVertexOnly(newVertex: VO): boolean {
@@ -87,7 +87,7 @@ export class DirectedGraph<
87
87
  * @returns a new instance of a DirectedVertex object, casted as type VO.
88
88
  */
89
89
  createVertex(key: VertexKey, value?: V): VO {
90
- return new DirectedVertex(key, value ?? key) as VO;
90
+ return new DirectedVertex(key, value) as VO;
91
91
  }
92
92
 
93
93
  /**