data-structure-typed 1.39.5 → 1.39.6

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 (107) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js +13 -13
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +17 -17
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
  9. package/dist/cjs/data-structures/binary-tree/bst.js +13 -13
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
  12. package/dist/cjs/data-structures/binary-tree/rb-tree.js +4 -4
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
  15. package/dist/cjs/data-structures/binary-tree/segment-tree.js +16 -16
  16. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  18. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +18 -18
  19. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
  21. package/dist/cjs/data-structures/graph/abstract-graph.js +24 -24
  22. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/directed-graph.d.ts +12 -12
  24. package/dist/cjs/data-structures/graph/directed-graph.js +15 -15
  25. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/map-graph.d.ts +9 -9
  27. package/dist/cjs/data-structures/graph/map-graph.js +13 -13
  28. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +11 -11
  30. package/dist/cjs/data-structures/graph/undirected-graph.js +14 -14
  31. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/hash/hash-table.d.ts +4 -4
  33. package/dist/cjs/data-structures/hash/hash-table.js +8 -8
  34. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  35. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
  36. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +54 -54
  37. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
  39. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +52 -52
  40. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  41. package/dist/cjs/data-structures/queue/queue.js +1 -1
  42. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  43. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  44. package/dist/cjs/interfaces/graph.d.ts +2 -2
  45. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
  46. package/dist/mjs/data-structures/binary-tree/avl-tree.js +13 -13
  47. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
  48. package/dist/mjs/data-structures/binary-tree/binary-tree.js +18 -18
  49. package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
  50. package/dist/mjs/data-structures/binary-tree/bst.js +13 -13
  51. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
  52. package/dist/mjs/data-structures/binary-tree/rb-tree.js +4 -4
  53. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
  54. package/dist/mjs/data-structures/binary-tree/segment-tree.js +16 -16
  55. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  56. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +18 -18
  57. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
  58. package/dist/mjs/data-structures/graph/abstract-graph.js +26 -26
  59. package/dist/mjs/data-structures/graph/directed-graph.d.ts +12 -12
  60. package/dist/mjs/data-structures/graph/directed-graph.js +15 -15
  61. package/dist/mjs/data-structures/graph/map-graph.d.ts +9 -9
  62. package/dist/mjs/data-structures/graph/map-graph.js +13 -13
  63. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +11 -11
  64. package/dist/mjs/data-structures/graph/undirected-graph.js +14 -14
  65. package/dist/mjs/data-structures/hash/hash-table.d.ts +4 -4
  66. package/dist/mjs/data-structures/hash/hash-table.js +9 -9
  67. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
  68. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +55 -55
  69. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
  70. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +53 -53
  71. package/dist/mjs/data-structures/queue/queue.js +1 -1
  72. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  73. package/dist/mjs/interfaces/graph.d.ts +2 -2
  74. package/dist/umd/data-structure-typed.min.js +1 -1
  75. package/dist/umd/data-structure-typed.min.js.map +1 -1
  76. package/package.json +5 -5
  77. package/src/data-structures/binary-tree/avl-tree.ts +13 -13
  78. package/src/data-structures/binary-tree/binary-tree.ts +18 -18
  79. package/src/data-structures/binary-tree/bst.ts +16 -16
  80. package/src/data-structures/binary-tree/rb-tree.ts +6 -6
  81. package/src/data-structures/binary-tree/segment-tree.ts +15 -15
  82. package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
  83. package/src/data-structures/graph/abstract-graph.ts +34 -34
  84. package/src/data-structures/graph/directed-graph.ts +16 -16
  85. package/src/data-structures/graph/map-graph.ts +13 -13
  86. package/src/data-structures/graph/undirected-graph.ts +15 -15
  87. package/src/data-structures/hash/hash-table.ts +9 -9
  88. package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
  89. package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
  90. package/src/data-structures/queue/queue.ts +1 -1
  91. package/src/interfaces/binary-tree.ts +2 -2
  92. package/src/interfaces/graph.ts +2 -2
  93. package/test/integration/bst.test.ts +2 -2
  94. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
  95. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +3 -3
  96. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +8 -8
  97. package/test/unit/data-structures/binary-tree/bst.test.ts +4 -4
  98. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
  99. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
  100. package/test/unit/data-structures/graph/abstract-graph.test.ts +99 -2
  101. package/test/unit/data-structures/graph/directed-graph.test.ts +22 -12
  102. package/test/unit/data-structures/graph/undirected-graph.test.ts +8 -0
  103. package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
  104. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
  105. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  106. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +15 -15
  107. package/test/utils/big-o.ts +7 -7
