data-structure-typed 1.35.0 → 1.40.0-rc

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 (173) hide show
  1. package/.github/workflows/ci.yml +3 -0
  2. package/CHANGELOG.md +3 -1
  3. package/CONTRIBUTING.md +18 -0
  4. package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  8. package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
  9. package/dist/data-structures/binary-tree/avl-tree.js +90 -3
  10. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
  13. package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  15. package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
  16. package/dist/data-structures/binary-tree/binary-tree.js +21 -0
  17. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  18. package/dist/data-structures/binary-tree/bst.d.ts +133 -0
  19. package/dist/data-structures/binary-tree/bst.js +114 -0
  20. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  21. package/dist/data-structures/binary-tree/index.d.ts +12 -0
  22. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
  23. package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
  24. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  25. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
  26. package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
  27. package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
  28. package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
  29. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  30. package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
  31. package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
  32. package/dist/data-structures/graph/abstract-graph.js +269 -4
  33. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  34. package/dist/data-structures/graph/directed-graph.d.ts +200 -0
  35. package/dist/data-structures/graph/directed-graph.js +167 -0
  36. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  37. package/dist/data-structures/graph/index.d.ts +4 -0
  38. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  39. package/dist/data-structures/graph/map-graph.js +54 -0
  40. package/dist/data-structures/graph/map-graph.js.map +1 -1
  41. package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
  42. package/dist/data-structures/graph/undirected-graph.js +105 -0
  43. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  44. package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
  45. package/dist/data-structures/hash/coordinate-map.js +35 -0
  46. package/dist/data-structures/hash/coordinate-map.js.map +1 -1
  47. package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
  48. package/dist/data-structures/hash/coordinate-set.js +28 -0
  49. package/dist/data-structures/hash/coordinate-set.js.map +1 -1
  50. package/dist/data-structures/hash/hash-map.d.ts +56 -0
  51. package/dist/data-structures/hash/hash-map.js +29 -1
  52. package/dist/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/data-structures/hash/hash-table.d.ts +106 -0
  54. package/dist/data-structures/hash/hash-table.js +88 -6
  55. package/dist/data-structures/hash/hash-table.js.map +1 -1
  56. package/dist/data-structures/hash/index.d.ts +7 -0
  57. package/dist/data-structures/hash/pair.d.ts +2 -0
  58. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  59. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  60. package/dist/data-structures/heap/heap.d.ts +83 -0
  61. package/dist/data-structures/heap/heap.js +62 -0
  62. package/dist/data-structures/heap/heap.js.map +1 -1
  63. package/dist/data-structures/heap/index.d.ts +3 -0
  64. package/dist/data-structures/heap/max-heap.d.ts +23 -0
  65. package/dist/data-structures/heap/max-heap.js +16 -0
  66. package/dist/data-structures/heap/max-heap.js.map +1 -1
  67. package/dist/data-structures/heap/min-heap.d.ts +24 -0
  68. package/dist/data-structures/heap/min-heap.js +17 -0
  69. package/dist/data-structures/heap/min-heap.js.map +1 -1
  70. package/dist/data-structures/index.d.ts +11 -0
  71. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
  72. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
  73. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  74. package/dist/data-structures/linked-list/index.d.ts +3 -0
  75. package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
  76. package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
  77. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
  78. package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
  79. package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
  80. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  81. package/dist/data-structures/matrix/index.d.ts +4 -0
  82. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  83. package/dist/data-structures/matrix/matrix.js +15 -0
  84. package/dist/data-structures/matrix/matrix.js.map +1 -1
  85. package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
  86. package/dist/data-structures/matrix/matrix2d.js +91 -2
  87. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  88. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  89. package/dist/data-structures/matrix/navigator.js +28 -0
  90. package/dist/data-structures/matrix/navigator.js.map +1 -1
  91. package/dist/data-structures/matrix/vector2d.d.ts +201 -0
  92. package/dist/data-structures/matrix/vector2d.js +188 -1
  93. package/dist/data-structures/matrix/vector2d.js.map +1 -1
  94. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  95. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  96. package/dist/data-structures/priority-queue/max-priority-queue.js +18 -0
  97. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  98. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  99. package/dist/data-structures/priority-queue/min-priority-queue.js +19 -0
  100. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  101. package/dist/data-structures/priority-queue/priority-queue.d.ts +180 -0
  102. package/dist/data-structures/priority-queue/priority-queue.js +141 -0
  103. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  104. package/dist/data-structures/queue/deque.d.ts +165 -0
  105. package/dist/data-structures/queue/deque.js +124 -0
  106. package/dist/data-structures/queue/deque.js.map +1 -1
  107. package/dist/data-structures/queue/index.d.ts +2 -0
  108. package/dist/data-structures/queue/queue.d.ts +107 -0
  109. package/dist/data-structures/queue/queue.js +80 -0
  110. package/dist/data-structures/queue/queue.js.map +1 -1
  111. package/dist/data-structures/stack/index.d.ts +1 -0
  112. package/dist/data-structures/stack/stack.d.ts +63 -0
  113. package/dist/data-structures/stack/stack.js +50 -0
  114. package/dist/data-structures/stack/stack.js.map +1 -1
  115. package/dist/data-structures/tree/index.d.ts +1 -0
  116. package/dist/data-structures/tree/tree.d.ts +14 -0
  117. package/dist/data-structures/tree/tree.js +1 -0
  118. package/dist/data-structures/tree/tree.js.map +1 -1
  119. package/dist/data-structures/trie/index.d.ts +1 -0
  120. package/dist/data-structures/trie/trie.d.ts +61 -0
  121. package/dist/data-structures/trie/trie.js +36 -0
  122. package/dist/data-structures/trie/trie.js.map +1 -1
  123. package/dist/index.d.ts +4 -0
  124. package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
  125. package/dist/interfaces/abstract-graph.d.ts +5 -0
  126. package/dist/interfaces/avl-tree.d.ts +7 -0
  127. package/dist/interfaces/binary-tree.d.ts +6 -0
  128. package/dist/interfaces/bst.d.ts +6 -0
  129. package/dist/interfaces/directed-graph.d.ts +3 -0
  130. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  131. package/dist/interfaces/heap.d.ts +1 -0
  132. package/dist/interfaces/index.d.ts +15 -0
  133. package/dist/interfaces/navigator.d.ts +1 -0
  134. package/dist/interfaces/priority-queue.d.ts +1 -0
  135. package/dist/interfaces/rb-tree.d.ts +6 -0
  136. package/dist/interfaces/segment-tree.d.ts +1 -0
  137. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  138. package/dist/interfaces/tree-multiset.d.ts +6 -0
  139. package/dist/interfaces/undirected-graph.d.ts +3 -0
  140. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  141. package/dist/types/data-structures/abstract-binary-tree.js +6 -0
  142. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
  143. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  144. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  145. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  146. package/dist/types/data-structures/bst.d.ts +13 -0
  147. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  148. package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
  149. package/dist/types/data-structures/hash.d.ts +1 -0
  150. package/dist/types/data-structures/heap.d.ts +3 -0
  151. package/dist/types/data-structures/index.d.ts +16 -0
  152. package/dist/types/data-structures/map-graph.d.ts +1 -0
  153. package/dist/types/data-structures/navigator.d.ts +14 -0
  154. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  155. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  156. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  157. package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
  158. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  159. package/dist/types/helpers.d.ts +1 -0
  160. package/dist/types/index.d.ts +3 -0
  161. package/dist/types/utils/index.d.ts +2 -0
  162. package/dist/types/utils/utils.d.ts +7 -0
  163. package/dist/types/utils/validate-type.d.ts +19 -0
  164. package/dist/utils/index.d.ts +1 -0
  165. package/dist/utils/utils.d.ts +19 -0
  166. package/package.json +11 -7
  167. package/test/integration/avl-tree.test.ts +4 -4
  168. package/test/integration/bst.test.ts +8 -8
  169. package/test/unit/data-structures/graph/directed-graph.test.ts +5 -5
  170. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  171. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
  172. package/test/unit/data-structures/graph/index.ts +0 -2
  173. package/test/unit/data-structures/linked-list/index.ts +0 -4
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PriorityQueue = void 0;
4
4
  class PriorityQueue {
5
+ /**
6
+ * The constructor initializes a priority queue with the given options, including an array of nodes and a comparator
7
+ * function.
8
+ * @param options - The `options` parameter is an object that contains the following properties:
9
+ */
5
10
  constructor(options) {
6
11
  this._nodes = [];
7
12
  this._comparator = (a, b) => {
@@ -11,6 +16,7 @@ class PriorityQueue {
11
16
  const { nodes, comparator, isFix = true } = options;
12
17
  this._comparator = comparator;
13
18
  if (nodes && Array.isArray(nodes) && nodes.length > 0) {
19
+ // TODO support distinct
14
20
  this._nodes = [...nodes];
15
21
  isFix && this._fix();
16
22
  }
@@ -21,27 +27,64 @@ class PriorityQueue {
21
27
  get size() {
22
28
  return this.nodes.length;
23
29
  }
30
+ /**
31
+ * The `heapify` function creates a new PriorityQueue instance and fixes the heap property.
32
+ * @param options - The "options" parameter is an object that contains the configuration options for the PriorityQueue.
33
+ * It can include properties such as "comparator" which specifies the comparison function used to order the elements in
34
+ * the priority queue, and "initialValues" which is an array of initial values to be added to the priority
35
+ * @returns a new instance of the PriorityQueue class after performing the heapify operation on it.
36
+ */
24
37
  static heapify(options) {
25
38
  const heap = new PriorityQueue(options);
26
39
  heap._fix();
27
40
  return heap;
28
41
  }
42
+ /**
43
+ * The function checks if a priority queue is valid by creating a new priority queue with a fix option and then calling
44
+ * the isValid method.
45
+ * @param options - An object containing options for creating a priority queue. The options object should have the
46
+ * following properties:
47
+ * @returns the result of calling the `isValid()` method on a new instance of the `PriorityQueue` class.
48
+ */
29
49
  static isPriorityQueueified(options) {
30
50
  return new PriorityQueue(Object.assign(Object.assign({}, options), { isFix: false })).isValid();
31
51
  }
52
+ /**
53
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
54
+ */
32
55
  getNodes() {
33
56
  return this._nodes;
34
57
  }
58
+ /**
59
+ * The "add" function adds a node to the heap and ensures that the heap property is maintained.
60
+ * @param {E} node - The parameter "node" is of type E, which means it can be any data type. It represents the node
61
+ * that needs to be added to the heap.
62
+ */
35
63
  add(node) {
36
64
  this.nodes.push(node);
37
65
  this._heapifyUp(this.size - 1);
38
66
  }
67
+ /**
68
+ * The "has" function checks if a given node is present in the list of nodes.
69
+ * @param {E} node - The parameter `node` is of type `E`, which means it can be any type. It represents the node that
70
+ * we want to check if it exists in the `nodes` array.
71
+ * @returns a boolean value indicating whether the given node is included in the array of nodes.
72
+ */
39
73
  has(node) {
40
74
  return this.nodes.includes(node);
41
75
  }
76
+ /**
77
+ * The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
78
+ * @returns The `peek()` function is returning the first element (`E`) of the `nodes` array if the `size` is not zero.
79
+ * Otherwise, it returns `null`.
80
+ */
42
81
  peek() {
43
82
  return this.size ? this.nodes[0] : null;
44
83
  }
84
+ /**
85
+ * The `poll` function removes and returns the top element from a heap data structure.
86
+ * @returns The `poll()` method returns a value of type `E` or `null`.
87
+ */
45
88
  poll() {
46
89
  var _a, _b;
47
90
  let res = null;
@@ -55,25 +98,54 @@ class PriorityQueue {
55
98
  }
56
99
  return res;
57
100
  }
101
+ /**
102
+ * The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.
103
+ * @returns The method `leaf()` is returning the last element (`E`) in the `nodes` array if it exists. If the array is
104
+ * empty or the last element is `null`, then it returns `null`.
105
+ */
58
106
  leaf() {
59
107
  var _a;
60
108
  return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : null;
61
109
  }
110
+ /**
111
+ * The function checks if the size of an object is equal to zero and returns a boolean value indicating whether the
112
+ * object is empty or not.
113
+ * @returns The method `isEmpty()` is returning a boolean value indicating whether the size of the object is equal to
114
+ * 0.
115
+ */
62
116
  isEmpty() {
63
117
  return this.size === 0;
64
118
  }
119
+ /**
120
+ * The clear function clears the nodes array.
121
+ */
65
122
  clear() {
66
123
  this._setNodes([]);
67
124
  }
125
+ /**
126
+ * The toArray function returns an array containing all the elements in the nodes property.
127
+ * @returns An array of type E, which is the elements of the nodes property.
128
+ */
68
129
  toArray() {
69
130
  return [...this.nodes];
70
131
  }
132
+ /**
133
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same nodes and comparator as the
134
+ * original instance.
135
+ * @returns The `clone()` method is returning a new instance of the `PriorityQueue` class with the same `nodes` and
136
+ * `comparator` properties as the original instance.
137
+ */
71
138
  clone() {
72
139
  return new PriorityQueue({
73
140
  nodes: this.nodes,
74
141
  comparator: this._comparator
75
142
  });
76
143
  }
144
+ // --- start additional methods ---
145
+ /**
146
+ * The `isValid` function recursively checks if a binary tree satisfies a certain condition.
147
+ * @returns The function `isValid()` returns a boolean value.
148
+ */
77
149
  isValid() {
78
150
  for (let i = 0; i < this.nodes.length; i++) {
79
151
  const leftChildIndex = this._getLeft(i);
@@ -87,6 +159,14 @@ class PriorityQueue {
87
159
  }
88
160
  return true;
89
161
  }
162
+ /**
163
+ * O(n log n), In scenarios with smaller data sizes, heap sort is generally expected to be slower than QuickSort or MergeSort.
164
+ */
165
+ /**
166
+ * The function sorts the elements in a data structure and returns them in an array.
167
+ * Plan to support sorting of duplicate elements.
168
+ * @returns The `sort()` method is returning an array of type `E[]`.
169
+ */
90
170
  sort() {
91
171
  const visitedNode = [];
92
172
  while (this.size !== 0) {
@@ -96,6 +176,13 @@ class PriorityQueue {
96
176
  }
97
177
  return visitedNode;
98
178
  }
179
+ /**
180
+ * The dfs function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
181
+ * based on the specified traversal order.
182
+ * @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
183
+ * the nodes should be visited during the Depth-First Search (dfs) traversal. It can have one of the following values:
184
+ * @returns an array of type `(E | null)[]`.
185
+ */
99
186
  dfs(dfsMode) {
100
187
  const visitedNode = [];
101
188
  const traverse = (cur) => {
@@ -126,26 +213,66 @@ class PriorityQueue {
126
213
  _setNodes(value) {
127
214
  this._nodes = value;
128
215
  }
216
+ /**
217
+ * The function compares two numbers using a custom comparator function.
218
+ * @param {number} a - The parameter "a" is a number that represents the index of a node in an array.
219
+ * @param {number} b - The parameter "b" is a number.
220
+ * @returns the result of the comparison between the elements at indices `a` and `b` in the `nodes` array. The
221
+ * comparison is done using the `_comparator` function, and if the result is greater than 0, `true` is returned,
222
+ * indicating that the element at index `a` is greater than the element at index `b`.
223
+ */
129
224
  _compare(a, b) {
130
225
  return this._comparator(this.nodes[a], this.nodes[b]) > 0;
131
226
  }
227
+ /**
228
+ * The function swaps two elements in an array.
229
+ * @param {number} a - The parameter "a" is a number that represents the index of an element in an array.
230
+ * @param {number} b - The parameter "b" is a number.
231
+ */
132
232
  _swap(a, b) {
133
233
  const temp = this.nodes[a];
134
234
  this.nodes[a] = this.nodes[b];
135
235
  this.nodes[b] = temp;
136
236
  }
237
+ /**
238
+ * The function checks if a given index is valid within an array.
239
+ * @param {number} index - The parameter "index" is of type number and represents the index value that needs to be
240
+ * checked for validity.
241
+ * @returns A boolean value indicating whether the given index is valid or not.
242
+ */
137
243
  _isValidIndex(index) {
138
244
  return index > -1 && index < this.nodes.length;
139
245
  }
246
+ /**
247
+ * The function returns the index of the parent node given the index of a child node in a binary tree.
248
+ * @param {number} child - The "child" parameter is a number representing the index of a child node in a binary tree.
249
+ * @returns the parent of the given child node.
250
+ */
140
251
  _getParent(child) {
141
252
  return Math.floor((child - 1) / 2);
142
253
  }
254
+ /**
255
+ * The function returns the index of the left child node in a binary tree given the index of its parent node.
256
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
257
+ * @returns the left child of a given parent node in a binary tree.
258
+ */
143
259
  _getLeft(parent) {
144
260
  return 2 * parent + 1;
145
261
  }
262
+ /**
263
+ * The function returns the index of the right child node in a binary tree given the index of its parent node.
264
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
265
+ * @returns the right child of a given parent node in a binary tree.
266
+ */
146
267
  _getRight(parent) {
147
268
  return 2 * parent + 2;
148
269
  }
270
+ /**
271
+ * The function returns the index of the smallest child node of a given parent node.
272
+ * @param {number} parent - The parent parameter is a number that represents the index of the parent node in a binary
273
+ * tree.
274
+ * @returns the minimum value between the parent node and its left and right child nodes.
275
+ */
149
276
  _getComparedChild(parent) {
150
277
  let min = parent;
151
278
  const left = this._getLeft(parent), right = this._getRight(parent);
@@ -157,6 +284,11 @@ class PriorityQueue {
157
284
  }
158
285
  return min;
159
286
  }
287
+ /**
288
+ * The function `_heapifyUp` is used to maintain the heap property by moving an element up the heap until it is in the
289
+ * correct position.
290
+ * @param {number} start - The start parameter is the index of the element that needs to be moved up in the heap.
291
+ */
160
292
  _heapifyUp(start) {
161
293
  while (start > 0 && this._compare(this._getParent(start), start)) {
162
294
  const parent = this._getParent(start);
@@ -164,6 +296,11 @@ class PriorityQueue {
164
296
  start = parent;
165
297
  }
166
298
  }
299
+ /**
300
+ * The function performs a heapify operation by comparing and swapping elements in a binary heap.
301
+ * @param {number} start - The start parameter is the index of the element in the heap from where the heapifyDown
302
+ * operation should start.
303
+ */
167
304
  _heapifyDown(start) {
168
305
  let min = this._getComparedChild(start);
169
306
  while (this._compare(start, min)) {
@@ -172,6 +309,10 @@ class PriorityQueue {
172
309
  min = this._getComparedChild(start);
173
310
  }
174
311
  }
312
+ /**
313
+ * The _fix function performs a heapify operation on the elements of the heap starting from the middle and moving
314
+ * towards the root.
315
+ */
175
316
  _fix() {
176
317
  for (let i = Math.floor(this.size / 2); i > -1; i--)
177
318
  this._heapifyDown(i);
@@ -1 +1 @@
1
- {"version":3,"file":"priority-queue.js","sourceRoot":"","sources":["../../../src/data-structures/priority-queue/priority-queue.ts"],"names":[],"mappings":";;;AASA,MAAa,aAAa;IAMxB,YAAY,OAAgC;QAWlC,WAAM,GAAQ,EAAE,CAAC;QAkNR,gBAAW,GAA+B,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;YAC1E,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;YAChC,OAAO,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC,CAAC;QAhOA,MAAM,EAAC,KAAK,EAAE,UAAU,EAAE,KAAK,GAAG,IAAI,EAAC,GAAG,OAAO,CAAC;QAClD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAErD,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YACzB,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;SACtB;IACH,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IASD,MAAM,CAAC,OAAO,CAAI,OAAgC;QAChD,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IASD,MAAM,CAAC,oBAAoB,CAAI,OAA+C;QAC5E,OAAO,IAAI,aAAa,iCAAK,OAAO,KAAE,KAAK,EAAE,KAAK,IAAE,CAAC,OAAO,EAAE,CAAC;IACjE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edList } from '../linked-list';
9
+ export declare class Deque<E = any> extends DoublyLinkedList<E> {
10
+ }
11
+ export declare class ObjectDeque<E = number> {
12
+ constructor(capacity?: number);
13
+ private _nodes;
14
+ get nodes(): {
15
+ [p: number]: E;
16
+ };
17
+ private _capacity;
18
+ get capacity(): number;
19
+ set capacity(value: number);
20
+ private _first;
21
+ get first(): number;
22
+ set first(value: number);
23
+ private _last;
24
+ get last(): number;
25
+ set last(value: number);
26
+ private _size;
27
+ get size(): number;
28
+ /**
29
+ * The "addFirst" function adds a value to the beginning of an array-like data structure.
30
+ * @param {E} value - The `value` parameter represents the value that you want to add to the beginning of the data
31
+ * structure.
32
+ */
33
+ addFirst(value: E): void;
34
+ /**
35
+ * The addLast function adds a value to the end of an array-like data structure.
36
+ * @param {E} value - The `value` parameter represents the value that you want to add to the end of the data structure.
37
+ */
38
+ addLast(value: E): void;
39
+ /**
40
+ * The function `pollFirst()` removes and returns the first element in a data structure.
41
+ * @returns The value of the first element in the data structure.
42
+ */
43
+ pollFirst(): E | undefined;
44
+ /**
45
+ * The `peekFirst` function returns the first element in an array-like data structure if it exists.
46
+ * @returns The element at the first position of the `_nodes` array.
47
+ */
48
+ peekFirst(): E | undefined;
49
+ /**
50
+ * The `pollLast()` function removes and returns the last element in a data structure.
51
+ * @returns The value that was removed from the data structure.
52
+ */
53
+ pollLast(): E | undefined;
54
+ /**
55
+ * The `peekLast()` function returns the last element in an array-like data structure.
56
+ * @returns The last element in the array "_nodes" is being returned.
57
+ */
58
+ peekLast(): E | undefined;
59
+ /**
60
+ * The get function returns the element at the specified index in an array-like data structure.
61
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
62
+ * retrieve from the array.
63
+ * @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
64
+ * index, `null` is returned.
65
+ */
66
+ get(index: number): NonNullable<E> | null;
67
+ /**
68
+ * The function checks if the size of a data structure is less than or equal to zero.
69
+ * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
70
+ */
71
+ isEmpty(): boolean;
72
+ protected _seNodes(value: {
73
+ [p: number]: E;
74
+ }): void;
75
+ protected _setSize(value: number): void;
76
+ }
77
+ export declare class ArrayDeque<E> {
78
+ protected _nodes: E[];
79
+ get size(): number;
80
+ /**
81
+ * O(n) time complexity of adding at the beginning and the end
82
+ */
83
+ /**
84
+ * The function "addLast" adds a value to the end of an array.
85
+ * @param {E} value - The value parameter represents the value that you want to add to the end of the array.
86
+ * @returns The return value is the new length of the array after the value has been added.
87
+ */
88
+ addLast(value: E): number;
89
+ /**
90
+ * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
91
+ * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
92
+ */
93
+ pollLast(): E | null;
94
+ /**
95
+ * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
96
+ * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
97
+ * empty.
98
+ */
99
+ pollFirst(): E | null;
100
+ /**
101
+ * O(n) time complexity of adding at the beginning and the end
102
+ */
103
+ /**
104
+ * The function "addFirst" adds a value to the beginning of an array.
105
+ * @param {E} value - The value parameter represents the value that you want to add to the beginning of the array.
106
+ * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
107
+ * `value` at the beginning.
108
+ */
109
+ addFirst(value: E): number;
110
+ /**
111
+ * The `peekFirst` function returns the first element of an array or null if the array is empty.
112
+ * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
113
+ * empty, it will return `null`.
114
+ */
115
+ peekFirst(): E | null;
116
+ /**
117
+ * The `peekLast` function returns the last element of an array or null if the array is empty.
118
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
119
+ */
120
+ peekLast(): E | null;
121
+ /**
122
+ * O(1) time complexity of obtaining the value
123
+ */
124
+ /**
125
+ * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
126
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
127
+ * retrieve from the array.
128
+ * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
129
+ * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
130
+ */
131
+ get(index: number): E | null;
132
+ /**
133
+ * The set function assigns a value to a specific index in an array.
134
+ * @param {number} index - The index parameter is a number that represents the position of the element in the array
135
+ * that you want to set a new value for.
136
+ * @param {E} value - The value parameter represents the new value that you want to set at the specified index in the
137
+ * _nodes array.
138
+ * @returns The value that is being set at the specified index in the `_nodes` array.
139
+ */
140
+ set(index: number, value: E): E;
141
+ /**
142
+ * The insert function adds a value at a specified index in an array.
143
+ * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
144
+ * array. It is a number that represents the index of the array where the value should be inserted. The index starts
145
+ * from 0, so the first element of the array has an index of 0, the second element has
146
+ * @param {E} value - The value parameter represents the value that you want to insert into the array at the specified
147
+ * index.
148
+ * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
149
+ * are being removed, an empty array will be returned.
150
+ */
151
+ insert(index: number, value: E): E[];
152
+ /**
153
+ * The remove function removes an element from an array at a specified index.
154
+ * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
155
+ * is a number that represents the index of the element to be removed.
156
+ * @returns The method is returning an array containing the removed element.
157
+ */
158
+ remove(index: number): E[];
159
+ /**
160
+ * The function checks if an array called "_nodes" is empty.
161
+ * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
162
+ * is 0, indicating that the array is empty. Otherwise, it returns `false`.
163
+ */
164
+ isEmpty(): boolean;
165
+ }