data-structure-typed 1.19.8 → 1.20.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.
@@ -73,6 +73,9 @@ export declare abstract class Heap<T = number> {
73
73
  toArray(isItem?: undefined): (T | undefined)[];
74
74
  toArray(isItem: false): (T | undefined)[];
75
75
  toArray(isItem: true): (HeapItem<T> | null)[];
76
+ sort(isItem?: undefined): (T | undefined)[];
77
+ sort(isItem: false): (T | undefined)[];
78
+ sort(isItem: true): (HeapItem<T> | null)[];
76
79
  /**
77
80
  * The clear function clears the priority queue.
78
81
  */
@@ -134,6 +134,19 @@ class Heap {
134
134
  const itemArray = this._pq.toArray();
135
135
  return isItem ? itemArray : itemArray.map(item => item.val);
136
136
  }
137
+ /**
138
+ * The function sorts the elements in the priority queue and returns either the sorted items or their values depending
139
+ * on the value of the isItem parameter.
140
+ * @param {boolean} [isItem] - The `isItem` parameter is a boolean flag that indicates whether the sorted result should
141
+ * be an array of `HeapItem<T>` objects or an array of the values (`T`) of those objects. If `isItem` is `true`, the
142
+ * sorted result will be an array of `HeapItem
143
+ * @returns an array of either `HeapItem<T>`, `null`, `T`, or `undefined` values.
144
+ */
145
+ sort(isItem) {
146
+ isItem = isItem !== null && isItem !== void 0 ? isItem : false;
147
+ const sorted = this._pq.sort();
148
+ return isItem ? sorted : sorted.map(item => item.val);
149
+ }
137
150
  /**
138
151
  * The clear function clears the priority queue.
139
152
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.19.8",
3
+ "version": "1.20.0",
4
4
  "description": "Javascript & TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -174,6 +174,23 @@ export abstract class Heap<T = number> {
174
174
  return isItem ? itemArray : itemArray.map(item => item.val);
175
175
  }
176
176
 
177
+ sort(isItem?: undefined): (T | undefined)[];
178
+ sort(isItem: false): (T | undefined)[];
179
+ sort(isItem: true): (HeapItem<T> | null)[];
180
+ /**
181
+ * The function sorts the elements in the priority queue and returns either the sorted items or their values depending
182
+ * on the value of the isItem parameter.
183
+ * @param {boolean} [isItem] - The `isItem` parameter is a boolean flag that indicates whether the sorted result should
184
+ * be an array of `HeapItem<T>` objects or an array of the values (`T`) of those objects. If `isItem` is `true`, the
185
+ * sorted result will be an array of `HeapItem
186
+ * @returns an array of either `HeapItem<T>`, `null`, `T`, or `undefined` values.
187
+ */
188
+ sort(isItem?: boolean): (HeapItem<T> | null | T | undefined)[] {
189
+ isItem = isItem ?? false;
190
+ const sorted = this._pq.sort();
191
+ return isItem ? sorted : sorted.map(item => item.val);
192
+ }
193
+
177
194
  /**
178
195
  * The clear function clears the priority queue.
179
196
  */
Binary file
Binary file