data-structure-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 (193) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -1
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  4. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  5. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  6. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +5 -20
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -29
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
  12. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +1 -3
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js +1 -7
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +10 -26
  17. package/dist/cjs/data-structures/binary-tree/segment-tree.js +10 -58
  18. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  19. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +6 -6
  21. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  22. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +5 -24
  23. package/dist/cjs/data-structures/graph/abstract-graph.js +4 -43
  24. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  25. package/dist/cjs/data-structures/graph/directed-graph.d.ts +4 -10
  26. package/dist/cjs/data-structures/graph/directed-graph.js +2 -20
  27. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/map-graph.d.ts +4 -10
  29. package/dist/cjs/data-structures/graph/map-graph.js +2 -20
  30. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  31. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -8
  32. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -14
  33. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  34. package/dist/cjs/data-structures/hash/coordinate-map.d.ts +0 -1
  35. package/dist/cjs/data-structures/hash/coordinate-map.js +0 -3
  36. package/dist/cjs/data-structures/hash/coordinate-map.js.map +1 -1
  37. package/dist/cjs/data-structures/hash/coordinate-set.d.ts +0 -1
  38. package/dist/cjs/data-structures/hash/coordinate-set.js +0 -3
  39. package/dist/cjs/data-structures/hash/coordinate-set.js.map +1 -1
  40. package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -14
  41. package/dist/cjs/data-structures/hash/hash-map.js +4 -22
  42. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  43. package/dist/cjs/data-structures/hash/hash-table.d.ts +6 -9
  44. package/dist/cjs/data-structures/hash/hash-table.js +0 -9
  45. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  46. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  47. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  48. package/dist/cjs/data-structures/heap/heap.d.ts +12 -6
  49. package/dist/cjs/data-structures/heap/heap.js +40 -22
  50. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  51. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  52. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  54. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +18 -42
  55. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  56. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  57. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +17 -35
  58. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  59. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  60. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +62 -17
  61. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  62. package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
  63. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  64. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -1
  65. package/dist/cjs/data-structures/matrix/navigator.d.ts +4 -4
  66. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  67. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  68. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  69. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  70. package/dist/cjs/data-structures/queue/deque.d.ts +8 -12
  71. package/dist/cjs/data-structures/queue/deque.js +31 -43
  72. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  73. package/dist/cjs/data-structures/queue/queue.d.ts +20 -5
  74. package/dist/cjs/data-structures/queue/queue.js +35 -18
  75. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  76. package/dist/cjs/data-structures/stack/stack.d.ts +2 -1
  77. package/dist/cjs/data-structures/stack/stack.js +10 -7
  78. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  79. package/dist/cjs/data-structures/tree/tree.d.ts +3 -9
  80. package/dist/cjs/data-structures/tree/tree.js +3 -21
  81. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  82. package/dist/cjs/data-structures/trie/trie.d.ts +6 -12
  83. package/dist/cjs/data-structures/trie/trie.js +6 -24
  84. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  85. package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
  86. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  87. package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -1
  88. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  89. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  90. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -20
  91. package/dist/mjs/data-structures/binary-tree/binary-tree.js +8 -29
  92. package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -1
  93. package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
  94. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +1 -3
  95. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -8
  96. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +10 -26
  97. package/dist/mjs/data-structures/binary-tree/segment-tree.js +10 -58
  98. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  99. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +6 -6
  100. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +5 -24
  101. package/dist/mjs/data-structures/graph/abstract-graph.js +8 -47
  102. package/dist/mjs/data-structures/graph/directed-graph.d.ts +4 -10
  103. package/dist/mjs/data-structures/graph/directed-graph.js +4 -22
  104. package/dist/mjs/data-structures/graph/map-graph.d.ts +4 -10
  105. package/dist/mjs/data-structures/graph/map-graph.js +4 -22
  106. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -8
  107. package/dist/mjs/data-structures/graph/undirected-graph.js +2 -15
  108. package/dist/mjs/data-structures/hash/coordinate-map.d.ts +0 -1
  109. package/dist/mjs/data-structures/hash/coordinate-map.js +0 -3
  110. package/dist/mjs/data-structures/hash/coordinate-set.d.ts +0 -1
  111. package/dist/mjs/data-structures/hash/coordinate-set.js +0 -3
  112. package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -14
  113. package/dist/mjs/data-structures/hash/hash-map.js +4 -22
  114. package/dist/mjs/data-structures/hash/hash-table.d.ts +6 -9
  115. package/dist/mjs/data-structures/hash/hash-table.js +0 -9
  116. package/dist/mjs/data-structures/heap/heap.d.ts +12 -6
  117. package/dist/mjs/data-structures/heap/heap.js +44 -26
  118. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  119. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +21 -45
  120. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  121. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +19 -37
  122. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  123. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +62 -17
  124. package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
  125. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -1
  126. package/dist/mjs/data-structures/matrix/navigator.d.ts +4 -4
  127. package/dist/mjs/data-structures/queue/deque.d.ts +8 -12
  128. package/dist/mjs/data-structures/queue/deque.js +31 -43
  129. package/dist/mjs/data-structures/queue/queue.d.ts +20 -5
  130. package/dist/mjs/data-structures/queue/queue.js +34 -17
  131. package/dist/mjs/data-structures/stack/stack.d.ts +2 -1
  132. package/dist/mjs/data-structures/stack/stack.js +11 -8
  133. package/dist/mjs/data-structures/tree/tree.d.ts +3 -9
  134. package/dist/mjs/data-structures/tree/tree.js +6 -24
  135. package/dist/mjs/data-structures/trie/trie.d.ts +6 -12
  136. package/dist/mjs/data-structures/trie/trie.js +10 -28
  137. package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
  138. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  139. package/dist/umd/data-structure-typed.min.js +1 -1
  140. package/dist/umd/data-structure-typed.min.js.map +1 -1
  141. package/package.json +5 -5
  142. package/src/data-structures/binary-tree/avl-tree.ts +2 -4
  143. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
  144. package/src/data-structures/binary-tree/binary-tree.ts +17 -42
  145. package/src/data-structures/binary-tree/bst.ts +5 -6
  146. package/src/data-structures/binary-tree/rb-tree.ts +13 -21
  147. package/src/data-structures/binary-tree/segment-tree.ts +16 -83
  148. package/src/data-structures/binary-tree/tree-multiset.ts +8 -9
  149. package/src/data-structures/graph/abstract-graph.ts +21 -67
  150. package/src/data-structures/graph/directed-graph.ts +13 -39
  151. package/src/data-structures/graph/map-graph.ts +7 -32
  152. package/src/data-structures/graph/undirected-graph.ts +9 -26
  153. package/src/data-structures/hash/coordinate-map.ts +0 -4
  154. package/src/data-structures/hash/coordinate-set.ts +0 -4
  155. package/src/data-structures/hash/hash-map.ts +13 -37
  156. package/src/data-structures/hash/hash-table.ts +6 -18
  157. package/src/data-structures/hash/tree-map.ts +2 -1
  158. package/src/data-structures/hash/tree-set.ts +2 -1
  159. package/src/data-structures/heap/heap.ts +58 -30
  160. package/src/data-structures/heap/max-heap.ts +1 -1
  161. package/src/data-structures/heap/min-heap.ts +1 -1
  162. package/src/data-structures/linked-list/doubly-linked-list.ts +26 -60
  163. package/src/data-structures/linked-list/singly-linked-list.ts +24 -49
  164. package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
  165. package/src/data-structures/matrix/matrix.ts +2 -2
  166. package/src/data-structures/matrix/matrix2d.ts +1 -1
  167. package/src/data-structures/matrix/navigator.ts +4 -4
  168. package/src/data-structures/matrix/vector2d.ts +2 -1
  169. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  170. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  171. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  172. package/src/data-structures/queue/deque.ts +38 -53
  173. package/src/data-structures/queue/queue.ts +38 -20
  174. package/src/data-structures/stack/stack.ts +13 -9
  175. package/src/data-structures/tree/tree.ts +7 -33
  176. package/src/data-structures/trie/trie.ts +14 -40
  177. package/src/interfaces/binary-tree.ts +1 -1
  178. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  179. package/src/types/data-structures/matrix/navigator.ts +1 -1
  180. package/src/types/utils/utils.ts +1 -1
  181. package/src/types/utils/validate-type.ts +2 -2
  182. package/test/integration/avl-tree.test.ts +1 -1
  183. package/test/integration/bst.test.ts +2 -2
  184. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +2 -2
  185. package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -6
  186. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  187. package/test/unit/data-structures/graph/map-graph.test.ts +2 -2
  188. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  189. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  190. package/test/unit/data-structures/hash/hash-map.test.ts +0 -1
  191. package/test/unit/data-structures/hash/hash-table.test.ts +3 -3
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +31 -0
  193. package/test/unit/data-structures/queue/queue.test.ts +8 -8
