min-heap-typed 1.39.6 → 1.40.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 (93) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.js +0 -1
  2. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  3. package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  4. package/dist/data-structures/binary-tree/binary-tree.d.ts +5 -20
  5. package/dist/data-structures/binary-tree/binary-tree.js +8 -29
  6. package/dist/data-structures/binary-tree/bst.d.ts +1 -1
  7. package/dist/data-structures/binary-tree/bst.js +3 -3
  8. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -3
  9. package/dist/data-structures/binary-tree/rb-tree.js +1 -7
  10. package/dist/data-structures/binary-tree/segment-tree.d.ts +10 -26
  11. package/dist/data-structures/binary-tree/segment-tree.js +10 -58
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  13. package/dist/data-structures/binary-tree/tree-multiset.js +6 -6
  14. package/dist/data-structures/graph/abstract-graph.d.ts +5 -24
  15. package/dist/data-structures/graph/abstract-graph.js +4 -43
  16. package/dist/data-structures/graph/directed-graph.d.ts +4 -10
  17. package/dist/data-structures/graph/directed-graph.js +2 -20
  18. package/dist/data-structures/graph/map-graph.d.ts +4 -10
  19. package/dist/data-structures/graph/map-graph.js +2 -20
  20. package/dist/data-structures/graph/undirected-graph.d.ts +1 -8
  21. package/dist/data-structures/graph/undirected-graph.js +1 -14
  22. package/dist/data-structures/hash/coordinate-map.d.ts +0 -1
  23. package/dist/data-structures/hash/coordinate-map.js +0 -3
  24. package/dist/data-structures/hash/coordinate-set.d.ts +0 -1
  25. package/dist/data-structures/hash/coordinate-set.js +0 -3
  26. package/dist/data-structures/hash/hash-map.d.ts +8 -14
  27. package/dist/data-structures/hash/hash-map.js +4 -22
  28. package/dist/data-structures/hash/hash-table.d.ts +6 -9
  29. package/dist/data-structures/hash/hash-table.js +0 -9
  30. package/dist/data-structures/heap/heap.d.ts +12 -6
  31. package/dist/data-structures/heap/heap.js +40 -22
  32. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  33. package/dist/data-structures/linked-list/doubly-linked-list.js +18 -42
  34. package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  35. package/dist/data-structures/linked-list/singly-linked-list.js +17 -35
  36. package/dist/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  37. package/dist/data-structures/linked-list/skip-linked-list.js +62 -17
  38. package/dist/data-structures/matrix/matrix.d.ts +1 -1
  39. package/dist/data-structures/matrix/matrix2d.d.ts +1 -1
  40. package/dist/data-structures/matrix/navigator.d.ts +4 -4
  41. package/dist/data-structures/queue/deque.d.ts +8 -12
  42. package/dist/data-structures/queue/deque.js +31 -43
  43. package/dist/data-structures/queue/queue.d.ts +20 -5
  44. package/dist/data-structures/queue/queue.js +35 -18
  45. package/dist/data-structures/stack/stack.d.ts +2 -1
  46. package/dist/data-structures/stack/stack.js +10 -7
  47. package/dist/data-structures/tree/tree.d.ts +3 -9
  48. package/dist/data-structures/tree/tree.js +3 -21
  49. package/dist/data-structures/trie/trie.d.ts +6 -12
  50. package/dist/data-structures/trie/trie.js +6 -24
  51. package/dist/interfaces/binary-tree.d.ts +1 -1
  52. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  53. package/package.json +2 -2
  54. package/src/data-structures/binary-tree/avl-tree.ts +2 -4
  55. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
  56. package/src/data-structures/binary-tree/binary-tree.ts +17 -42
  57. package/src/data-structures/binary-tree/bst.ts +5 -6
  58. package/src/data-structures/binary-tree/rb-tree.ts +13 -21
  59. package/src/data-structures/binary-tree/segment-tree.ts +16 -83
  60. package/src/data-structures/binary-tree/tree-multiset.ts +8 -9
  61. package/src/data-structures/graph/abstract-graph.ts +21 -67
  62. package/src/data-structures/graph/directed-graph.ts +13 -39
  63. package/src/data-structures/graph/map-graph.ts +7 -32
  64. package/src/data-structures/graph/undirected-graph.ts +9 -26
  65. package/src/data-structures/hash/coordinate-map.ts +0 -4
  66. package/src/data-structures/hash/coordinate-set.ts +0 -4
  67. package/src/data-structures/hash/hash-map.ts +13 -37
  68. package/src/data-structures/hash/hash-table.ts +6 -18
  69. package/src/data-structures/hash/tree-map.ts +2 -1
  70. package/src/data-structures/hash/tree-set.ts +2 -1
  71. package/src/data-structures/heap/heap.ts +58 -30
  72. package/src/data-structures/heap/max-heap.ts +1 -1
  73. package/src/data-structures/heap/min-heap.ts +1 -1
  74. package/src/data-structures/linked-list/doubly-linked-list.ts +26 -60
  75. package/src/data-structures/linked-list/singly-linked-list.ts +24 -49
  76. package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
  77. package/src/data-structures/matrix/matrix.ts +2 -2
  78. package/src/data-structures/matrix/matrix2d.ts +1 -1
  79. package/src/data-structures/matrix/navigator.ts +4 -4
  80. package/src/data-structures/matrix/vector2d.ts +2 -1
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  83. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  84. package/src/data-structures/queue/deque.ts +38 -53
  85. package/src/data-structures/queue/queue.ts +38 -20
  86. package/src/data-structures/stack/stack.ts +13 -9
  87. package/src/data-structures/tree/tree.ts +7 -33
  88. package/src/data-structures/trie/trie.ts +14 -40
  89. package/src/interfaces/binary-tree.ts +1 -1
  90. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  91. package/src/types/data-structures/matrix/navigator.ts +1 -1
  92. package/src/types/utils/utils.ts +1 -1
  93. package/src/types/utils/validate-type.ts +2 -2