@@ -16,12 +16,12 @@ export abstract class AbstractVertex<V = any> {
16
16
  * The function is a protected constructor that takes an key and an optional value as parameters.
17
17
  * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
18
18
  * used to uniquely identify the vertex object.
19
- * @param {V} [val] - The parameter "val" is an optional parameter of type V. It is used to assign a value to the
19
+ * @param {V} [value] - The parameter "value" is an optional parameter of type V. It is used to assign a value to the
20
20
  * vertex. If no value is provided, it will be set to undefined.
21
21
  */
22
- protected constructor(key: VertexKey, val?: V) {
22
+ protected constructor(key: VertexKey, value?: V) {
23
23
  this._key = key;
24
- this._val = val;
24
+ this._value = value;
25
25
  }
26
26
 
27
27
  private _key: VertexKey;
@@ -34,41 +34,41 @@ export abstract class AbstractVertex<V = any> {
34
34
  this._key = v;
35
35
  }
36
36
 
37
- private _val: V | undefined;
37
+ private _value: V | undefined;
38
38
 
39
- get val(): V | undefined {
40
- return this._val;
39
+ get value(): V | undefined {
40
+ return this._value;
41
41
  }
42
42
 
43
- set val(value: V | undefined) {
44
- this._val = value;
43
+ set value(value: V | undefined) {
44
+ this._value = value;
45
45
  }
46
46
  }
47
47
 
48
- export abstract class AbstractEdge<VO = any> {
48
+ export abstract class AbstractEdge<E = any> {
49
49
  /**
50
50
  * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
51
51
  * object.
52
52
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
53
53
  * a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
54
54
  * will be assigned.
55
- * @param {VO} [val] - The `val` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
55
+ * @param {VO} [value] - The `value` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
56
56
  * meaning it can be omitted when creating an instance of the class.
57
57
  */
58
- protected constructor(weight?: number, val?: VO) {
58
+ protected constructor(weight?: number, value?: E) {
59
59
  this._weight = weight !== undefined ? weight : 1;
60
- this._val = val;
60
+ this._value = value;
61
61
  this._hashCode = uuidV4();
62
62
  }
63
63
 
64
- private _val: VO | undefined;
64
+ private _value: E | undefined;
65
65
 
66
- get val(): VO | undefined {
67
- return this._val;
66
+ get value(): E | undefined {
67
+ return this._value;
68
68
  }
69
69
 
70
- set val(value: VO | undefined) {
71
- this._val = value;
70
+ set value(value: E | undefined) {
71
+ this._value = value;
72
72
  }
73
73
 
74
74
  private _weight: number;
@@ -119,9 +119,9 @@ export abstract class AbstractGraph<
119
119
  * 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.
120
120
  * 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.
121
121
  * @param key
122
- * @param val
122
+ * @param value
123
123
  */
124
- abstract createVertex(key: VertexKey, val?: V): VO;
124
+ abstract createVertex(key: VertexKey, value?: V): VO;
125
125
 
126
126
  /**
127
127
  * 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.
@@ -129,9 +129,9 @@ export abstract class AbstractGraph<
129
129
  * @param srcOrV1
130
130
  * @param destOrV2
131
131
  * @param weight
132
- * @param val
132
+ * @param value
133
133
  */
134
- abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): EO;
134
+ abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
135
135
 
136
136
  abstract deleteEdge(edge: EO): EO | null;
137
137
 
@@ -170,13 +170,13 @@ export abstract class AbstractGraph<
170
170
 
171
171
  addVertex(vertex: VO): boolean;
172
172
 
173
- addVertex(key: VertexKey, val?: V): boolean;
173
+ addVertex(key: VertexKey, value?: V): boolean;
174
174
 
175
- addVertex(keyOrVertex: VertexKey | VO, val?: V): boolean {
175
+ addVertex(keyOrVertex: VertexKey | VO, value?: V): boolean {
176
176
  if (keyOrVertex instanceof AbstractVertex) {
177
177
  return this._addVertexOnly(keyOrVertex);
178
178
  } else {
179
- const newVertex = this.createVertex(keyOrVertex, val);
179
+ const newVertex = this.createVertex(keyOrVertex, value);
180
180
  return this._addVertexOnly(newVertex);
181
181
  }
182
182
  }
@@ -222,9 +222,9 @@ export abstract class AbstractGraph<
222
222
 
223
223
  addEdge(edge: EO): boolean;
224
224
 
225
- addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, val?: E): boolean;
225
+ addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
226
226
 
227
- addEdge(srcOrEdge: VO | VertexKey | EO, dest?: VO | VertexKey, weight?: number, val?: E): boolean {
227
+ addEdge(srcOrEdge: VO | VertexKey | EO, dest?: VO | VertexKey, weight?: number, value?: E): boolean {
228
228
  if (srcOrEdge instanceof AbstractEdge) {
229
229
  return this._addEdgeOnly(srcOrEdge);
230
230
  } else {
@@ -232,7 +232,7 @@ export abstract class AbstractGraph<
232
232
  if (!(this.hasVertex(srcOrEdge) && this.hasVertex(dest))) return false;
233
233
  if (srcOrEdge instanceof AbstractVertex) srcOrEdge = srcOrEdge.key;
234
234
  if (dest instanceof AbstractVertex) dest = dest.key;
235
- const newEdge = this.createEdge(srcOrEdge, dest, weight, val);
235
+ const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
236
236
  return this._addEdgeOnly(newEdge);
237
237
  } else {
238
238
  throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
@@ -493,10 +493,10 @@ export abstract class AbstractGraph<
493
493
  const getMinOfNoSeen = () => {
494
494
  let min = Infinity;
495
495
  let minV: VO | null = null;
496
- for (const [key, val] of distMap) {
496
+ for (const [key, value] of distMap) {
497
497
  if (!seen.has(key)) {
498
- if (val < min) {
499
- min = val;
498
+ if (value < min) {
499
+ min = value;
500
500
  minV = key;
501
501
  }
502
502
  }
@@ -625,8 +625,8 @@ export abstract class AbstractGraph<
625
625
  if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
626
626
  }
627
627
 
628
- const heap = new PriorityQueue<{key: number; val: VO}>({comparator: (a, b) => a.key - b.key});
629
- heap.add({key: 0, val: srcVertex});
628
+ const heap = new PriorityQueue<{key: number; value: VO}>({comparator: (a, b) => a.key - b.key});
629
+ heap.add({key: 0, value: srcVertex});
630
630
 
631
631
  distMap.set(srcVertex, 0);
632
632
  preMap.set(srcVertex, null);
@@ -656,7 +656,7 @@ export abstract class AbstractGraph<
656
656
  while (heap.size > 0) {
657
657
  const curHeapNode = heap.poll();
658
658
  const dist = curHeapNode?.key;
659
- const cur = curHeapNode?.val;
659
+ const cur = curHeapNode?.value;
660
660
  if (dist !== undefined) {
661
661
  if (cur) {
662
662
  seen.add(cur);
@@ -677,7 +677,7 @@ export abstract class AbstractGraph<
677
677
  const distSrcToNeighbor = distMap.get(neighbor);
678
678
  if (distSrcToNeighbor) {
679
679
  if (dist + weight < distSrcToNeighbor) {
680
- heap.add({key: dist + weight, val: neighbor});
680
+ heap.add({key: dist + weight, value: neighbor});
681
681
  preMap.set(neighbor, cur);
682
682
  distMap.set(neighbor, dist + weight);
683
683
  }
@@ -15,11 +15,11 @@ export class DirectedVertex<V = any> extends AbstractVertex<V> {
15
15
  * The constructor function initializes a vertex with an optional value.
16
16
  * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
17
17
  * used to uniquely identify the vertex within a graph or data structure.
18
- * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
18
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
19
19
  * vertex. If no value is provided, the vertex will be initialized with a default value.
20
20
  */
21
- constructor(key: VertexKey, val?: V) {
22
- super(key, val);
21
+ constructor(key: VertexKey, value?: V) {
22
+ super(key, value);
23
23
  }
24
24
  }
25
25
 
@@ -32,11 +32,11 @@ export class DirectedEdge<E = any> extends AbstractEdge<E> {
32
32
  * @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
33
33
  * `VertexKey`, which is likely a unique identifier for a vertex in a graph.
34
34
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
35
- * @param {E} [val] - The `val` parameter is an optional parameter of type `E`. It represents the value associated with
35
+ * @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
36
36
  * the edge.
37
37
  */
38
- constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: E) {
39
- super(weight, val);
38
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E) {
39
+ super(weight, value);
40
40
  this._src = src;
41
41
  this._dest = dest;
42
42
  }
@@ -99,13 +99,13 @@ export class DirectedGraph<
99
99
  * The function creates a new vertex with an optional value and returns it.
100
100
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
101
101
  * could be a number or a string depending on how you want to identify your vertices.
102
- * @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
103
- * it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
102
+ * @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
103
+ * it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
104
104
  * assigned the same value as the 'key' parameter
105
105
  * @returns a new instance of a DirectedVertex object, casted as type VO.
106
106
  */
107
- createVertex(key: VertexKey, val?: V): VO {
108
- return new DirectedVertex(key, val ?? key) as VO;
107
+ createVertex(key: VertexKey, value?: V): VO {
108
+ return new DirectedVertex(key, value ?? key) as VO;
109
109
  }
110
110
 
111
111
  /**
@@ -119,23 +119,23 @@ export class DirectedGraph<
119
119
  * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
120
120
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
121
121
  * weight is provided, it defaults to 1.
122
- * @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
122
+ * @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
123
123
  * is used to store additional information or data associated with the edge.
124
124
  * @returns a new instance of a DirectedEdge object, casted as type EO.
125
125
  */
126
- createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E): EO {
127
- return new DirectedEdge(src, dest, weight ?? 1, val) as EO;
126
+ createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO {
127
+ return new DirectedEdge(src, dest, weight ?? 1, value) as EO;
128
128
  }
129
129
 
130
130
  /**
131
131
  * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
132
- * @param {VO | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
133
- * @param {VO | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
132
+ * @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
133
+ * @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
134
134
  * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
135
135
  * destination is not specified.
136
136
  * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
137
137
  */
138
- getEdge(srcOrKey: VO | null | VertexKey, destOrKey: VO | null | VertexKey): EO | null {
138
+ getEdge(srcOrKey: VO | VertexKey | null, destOrKey: VO | VertexKey | null): EO | null {
139
139
  let edges: EO[] = [];
140
140
 
141
141
  if (srcOrKey !== null && destOrKey !== null) {
@@ -11,11 +11,11 @@ export class MapVertex<V = any> extends DirectedVertex<V> {
11
11
  * @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
12
12
  * coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
13
13
  * values ranging from -180 to 180.
14
- * @param {V} [val] - The "val" parameter is an optional value of type V. It is not required to be provided when
14
+ * @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
15
15
  * creating an instance of the class.
16
16
  */
17
- constructor(key: VertexKey, val: V, lat: number, long: number) {
18
- super(key, val);
17
+ constructor(key: VertexKey, value: V, lat: number, long: number) {
18
+ super(key, value);
19
19
  this._lat = lat;
20
20
  this._long = long;
21
21
  }
@@ -49,11 +49,11 @@ export class MapEdge<E = any> extends DirectedEdge<E> {
49
49
  * a graph.
50
50
  * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
51
51
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
52
- * @param {E} [val] - The "val" parameter is an optional parameter of type E. It is used to store additional
52
+ * @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
53
53
  * information or data associated with the edge.
54
54
  */
55
- constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: E) {
56
- super(src, dest, weight, val);
55
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E) {
56
+ super(src, dest, weight, value);
57
57
  }
58
58
  }
59
59
 
@@ -102,15 +102,15 @@ export class MapGraph<
102
102
  * The function creates a new vertex with the given key, value, latitude, and longitude.
103
103
  * @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
104
104
  * be a string or a number depending on how you define it in your code.
105
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
106
- * is of type `V`, which means it should be of the same type as the `val` property of the vertex class `VO`.
105
+ * @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
106
+ * is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
107
107
  * @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
108
108
  * position of the vertex on the Earth's surface in the north-south direction.
109
109
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
110
110
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
111
111
  */
112
- override createVertex(key: VertexKey, val?: V, lat: number = this.origin[0], long: number = this.origin[1]): VO {
113
- return new MapVertex(key, val, lat, long) as VO;
112
+ override createVertex(key: VertexKey, value?: V, lat: number = this.origin[0], long: number = this.origin[1]): VO {
113
+ return new MapVertex(key, value, lat, long) as VO;
114
114
  }
115
115
 
116
116
  /**
@@ -121,11 +121,11 @@ export class MapGraph<
121
121
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
122
122
  * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
123
123
  * If the weight is not provided, it can be set to a default value or left undefined.
124
- * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type,
124
+ * @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
125
125
  * depending on the specific implementation of the `MapEdge` class.
126
126
  * @returns a new instance of the `MapEdge` class, cast as type `EO`.
127
127
  */
128
- override createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E): EO {
129
- return new MapEdge(src, dest, weight, val) as EO;
128
+ override createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO {
129
+ return new MapEdge(src, dest, weight, value) as EO;
130
130
  }
131
131
  }
@@ -15,11 +15,11 @@ export class UndirectedVertex<V = any> extends AbstractVertex<V> {
15
15
  * The constructor function initializes a vertex with an optional value.
16
16
  * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
17
17
  * used to uniquely identify the vertex within a graph or network.
18
- * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
18
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
19
19
  * vertex. If no value is provided, the vertex will be initialized with a default value.
20
20
  */
21
- constructor(key: VertexKey, val?: V) {
22
- super(key, val);
21
+ constructor(key: VertexKey, value?: V) {
22
+ super(key, value);
23
23
  }
24
24
  }
25
25
 
@@ -31,11 +31,11 @@ export class UndirectedEdge<E = number> extends AbstractEdge<E> {
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 {E} [val] - The "val" parameter is an optional parameter of type E. It is used to store a value associated
34
+ * @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
35
35
  * with the edge.
36
36
  */
37
- constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: E) {
38
- super(weight, val);
37
+ constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E) {
38
+ super(weight, value);
39
39
  this._vertices = [v1, v2];
40
40
  }
41
41
 
@@ -77,13 +77,13 @@ export class UndirectedGraph<
77
77
  * The function creates a new vertex with an optional value and returns it.
78
78
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
79
79
  * vertex from another in the graph.
80
- * @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
80
+ * @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
81
81
  * 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
82
82
  * the vertex.
83
83
  * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
84
84
  */
85
- override createVertex(key: VertexKey, val?: VO['val']): VO {
86
- return new UndirectedVertex(key, val ?? key) as VO;
85
+ override createVertex(key: VertexKey, value?: VO['value']): VO {
86
+ return new UndirectedVertex(key, value ?? key) as VO;
87
87
  }
88
88
 
89
89
  /**
@@ -92,23 +92,23 @@ export class UndirectedGraph<
92
92
  * @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
93
93
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
94
94
  * no weight is provided, it defaults to 1.
95
- * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
95
+ * @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type and
96
96
  * is used to store additional information or data associated with the edge.
97
97
  * @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
98
98
  */
99
- override createEdge(v1: VertexKey, v2: VertexKey, weight?: number, val?: EO['val']): EO {
100
- return new UndirectedEdge(v1, v2, weight ?? 1, val) as EO;
99
+ override createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO {
100
+ return new UndirectedEdge(v1, v2, weight ?? 1, value) as EO;
101
101
  }
102
102
 
103
103
  /**
104
104
  * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
105
- * @param {VO | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
105
+ * @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
106
106
  * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
107
- * @param {VO | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
107
+ * @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
108
108
  * object), `null`, or `VertexKey` (vertex ID).
109
109
  * @returns an edge (EO) or null.
110
110
  */
111
- getEdge(v1: VO | null | VertexKey, v2: VO | null | VertexKey): EO | null {
111
+ getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null {
112
112
  let edges: EO[] | undefined = [];
113
113
 
114
114
  if (v1 !== null && v2 !== null) {
@@ -8,12 +8,12 @@
8
8
 
9
9
  export class HashTableNode<K, V> {
10
10
  key: K;
11
- val: V;
11
+ value: V;
12
12
  next: HashTableNode<K, V> | null;
13
13
 
14
- constructor(key: K, val: V) {
14
+ constructor(key: K, value: V) {
15
15
  this.key = key;
16
- this.val = val;
16
+ this.value = value;
17
17
  this.next = null;
18
18
  }
19
19
  }
@@ -71,14 +71,14 @@ export class HashTable<K, V> {
71
71
  * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
72
72
  * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
73
73
  * table. It is of type K, which is a generic type representing the key's data type.
74
- * @param {V} val - The parameter `val` represents the value that you want to associate with the given key in the hash
74
+ * @param {V} value - The parameter `value` represents the value that you want to associate with the given key in the hash
75
75
  * table.
76
76
  * @returns Nothing is being returned. The return type of the `put` method is `void`, which means it does not return any
77
77
  * value.
78
78
  */
79
- set(key: K, val: V): void {
79
+ set(key: K, value: V): void {
80
80
  const index = this._hash(key);
81
- const newNode = new HashTableNode<K, V>(key, val);
81
+ const newNode = new HashTableNode<K, V>(key, value);
82
82
 
83
83
  if (!this._buckets[index]) {
84
84
  this._buckets[index] = newNode;
@@ -88,7 +88,7 @@ export class HashTable<K, V> {
88
88
  while (currentNode) {
89
89
  if (currentNode.key === key) {
90
90
  // If the key already exists, update the value
91
- currentNode.val = val;
91
+ currentNode.value = value;
92
92
  return;
93
93
  }
94
94
  if (!currentNode.next) {
@@ -120,7 +120,7 @@ export class HashTable<K, V> {
120
120
 
121
121
  while (currentNode) {
122
122
  if (currentNode.key === key) {
123
- return currentNode.val;
123
+ return currentNode.value;
124
124
  }
125
125
  currentNode = currentNode.next;
126
126
  }
@@ -259,7 +259,7 @@ export class HashTable<K, V> {
259
259
  let currentNode = bucket;
260
260
  while (currentNode) {
261
261
  const newIndex = this._hash(currentNode.key);
262
- const newNode = new HashTableNode<K, V>(currentNode.key, currentNode.val);
262
+ const newNode = new HashTableNode<K, V>(currentNode.key, currentNode.value);
263
263
 
264
264
  if (!newBuckets[newIndex]) {
265
265
  newBuckets[newIndex] = newNode;