priority-queue-typed 1.19.5 → 1.19.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +58 -2
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -18,11 +18,67 @@ yarn add priority-queue-typed
18
18
  ### snippet
19
19
  #### TS
20
20
  ```typescript
21
-
21
+ import {PriorityQueue, MinPriorityQueue} from 'data-structure-typed';
22
+ // /* or if you prefer */ import {PriorityQueue, MinPriorityQueue} from 'priority-queue-typed';
23
+
24
+ const minPQ = new PriorityQueue<number>({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => a - b});
25
+ minPQ.toArray() // [1, 2, 3, 4, 6, 5]
26
+ minPQ.poll();
27
+ minPQ.poll();
28
+ minPQ.poll();
29
+ minPQ.toArray() // [4, 5, 6]
30
+ minPQ.peek() // 4
31
+ PriorityQueue.heapify({
32
+ nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
33
+ comparator: (a, b) => a - b
34
+ }).toArray() // [1, 2, 3, 5, 6, 7, 8, 9, 10]
35
+
36
+ const priorityQueue = new MinPriorityQueue<number>();
37
+ priorityQueue.add(5);
38
+ priorityQueue.add(3);
39
+ priorityQueue.add(7);
40
+ priorityQueue.add(1);
41
+ const sortedArray = priorityQueue.sort(); // [1, 3, 5, 7]);
42
+
43
+ const minPQ1 = new PriorityQueue<number>({nodes: [2, 5, 8, 3, 1, 6, 7, 4], comparator: (a, b) => a - b});
44
+ const clonedPriorityQueue = minPQ1.clone();
45
+ clonedPriorityQueue.getNodes() // minPQ1.getNodes()
46
+ clonedPriorityQueue.sort() // [1, 2, 3, 4, 5, 6, 7, 8]
47
+ minPQ1.DFS('in') // [4, 3, 2, 5, 1, 8, 6, 7]
48
+ minPQ1.DFS('post') // [4, 3, 5, 2, 8, 7, 6, 1]
49
+ minPQ1.DFS('pre') // [1, 2, 3, 4, 5, 6, 8, 7]
22
50
  ```
23
51
  #### JS
24
52
  ```javascript
25
-
53
+ const {PriorityQueue, MinPriorityQueue} = require('data-structure-typed');
54
+ // /* or if you prefer */ const {PriorityQueue, MinPriorityQueue} = require('priority-queue-typed');
55
+
56
+ const minPQ = new PriorityQueue({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => a - b});
57
+ minPQ.toArray() // [1, 2, 3, 4, 6, 5]
58
+ minPQ.poll();
59
+ minPQ.poll();
60
+ minPQ.poll();
61
+ minPQ.toArray() // [4, 5, 6]
62
+ minPQ.peek() // 4
63
+ PriorityQueue.heapify({
64
+ nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
65
+ comparator: (a, b) => a - b
66
+ }).toArray() // [1, 2, 3, 5, 6, 7, 8, 9, 10]
67
+
68
+ const priorityQueue = new MinPriorityQueue();
69
+ priorityQueue.add(5);
70
+ priorityQueue.add(3);
71
+ priorityQueue.add(7);
72
+ priorityQueue.add(1);
73
+ const sortedArray = priorityQueue.sort(); // [1, 3, 5, 7]);
74
+
75
+ const minPQ1 = new PriorityQueue<number>({nodes: [2, 5, 8, 3, 1, 6, 7, 4], comparator: (a, b) => a - b});
76
+ const clonedPriorityQueue = minPQ1.clone();
77
+ clonedPriorityQueue.getNodes() // minPQ1.getNodes()
78
+ clonedPriorityQueue.sort() // [1, 2, 3, 4, 5, 6, 7, 8]
79
+ minPQ1.DFS('in') // [4, 3, 2, 5, 1, 8, 6, 7]
80
+ minPQ1.DFS('post') // [4, 3, 5, 2, 8, 7, 6, 1]
81
+ minPQ1.DFS('pre') // [1, 2, 3, 4, 5, 6, 8, 7]
26
82
  ```
27
83
 
28
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "priority-queue-typed",
3
- "version": "1.19.5",
3
+ "version": "1.19.6",
4
4
  "description": "Priority Queue, Min Priority Queue, Max Priority Queue. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -55,7 +55,7 @@
55
55
  "typescript": "^4.9.5"
56
56
  },
57
57
  "dependencies": {
58
- "data-structure-typed": "^1.19.5",
58
+ "data-structure-typed": "1.19.6",
59
59
  "zod": "^3.22.2"
60
60
  }
61
61
  }