@@ -12,6 +12,9 @@ import {IGraph} from '../../interfaces';
12
12
  import {Queue} from '../queue';
13
13
 
14
14
  export abstract class AbstractVertex<V = any> {
15
+ key: VertexKey;
16
+ value: V | undefined;
17
+
15
18
  /**
16
19
  * The function is a protected constructor that takes an key and an optional value as parameters.
17
20
  * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
@@ -20,32 +23,16 @@ export abstract class AbstractVertex<V = any> {
20
23
  * vertex. If no value is provided, it will be set to undefined.
21
24
  */
22
25
  protected constructor(key: VertexKey, value?: V) {
23
- this._key = key;
24
- this._value = value;
25
- }
26
-
27
- private _key: VertexKey;
28
-
29
- get key(): VertexKey {
30
- return this._key;
31
- }
32
-
33
- set key(v: VertexKey) {
34
- this._key = v;
35
- }
36
-
37
- private _value: V | undefined;
38
-
39
- get value(): V | undefined {
40
- return this._value;
26
+ this.key = key;
27
+ this.value = value;
41
28
  }
42
29
 
43
- set value(value: V | undefined) {
44
- this._value = value;
45
- }
46
30
  }
47
31
 
48
32
  export abstract class AbstractEdge<E = any> {
33
+ value: E | undefined;
34
+ weight: number;
35
+
49
36
  /**
50
37
  * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
51
38
  * object.
@@ -56,31 +43,11 @@ export abstract class AbstractEdge<E = any> {
56
43
  * meaning it can be omitted when creating an instance of the class.
57
44
  */
58
45
  protected constructor(weight?: number, value?: E) {
59
- this._weight = weight !== undefined ? weight : 1;
60
- this._value = value;
46
+ this.weight = weight !== undefined ? weight : 1;
47
+ this.value = value;
61
48
  this._hashCode = uuidV4();
62
49
  }
63
50
 
64
- private _value: E | undefined;
65
-
66
- get value(): E | undefined {
67
- return this._value;
68
- }
69
-
70
- set value(value: E | undefined) {
71
- this._value = value;
72
- }
73
-
74
- private _weight: number;
75
-
76
- get weight(): number {
77
- return this._weight;
78
- }
79
-
80
- set weight(v: number) {
81
- this._weight = v;
82
- }
83
-
84
51
  protected _hashCode: string;
85
52
 
86
53
  get hashCode(): string {
@@ -91,15 +58,6 @@ export abstract class AbstractEdge<E = any> {
91
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.
92
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.
93
60
  */
94
-
95
- /**
96
- * The function sets the value of the _hashCode property to the provided string.
97
- * @param {string} v - The parameter "v" is of type string and represents the value that will be assigned to the
98
- * "_hashCode" property.
99
- */
100
- protected _setHashCode(v: string) {
101
- this._hashCode = v;
102
- }
103
61
  }
104
62
 
105
63
  export abstract class AbstractGraph<
@@ -107,9 +65,8 @@ export abstract class AbstractGraph<
107
65
  E = any,
108
66
  VO extends AbstractVertex<V> = AbstractVertex<V>,
109
67
  EO extends AbstractEdge<E> = AbstractEdge<E>
110
- > implements IGraph<V, E, VO, EO>
111
- {
112
- private _vertices: Map<VertexKey, VO> = new Map<VertexKey, VO>();
68
+ > implements IGraph<V, E, VO, EO> {
69
+ protected _vertices: Map<VertexKey, VO> = new Map<VertexKey, VO>();
113
70
 
114
71
  get vertices(): Map<VertexKey, VO> {
115
72
  return this._vertices;
@@ -556,14 +513,14 @@ export abstract class AbstractGraph<
556
513
  }
557
514
 
558
515
  getMinDist &&
559
- distMap.forEach((d, v) => {
560
- if (v !== srcVertex) {
561
- if (d < minDist) {
562
- minDist = d;
563
- if (genPaths) minDest = v;
564
- }
516
+ distMap.forEach((d, v) => {
517
+ if (v !== srcVertex) {
518
+ if (d < minDist) {
519
+ minDist = d;
520
+ if (genPaths) minDest = v;
565
521
  }
566
- });
522
+ }
523
+ });
567
524
 
568
525
  genPaths && getPaths(minDest);
569
526
 
@@ -625,7 +582,7 @@ export abstract class AbstractGraph<
625
582
  if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
626
583
  }
627
584
 
628
- const heap = new PriorityQueue<{key: number; value: VO}>({comparator: (a, b) => a.key - b.key});
585
+ const heap = new PriorityQueue<{ key: number; value: VO }>({comparator: (a, b) => a.key - b.key});
629
586
  heap.add({key: 0, value: srcVertex});
630
587
 
631
588
  distMap.set(srcVertex, 0);
@@ -854,7 +811,7 @@ export abstract class AbstractGraph<
854
811
  * `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
855
812
  * path between vertices in the
856
813
  */
857
- floyd(): {costs: number[][]; predecessor: (VO | null)[][]} {
814
+ floyd(): { costs: number[][]; predecessor: (VO | null)[][] } {
858
815
  const idAndVertices = [...this._vertices];
859
816
  const n = idAndVertices.length;
860
817
 
@@ -1040,7 +997,4 @@ export abstract class AbstractGraph<
1040
997
  return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
1041
998
  }
1042
999
 
1043
- protected _setVertices(value: Map<VertexKey, VO>) {
1044
- this._vertices = value;
1045
- }
1046
1000
  }
@@ -24,6 +24,9 @@ export class DirectedVertex<V = any> extends AbstractVertex<V> {
24
24
  }
25
25
 
26
26
  export class DirectedEdge<E = any> extends AbstractEdge<E> {
27
+ src: VertexKey;
28
+ dest: VertexKey;
29
+
27
30
  /**
28
31
  * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
29
32
  * and value.
@@ -37,40 +40,19 @@ export class DirectedEdge<E = any> extends AbstractEdge<E> {
37
40
  */
38
41
  constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E) {
39
42
  super(weight, value);
40
- this._src = src;
41
- this._dest = dest;
42
- }
43
-
44
- private _src: VertexKey;
45
-
46
- get src(): VertexKey {
47
- return this._src;
48
- }
49
-
50
- set src(v: VertexKey) {
51
- this._src = v;
52
- }
53
-
54
- private _dest: VertexKey;
55
-
56
- get dest(): VertexKey {
57
- return this._dest;
58
- }
59
-
60
- set dest(v: VertexKey) {
61
- this._dest = v;
43
+ this.src = src;
44
+ this.dest = dest;
62
45
  }
63
46
  }
64
47
 
65
48
  export class DirectedGraph<
66
- V = any,
67
- E = any,
68
- VO extends DirectedVertex<V> = DirectedVertex<V>,
69
- EO extends DirectedEdge<E> = DirectedEdge<E>
70
- >
49
+ V = any,
50
+ E = any,
51
+ VO extends DirectedVertex<V> = DirectedVertex<V>,
52
+ EO extends DirectedEdge<E> = DirectedEdge<E>
53
+ >
71
54
  extends AbstractGraph<V, E, VO, EO>
72
- implements IGraph<V, E, VO, EO>
73
- {
55
+ implements IGraph<V, E, VO, EO> {
74
56
  /**
75
57
  * The constructor function initializes an instance of a class.
76
58
  */
@@ -78,13 +60,13 @@ export class DirectedGraph<
78
60
  super();
79
61
  }
80
62
 
81
- private _outEdgeMap: Map<VO, EO[]> = new Map<VO, EO[]>();
63
+ protected _outEdgeMap: Map<VO, EO[]> = new Map<VO, EO[]>();
82
64
 
83
65
  get outEdgeMap(): Map<VO, EO[]> {
84
66
  return this._outEdgeMap;
85
67
  }
86
68
 
87
- private _inEdgeMap: Map<VO, EO[]> = new Map<VO, EO[]>();
69
+ protected _inEdgeMap: Map<VO, EO[]> = new Map<VO, EO[]>();
88
70
 
89
71
  get inEdgeMap(): Map<VO, EO[]> {
90
72
  return this._inEdgeMap;
@@ -464,12 +446,4 @@ export class DirectedGraph<
464
446
  return false;
465
447
  }
466
448
  }
467
-
468
- protected _setOutEdgeMap(value: Map<VO, EO[]>) {
469
- this._outEdgeMap = value;
470
- }
471
-
472
- protected _setInEdgeMap(value: Map<VO, EO[]>) {
473
- this._inEdgeMap = value;
474
- }
475
449
  }
@@ -2,6 +2,9 @@ import {MapGraphCoordinate, VertexKey} from '../../types';
2
2
  import {DirectedEdge, DirectedGraph, DirectedVertex} from './directed-graph';
3
3
 
4
4
  export class MapVertex<V = any> extends DirectedVertex<V> {
5
+ lat: number;
6
+ long: number;
7
+
5
8
  /**
6
9
  * The constructor function initializes an object with an key, latitude, longitude, and an optional value.
7
10
  * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
@@ -16,28 +19,8 @@ export class MapVertex<V = any> extends DirectedVertex<V> {
16
19
  */
17
20
  constructor(key: VertexKey, value: V, lat: number, long: number) {
18
21
  super(key, value);
19
- this._lat = lat;
20
- this._long = long;
21
- }
22
-
23
- private _lat: number;
24
-
25
- get lat(): number {
26
- return this._lat;
27
- }
28
-
29
- set lat(value: number) {
30
- this._lat = value;
31
- }
32
-
33
- private _long: number;
34
-
35
- get long(): number {
36
- return this._long;
37
- }
38
-
39
- set long(value: number) {
40
- this._long = value;
22
+ this.lat = lat;
23
+ this.long = long;
41
24
  }
42
25
  }
43
26
 
@@ -78,26 +61,18 @@ export class MapGraph<
78
61
  this._bottomRight = bottomRight;
79
62
  }
80
63
 
81
- private _origin: MapGraphCoordinate = [0, 0];
64
+ protected _origin: MapGraphCoordinate = [0, 0];
82
65
 
83
66
  get origin(): MapGraphCoordinate {
84
67
  return this._origin;
85
68
  }
86
69
 
87
- set origin(value: MapGraphCoordinate) {
88
- this._origin = value;
89
- }
90
-
91
- private _bottomRight: MapGraphCoordinate | undefined;
70
+ protected _bottomRight: MapGraphCoordinate | undefined;
92
71
 
93
72
  get bottomRight(): MapGraphCoordinate | undefined {
94
73
  return this._bottomRight;
95
74
  }
96
75
 
97
- set bottomRight(value: MapGraphCoordinate | undefined) {
98
- this._bottomRight = value;
99
- }
100
-
101
76
  /**
102
77
  * The function creates a new vertex with the given key, value, latitude, and longitude.
103
78
  * @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
@@ -24,6 +24,8 @@ export class UndirectedVertex<V = any> extends AbstractVertex<V> {
24
24
  }
25
25
 
26
26
  export class UndirectedEdge<E = number> extends AbstractEdge<E> {
27
+ vertices: [VertexKey, VertexKey];
28
+
27
29
  /**
28
30
  * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
29
31
  * value.
@@ -36,29 +38,18 @@ export class UndirectedEdge<E = number> extends AbstractEdge<E> {
36
38
  */
37
39
  constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E) {
38
40
  super(weight, value);
39
- this._vertices = [v1, v2];
40
- }
41
-
42
- private _vertices: [VertexKey, VertexKey];
43
-
44
- get vertices() {
45
- return this._vertices;
46
- }
47
-
48
- set vertices(v: [VertexKey, VertexKey]) {
49
- this._vertices = v;
41
+ this.vertices = [v1, v2];
50
42
  }
51
43
  }
52
44
 
53
45
  export class UndirectedGraph<
54
- V = any,
55
- E = any,
56
- VO extends UndirectedVertex<V> = UndirectedVertex<V>,
57
- EO extends UndirectedEdge<E> = UndirectedEdge<E>
58
- >
46
+ V = any,
47
+ E = any,
48
+ VO extends UndirectedVertex<V> = UndirectedVertex<V>,
49
+ EO extends UndirectedEdge<E> = UndirectedEdge<E>
50
+ >
59
51
  extends AbstractGraph<V, E, VO, EO>
60
- implements IGraph<V, E, VO, EO>
61
- {
52
+ implements IGraph<V, E, VO, EO> {
62
53
  /**
63
54
  * The constructor initializes a new Map object to store edges.
64
55
  */
@@ -265,12 +256,4 @@ export class UndirectedGraph<
265
256
  }
266
257
  return true;
267
258
  }
268
-
269
- /**
270
- * The function sets the edges of a graph.
271
- * @param v - A map where the keys are of type VO and the values are arrays of type EO.
272
- */
273
- protected _setEdges(v: Map<VO, EO[]>) {
274
- this._edges = v;
275
- }
276
259
  }
@@ -60,8 +60,4 @@ export class CoordinateMap<V> extends Map<any, V> {
60
60
  override delete(key: number[]) {
61
61
  return super.delete(key.join(this._joint));
62
62
  }
63
-
64
- protected _setJoint(v: string) {
65
- this._joint = v;
66
- }
67
63
  }
@@ -49,8 +49,4 @@ export class CoordinateSet extends Set<any> {
49
49
  override delete(value: number[]) {
50
50
  return super.delete(value.join(this._joint));
51
51
  }
52
-
53
- protected _setJoint(v: string) {
54
- this._joint = v;
55
- }
56
52
  }
@@ -38,66 +38,42 @@ export class HashMap<K, V> {
38
38
  });
39
39
  }
40
40
 
41
- private _initialCapacity: number;
41
+ protected _initialCapacity: number;
42
42
 
43
43
  get initialCapacity(): number {
44
44
  return this._initialCapacity;
45
45
  }
46
46
 
47
- set initialCapacity(value: number) {
48
- this._initialCapacity = value;
49
- }
50
-
51
- private _loadFactor: number;
47
+ protected _loadFactor: number;
52
48
 
53
49
  get loadFactor(): number {
54
50
  return this._loadFactor;
55
51
  }
56
52
 
57
- set loadFactor(value: number) {
58
- this._loadFactor = value;
59
- }
60
-
61
- private _capacityMultiplier: number;
53
+ protected _capacityMultiplier: number;
62
54
 
63
55
  get capacityMultiplier(): number {
64
56
  return this._capacityMultiplier;
65
57
  }
66
58
 
67
- set capacityMultiplier(value: number) {
68
- this._capacityMultiplier = value;
69
- }
70
-
71
- private _size: number;
59
+ protected _size: number;
72
60
 
73
61
  get size(): number {
74
62
  return this._size;
75
63
  }
76
64
 
77
- set size(value: number) {
78
- this._size = value;
79
- }
80
-
81
- private _table: Array<Array<[K, V]>>;
65
+ protected _table: Array<Array<[K, V]>>;
82
66
 
83
67
  get table(): Array<Array<[K, V]>> {
84
68
  return this._table;
85
69
  }
86
70
 
87
- set table(value: Array<Array<[K, V]>>) {
88
- this._table = value;
89
- }
90
-
91
- private _hashFn: HashFunction<K>;
71
+ protected _hashFn: HashFunction<K>;
92
72
 
93
73
  get hashFn(): HashFunction<K> {
94
74
  return this._hashFn;
95
75
  }
96
76
 
97
- set hashFn(value: HashFunction<K>) {
98
- this._hashFn = value;
99
- }
100
-
101
77
  set(key: K, value: V): void {
102
78
  const loadFactor = this.size / this.table.length;
103
79
  if (loadFactor >= this.loadFactor) {
@@ -118,7 +94,7 @@ export class HashMap<K, V> {
118
94
  }
119
95
 
120
96
  this.table[index].push([key, value]);
121
- this.size++;
97
+ this._size++;
122
98
  }
123
99
 
124
100
  get(key: K): V | undefined {
@@ -145,7 +121,7 @@ export class HashMap<K, V> {
145
121
  for (let i = 0; i < this.table[index].length; i++) {
146
122
  if (this.table[index][i][0] === key) {
147
123
  this.table[index].splice(i, 1);
148
- this.size--;
124
+ this._size--;
149
125
 
150
126
  // Check if the table needs to be resized down
151
127
  const loadFactor = this.size / this.table.length;
@@ -157,7 +133,7 @@ export class HashMap<K, V> {
157
133
  }
158
134
  }
159
135
 
160
- *entries(): IterableIterator<[K, V]> {
136
+ * entries(): IterableIterator<[K, V]> {
161
137
  for (const bucket of this.table) {
162
138
  if (bucket) {
163
139
  for (const [key, value] of bucket) {
@@ -172,15 +148,15 @@ export class HashMap<K, V> {
172
148
  }
173
149
 
174
150
  clear(): void {
175
- this.size = 0;
176
- this.table = new Array(this.initialCapacity);
151
+ this._size = 0;
152
+ this._table = new Array(this.initialCapacity);
177
153
  }
178
154
 
179
155
  isEmpty(): boolean {
180
156
  return this.size === 0;
181
157
  }
182
158
 
183
- private _hash(key: K): number {
159
+ protected _hash(key: K): number {
184
160
  return this._hashFn(key);
185
161
  }
186
162
 
@@ -190,7 +166,7 @@ export class HashMap<K, V> {
190
166
  * @param {number} newCapacity - The newCapacity parameter is the desired capacity for the resized table. It represents
191
167
  * the number of buckets that the new table should have.
192
168
  */
193
- private resizeTable(newCapacity: number): void {
169
+ protected resizeTable(newCapacity: number): void {
194
170
  const newTable = new Array(newCapacity);
195
171
  for (const bucket of this._table) {
196
172
  // Note that this is this._table
@@ -21,8 +21,8 @@ export class HashTableNode<K, V> {
21
21
  import {HashFunction} from '../../types';
22
22
 
23
23
  export class HashTable<K, V> {
24
- private static readonly DEFAULT_CAPACITY = 16;
25
- private static readonly LOAD_FACTOR = 0.75;
24
+ protected static readonly DEFAULT_CAPACITY = 16;
25
+ protected static readonly LOAD_FACTOR = 0.75;
26
26
 
27
27
  constructor(capacity: number = HashTable.DEFAULT_CAPACITY, hashFn?: HashFunction<K>) {
28
28
  this._hashFn = hashFn || this._defaultHashFn;
@@ -31,42 +31,30 @@ export class HashTable<K, V> {
31
31
  this._buckets = new Array<HashTableNode<K, V> | null>(this._capacity).fill(null);
32
32
  }
33
33
 
34
- private _capacity: number;
34
+ protected _capacity: number;
35
35
 
36
36
  get capacity(): number {
37
37
  return this._capacity;
38
38
  }
39
39
 
40
- set capacity(value: number) {
41
- this._capacity = value;
42
- }
43
-
44
- private _size: number;
40
+ protected _size: number;
45
41
 
46
42
  get size(): number {
47
43
  return this._size;
48
44
  }
49
45
 
50
- private _buckets: Array<HashTableNode<K, V> | null>;
46
+ protected _buckets: Array<HashTableNode<K, V> | null>;
51
47
 
52
48
  get buckets(): Array<HashTableNode<K, V> | null> {
53
49
  return this._buckets;
54
50
  }
55
51
 
56
- set buckets(value: Array<HashTableNode<K, V> | null>) {
57
- this._buckets = value;
58
- }
59
-
60
- private _hashFn: HashFunction<K>;
52
+ protected _hashFn: HashFunction<K>;
61
53
 
62
54
  get hashFn(): HashFunction<K> {
63
55
  return this._hashFn;
64
56
  }
65
57
 
66
- set hashFn(value: HashFunction<K>) {
67
- this._hashFn = value;
68
- }
69
-
70
58
  /**
71
59
  * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
72
60
  * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
@@ -1 +1,2 @@
1
- export class TreeMap {}
1
+ export class TreeMap {
2
+ }
@@ -1 +1,2 @@
1
- export class TreeSet {}
1
+ export class TreeSet {
2
+ }