@@ -48,8 +48,5 @@ class CoordinateSet extends Set {
48
48
  delete(value) {
49
49
  return super.delete(value.join(this._joint));
50
50
  }
51
- _setJoint(v) {
52
- this._joint = v;
53
- }
54
51
  }
55
52
  exports.CoordinateSet = CoordinateSet;
@@ -20,24 +20,18 @@ export declare class HashMap<K, V> {
20
20
  * default hash function converts the key to a string, calculates the sum of the
21
21
  */
22
22
  constructor(initialCapacity?: number, loadFactor?: number, hashFn?: HashFunction<K>);
23
- private _initialCapacity;
23
+ protected _initialCapacity: number;
24
24
  get initialCapacity(): number;
25
- set initialCapacity(value: number);
26
- private _loadFactor;
25
+ protected _loadFactor: number;
27
26
  get loadFactor(): number;
28
- set loadFactor(value: number);
29
- private _capacityMultiplier;
27
+ protected _capacityMultiplier: number;
30
28
  get capacityMultiplier(): number;
31
- set capacityMultiplier(value: number);
32
- private _size;
29
+ protected _size: number;
33
30
  get size(): number;
34
- set size(value: number);
35
- private _table;
31
+ protected _table: Array<Array<[K, V]>>;
36
32
  get table(): Array<Array<[K, V]>>;
37
- set table(value: Array<Array<[K, V]>>);
38
- private _hashFn;
33
+ protected _hashFn: HashFunction<K>;
39
34
  get hashFn(): HashFunction<K>;
40
- set hashFn(value: HashFunction<K>);
41
35
  set(key: K, value: V): void;
42
36
  get(key: K): V | undefined;
43
37
  delete(key: K): void;
@@ -45,12 +39,12 @@ export declare class HashMap<K, V> {
45
39
  [Symbol.iterator](): IterableIterator<[K, V]>;
46
40
  clear(): void;
47
41
  isEmpty(): boolean;
48
- private _hash;
42
+ protected _hash(key: K): number;
49
43
  /**
50
44
  * The `resizeTable` function resizes the table used in a hash map by creating a new table with a specified capacity and
51
45
  * rehashing the key-value pairs from the old table into the new table.
52
46
  * @param {number} newCapacity - The newCapacity parameter is the desired capacity for the resized table. It represents
53
47
  * the number of buckets that the new table should have.
54
48
  */
55
- private resizeTable;
49
+ protected resizeTable(newCapacity: number): void;
56
50
  }
@@ -42,44 +42,26 @@ class HashMap {
42
42
  get initialCapacity() {
43
43
  return this._initialCapacity;
44
44
  }
45
- set initialCapacity(value) {
46
- this._initialCapacity = value;
47
- }
48
45
  _loadFactor;
49
46
  get loadFactor() {
50
47
  return this._loadFactor;
51
48
  }
52
- set loadFactor(value) {
53
- this._loadFactor = value;
54
- }
55
49
  _capacityMultiplier;
56
50
  get capacityMultiplier() {
57
51
  return this._capacityMultiplier;
58
52
  }
59
- set capacityMultiplier(value) {
60
- this._capacityMultiplier = value;
61
- }
62
53
  _size;
63
54
  get size() {
64
55
  return this._size;
65
56
  }
66
- set size(value) {
67
- this._size = value;
68
- }
69
57
  _table;
70
58
  get table() {
71
59
  return this._table;
72
60
  }
73
- set table(value) {
74
- this._table = value;
75
- }
76
61
  _hashFn;
77
62
  get hashFn() {
78
63
  return this._hashFn;
79
64
  }
80
- set hashFn(value) {
81
- this._hashFn = value;
82
- }
83
65
  set(key, value) {
84
66
  const loadFactor = this.size / this.table.length;
85
67
  if (loadFactor >= this.loadFactor) {
@@ -97,7 +79,7 @@ class HashMap {
97
79
  }
98
80
  }
99
81
  this.table[index].push([key, value]);
100
- this.size++;
82
+ this._size++;
101
83
  }
102
84
  get(key) {
103
85
  const index = this._hash(key);
@@ -119,7 +101,7 @@ class HashMap {
119
101
  for (let i = 0; i < this.table[index].length; i++) {
120
102
  if (this.table[index][i][0] === key) {
121
103
  this.table[index].splice(i, 1);
122
- this.size--;
104
+ this._size--;
123
105
  // Check if the table needs to be resized down
124
106
  const loadFactor = this.size / this.table.length;
125
107
  if (loadFactor < this.loadFactor / this.capacityMultiplier) {
@@ -142,8 +124,8 @@ class HashMap {
142
124
  return this.entries();
143
125
  }
144
126
  clear() {
145
- this.size = 0;
146
- this.table = new Array(this.initialCapacity);
127
+ this._size = 0;
128
+ this._table = new Array(this.initialCapacity);
147
129
  }
148
130
  isEmpty() {
149
131
  return this.size === 0;
@@ -13,20 +13,17 @@ export declare class HashTableNode<K, V> {
13
13
  }
14
14
  import { HashFunction } from '../../types';
15
15
  export declare class HashTable<K, V> {
16
- private static readonly DEFAULT_CAPACITY;
17
- private static readonly LOAD_FACTOR;
16
+ protected static readonly DEFAULT_CAPACITY = 16;
17
+ protected static readonly LOAD_FACTOR = 0.75;
18
18
  constructor(capacity?: number, hashFn?: HashFunction<K>);
19
- private _capacity;
19
+ protected _capacity: number;
20
20
  get capacity(): number;
21
- set capacity(value: number);
22
- private _size;
21
+ protected _size: number;
23
22
  get size(): number;
24
- private _buckets;
23
+ protected _buckets: Array<HashTableNode<K, V> | null>;
25
24
  get buckets(): Array<HashTableNode<K, V> | null>;
26
- set buckets(value: Array<HashTableNode<K, V> | null>);
27
- private _hashFn;
25
+ protected _hashFn: HashFunction<K>;
28
26
  get hashFn(): HashFunction<K>;
29
- set hashFn(value: HashFunction<K>);
30
27
  /**
31
28
  * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
32
29
  * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
@@ -32,9 +32,6 @@ class HashTable {
32
32
  get capacity() {
33
33
  return this._capacity;
34
34
  }
35
- set capacity(value) {
36
- this._capacity = value;
37
- }
38
35
  _size;
39
36
  get size() {
40
37
  return this._size;
@@ -43,16 +40,10 @@ class HashTable {
43
40
  get buckets() {
44
41
  return this._buckets;
45
42
  }
46
- set buckets(value) {
47
- this._buckets = value;
48
- }
49
43
  _hashFn;
50
44
  get hashFn() {
51
45
  return this._hashFn;
52
46
  }
53
- set hashFn(value) {
54
- this._hashFn = value;
55
- }
56
47
  /**
57
48
  * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
58
49
  * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
@@ -6,12 +6,14 @@
6
6
  */
7
7
  import type { Comparator, DFSOrderPattern } from '../../types';
8
8
  export declare class Heap<E = any> {
9
- protected nodes: E[];
10
- protected readonly comparator: Comparator<E>;
11
9
  constructor(options: {
12
10
  comparator: Comparator<E>;
13
11
  nodes?: E[];
14
12
  });
13
+ protected _nodes: E[];
14
+ get nodes(): E[];
15
+ protected _comparator: Comparator<E>;
16
+ get comparator(): Comparator<E>;
15
17
  /**
16
18
  * Get the size (number of elements) of the heap.
17
19
  */
@@ -123,11 +125,15 @@ export declare class FibonacciHeapNode<E> {
123
125
  constructor(element: E, degree?: number);
124
126
  }
125
127
  export declare class FibonacciHeap<E> {
126
- root?: FibonacciHeapNode<E>;
127
- size: number;
128
- protected min?: FibonacciHeapNode<E>;
129
- protected readonly comparator: Comparator<E>;
130
128
  constructor(comparator?: Comparator<E>);
129
+ protected _root?: FibonacciHeapNode<E>;
130
+ get root(): FibonacciHeapNode<E> | undefined;
131
+ protected _size: number;
132
+ get size(): number;
133
+ protected _min?: FibonacciHeapNode<E>;
134
+ get min(): FibonacciHeapNode<E> | undefined;
135
+ protected _comparator: Comparator<E>;
136
+ get comparator(): Comparator<E>;
131
137
  /**
132
138
  * Get the size (number of elements) of the heap.
133
139
  * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
@@ -8,15 +8,21 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.FibonacciHeap = exports.FibonacciHeapNode = exports.Heap = void 0;
10
10
  class Heap {
11
- nodes = [];
12
- comparator;
13
11
  constructor(options) {
14
- this.comparator = options.comparator;
12
+ this._comparator = options.comparator;
15
13
  if (options.nodes && options.nodes.length > 0) {
16
- this.nodes = options.nodes;
14
+ this._nodes = options.nodes;
17
15
  this.fix();
18
16
  }
19
17
  }
18
+ _nodes = [];
19
+ get nodes() {
20
+ return this._nodes;
21
+ }
22
+ _comparator;
23
+ get comparator() {
24
+ return this._comparator;
25
+ }
20
26
  /**
21
27
  * Get the size (number of elements) of the heap.
22
28
  */
@@ -98,14 +104,14 @@ class Heap {
98
104
  * Reset the nodes of the heap. Make the nodes empty.
99
105
  */
100
106
  clear() {
101
- this.nodes = [];
107
+ this._nodes = [];
102
108
  }
103
109
  /**
104
110
  * Clear and add nodes of the heap
105
111
  * @param nodes
106
112
  */
107
113
  refill(nodes) {
108
- this.nodes = nodes;
114
+ this._nodes = nodes;
109
115
  this.fix();
110
116
  }
111
117
  /**
@@ -162,7 +168,7 @@ class Heap {
162
168
  */
163
169
  clone() {
164
170
  const clonedHeap = new Heap({ comparator: this.comparator });
165
- clonedHeap.nodes = [...this.nodes];
171
+ clonedHeap._nodes = [...this.nodes];
166
172
  return clonedHeap;
167
173
  }
168
174
  /**
@@ -245,25 +251,37 @@ class FibonacciHeapNode {
245
251
  }
246
252
  exports.FibonacciHeapNode = FibonacciHeapNode;
247
253
  class FibonacciHeap {
248
- root;
249
- size = 0;
250
- min;
251
- comparator;
252
254
  constructor(comparator) {
253
255
  this.clear();
254
- this.comparator = comparator || this.defaultComparator;
256
+ this._comparator = comparator || this.defaultComparator;
255
257
  if (typeof this.comparator !== 'function') {
256
258
  throw new Error('FibonacciHeap constructor: given comparator should be a function.');
257
259
  }
258
260
  }
261
+ _root;
262
+ get root() {
263
+ return this._root;
264
+ }
265
+ _size = 0;
266
+ get size() {
267
+ return this._size;
268
+ }
269
+ _min;
270
+ get min() {
271
+ return this._min;
272
+ }
273
+ _comparator;
274
+ get comparator() {
275
+ return this._comparator;
276
+ }
259
277
  /**
260
278
  * Get the size (number of elements) of the heap.
261
279
  * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
262
280
  */
263
281
  clear() {
264
- this.root = undefined;
265
- this.min = undefined;
266
- this.size = 0;
282
+ this._root = undefined;
283
+ this._min = undefined;
284
+ this._size = 0;
267
285
  }
268
286
  /**
269
287
  * O(1) time operation.
@@ -286,9 +304,9 @@ class FibonacciHeap {
286
304
  node.right = node;
287
305
  this.mergeWithRoot(node);
288
306
  if (!this.min || this.comparator(node.element, this.min.element) <= 0) {
289
- this.min = node;
307
+ this._min = node;
290
308
  }
291
- this.size++;
309
+ this._size++;
292
310
  return this;
293
311
  }
294
312
  /**
@@ -368,14 +386,14 @@ class FibonacciHeap {
368
386
  }
369
387
  this.removeFromRoot(z);
370
388
  if (z === z.right) {
371
- this.min = undefined;
372
- this.root = undefined;
389
+ this._min = undefined;
390
+ this._root = undefined;
373
391
  }
374
392
  else {
375
- this.min = z.right;
393
+ this._min = z.right;
376
394
  this.consolidate();
377
395
  }
378
- this.size--;
396
+ this._size--;
379
397
  return z.element;
380
398
  }
381
399
  /**
@@ -400,10 +418,10 @@ class FibonacciHeap {
400
418
  }
401
419
  // Update the minimum node
402
420
  if (!this.min || (heapToMerge.min && this.comparator(heapToMerge.min.element, this.min.element) < 0)) {
403
- this.min = heapToMerge.min;
421
+ this._min = heapToMerge.min;
404
422
  }
405
423
  // Update the size
406
- this.size += heapToMerge.size;
424
+ this._size += heapToMerge.size;
407
425
  // Clear the heap that was merged
408
426
  heapToMerge.clear();
409
427
  }
@@ -434,7 +452,7 @@ class FibonacciHeap {
434
452
  */
435
453
  mergeWithRoot(node) {
436
454
  if (!this.root) {
437
- this.root = node;
455
+ this._root = node;
438
456
  }
439
457
  else {
440
458
  node.right = this.root.right;
@@ -451,7 +469,7 @@ class FibonacciHeap {
451
469
  */
452
470
  removeFromRoot(node) {
453
471
  if (this.root === node)
454
- this.root = node.right;
472
+ this._root = node.right;
455
473
  if (node.left)
456
474
  node.left.right = node.right;
457
475
  if (node.right)
@@ -499,7 +517,7 @@ class FibonacciHeap {
499
517
  }
500
518
  for (let i = 0; i < this.size; i++) {
501
519
  if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
502
- this.min = A[i];
520
+ this._min = A[i];
503
521
  }
504
522
  }
505
523
  }
@@ -6,34 +6,26 @@
6
6
  * @license MIT License
7
7
  */
8
8
  export declare class DoublyLinkedListNode<E = any> {
9
+ value: E;
10
+ next: DoublyLinkedListNode<E> | null;
11
+ prev: DoublyLinkedListNode<E> | null;
9
12
  /**
10
13
  * The constructor function initializes the value, next, and previous properties of an object.
11
14
  * @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
12
15
  * is defined as a generic type "E".
13
16
  */
14
17
  constructor(value: E);
15
- private _value;
16
- get value(): E;
17
- set value(value: E);
18
- private _next;
19
- get next(): DoublyLinkedListNode<E> | null;
20
- set next(value: DoublyLinkedListNode<E> | null);
21
- private _prev;
22
- get prev(): DoublyLinkedListNode<E> | null;
23
- set prev(value: DoublyLinkedListNode<E> | null);
24
18
  }
25
19
  export declare class DoublyLinkedList<E = any> {
26
20
  /**
27
21
  * The constructor initializes the linked list with an empty head, tail, and length.
28
22
  */
29
23
  constructor();
30
- private _head;
24
+ protected _head: DoublyLinkedListNode<E> | null;
31
25
  get head(): DoublyLinkedListNode<E> | null;
32
- set head(value: DoublyLinkedListNode<E> | null);
33
- private _tail;
26
+ protected _tail: DoublyLinkedListNode<E> | null;
34
27
  get tail(): DoublyLinkedListNode<E> | null;
35
- set tail(value: DoublyLinkedListNode<E> | null);
36
- private _length;
28
+ protected _length: number;
37
29
  get length(): number;
38
30
  get size(): number;
39
31
  /**
@@ -9,36 +9,18 @@ exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
9
9
  * @license MIT License
10
10
  */
11
11
  class DoublyLinkedListNode {
12
+ value;
13
+ next;
14
+ prev;
12
15
  /**
13
16
  * The constructor function initializes the value, next, and previous properties of an object.
14
17
  * @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
15
18
  * is defined as a generic type "E".
16
19
  */
17
20
  constructor(value) {
18
- this._value = value;
19
- this._next = null;
20
- this._prev = null;
21
- }
22
- _value;
23
- get value() {
24
- return this._value;
25
- }
26
- set value(value) {
27
- this._value = value;
28
- }
29
- _next;
30
- get next() {
31
- return this._next;
32
- }
33
- set next(value) {
34
- this._next = value;
35
- }
36
- _prev;
37
- get prev() {
38
- return this._prev;
39
- }
40
- set prev(value) {
41
- this._prev = value;
21
+ this.value = value;
22
+ this.next = null;
23
+ this.prev = null;
42
24
  }
43
25
  }
44
26
  exports.DoublyLinkedListNode = DoublyLinkedListNode;
@@ -55,16 +37,10 @@ class DoublyLinkedList {
55
37
  get head() {
56
38
  return this._head;
57
39
  }
58
- set head(value) {
59
- this._head = value;
60
- }
61
40
  _tail;
62
41
  get tail() {
63
42
  return this._tail;
64
43
  }
65
- set tail(value) {
66
- this._tail = value;
67
- }
68
44
  _length;
69
45
  get length() {
70
46
  return this._length;
@@ -92,13 +68,13 @@ class DoublyLinkedList {
92
68
  push(value) {
93
69
  const newNode = new DoublyLinkedListNode(value);
94
70
  if (!this.head) {
95
- this.head = newNode;
96
- this.tail = newNode;
71
+ this._head = newNode;
72
+ this._tail = newNode;
97
73
  }
98
74
  else {
99
75
  newNode.prev = this.tail;
100
76
  this.tail.next = newNode;
101
- this.tail = newNode;
77
+ this._tail = newNode;
102
78
  }
103
79
  this._length++;
104
80
  }
@@ -119,11 +95,11 @@ class DoublyLinkedList {
119
95
  return undefined;
120
96
  const removedNode = this.tail;
121
97
  if (this.head === this.tail) {
122
- this.head = null;
123
- this.tail = null;
98
+ this._head = null;
99
+ this._tail = null;
124
100
  }
125
101
  else {
126
- this.tail = removedNode.prev;
102
+ this._tail = removedNode.prev;
127
103
  this.tail.next = null;
128
104
  }
129
105
  this._length--;
@@ -147,11 +123,11 @@ class DoublyLinkedList {
147
123
  return undefined;
148
124
  const removedNode = this.head;
149
125
  if (this.head === this.tail) {
150
- this.head = null;
151
- this.tail = null;
126
+ this._head = null;
127
+ this._tail = null;
152
128
  }
153
129
  else {
154
- this.head = removedNode.next;
130
+ this._head = removedNode.next;
155
131
  this.head.prev = null;
156
132
  }
157
133
  this._length--;
@@ -173,13 +149,13 @@ class DoublyLinkedList {
173
149
  unshift(value) {
174
150
  const newNode = new DoublyLinkedListNode(value);
175
151
  if (!this.head) {
176
- this.head = newNode;
177
- this.tail = newNode;
152
+ this._head = newNode;
153
+ this._tail = newNode;
178
154
  }
179
155
  else {
180
156
  newNode.next = this.head;
181
157
  this.head.prev = newNode;
182
- this.head = newNode;
158
+ this._head = newNode;
183
159
  }
184
160
  this._length++;
185
161
  }
@@ -312,7 +288,7 @@ class DoublyLinkedList {
312
288
  newNode.next = existingNode;
313
289
  existingNode.prev = newNode;
314
290
  if (existingNode === this.head) {
315
- this.head = newNode;
291
+ this._head = newNode;
316
292
  }
317
293
  this._length++;
318
294
  return true;
@@ -474,7 +450,7 @@ class DoublyLinkedList {
474
450
  */
475
451
  reverse() {
476
452
  let current = this.head;
477
- [this.head, this.tail] = [this.tail, this.head];
453
+ [this._head, this._tail] = [this.tail, this.head];
478
454
  while (current) {
479
455
  const next = current.next;
480
456
  [current.prev, current.next] = [current.next, current.prev];
@@ -576,7 +552,7 @@ class DoublyLinkedList {
576
552
  newNode.prev = existingNode;
577
553
  existingNode.next = newNode;
578
554
  if (existingNode === this.tail) {
579
- this.tail = newNode;
555
+ this._tail = newNode;
580
556
  }
581
557
  this._length++;
582
558
  return true;
@@ -6,31 +6,25 @@
6
6
  * @license MIT License
7
7
  */
8
8
  export declare class SinglyLinkedListNode<E = any> {
9
+ value: E;
10
+ next: SinglyLinkedListNode<E> | null;
9
11
  /**
10
12
  * The constructor function initializes an instance of a class with a given value and sets the next property to null.
11
13
  * @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
12
14
  * will be stored in the node of a linked list.
13
15
  */
14
16
  constructor(value: E);
15
- private _value;
16
- get value(): E;
17
- set value(value: E);
18
- private _next;
19
- get next(): SinglyLinkedListNode<E> | null;
20
- set next(value: SinglyLinkedListNode<E> | null);
21
17
  }
22
18
  export declare class SinglyLinkedList<E = any> {
23
19
  /**
24
20
  * The constructor initializes the linked list with an empty head, tail, and length.
25
21
  */
26
22
  constructor();
27
- private _head;
23
+ protected _head: SinglyLinkedListNode<E> | null;
28
24
  get head(): SinglyLinkedListNode<E> | null;
29
- set head(value: SinglyLinkedListNode<E> | null);
30
- private _tail;
25
+ protected _tail: SinglyLinkedListNode<E> | null;
31
26
  get tail(): SinglyLinkedListNode<E> | null;
32
- set tail(value: SinglyLinkedListNode<E> | null);
33
- private _length;
27
+ protected _length: number;
34
28
  get length(): number;
35
29
  /**
36
30
  * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given