heap-typed 1.19.5 → 1.19.7

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 +106 -5
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,31 +1,133 @@
1
1
  # What
2
+
2
3
  ## Brief
3
- This is a standalone Heap data structure from the data-structure-typed collection. If you wish to access more data structures or advanced features, you can transition to directly installing the complete [data-structure-typed](https://www.npmjs.com/package/data-structure-typed) package
4
4
 
5
+ This is a standalone Heap data structure from the data-structure-typed collection. If you wish to access more data
6
+ structures or advanced features, you can transition to directly installing the
7
+ complete [data-structure-typed](https://www.npmjs.com/package/data-structure-typed) package
5
8
 
6
9
  # How
7
10
 
8
11
  ## install
12
+
9
13
  ### npm
14
+
10
15
  ```bash
11
16
  npm i heap-typed
12
17
  ```
18
+
13
19
  ### yarn
20
+
14
21
  ```bash
15
22
  yarn add heap-typed
16
23
  ```
17
24
 
18
25
  ### snippet
26
+
19
27
  #### TS
20
- ```typescript
21
28
 
29
+ ```typescript
30
+ import {MinHeap, MaxHeap} from 'data-structure-typed';
31
+ // /* or if you prefer */ import {MinHeap, MaxHeap} from 'heap-typed';
32
+
33
+ const minNumHeap = new MinHeap<number>();
34
+ minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
35
+ minNumHeap.poll() // 0
36
+ minNumHeap.poll() // 1
37
+ minNumHeap.peek() // 2
38
+ minNumHeap.toArray().length // 4
39
+ minNumHeap.toArray()[0] // 2
40
+ minNumHeap.toArray()[1] // 5
41
+ minNumHeap.toArray()[2] // 9
42
+ minNumHeap.toArray()[3] // 6
43
+
44
+
45
+ const maxHeap = new MaxHeap<{ keyA: string }>();
46
+ const myObj1 = {keyA: 'a1'}, myObj6 = {keyA: 'a6'}, myObj5 = {keyA: 'a5'}, myObj2 = {keyA: 'a2'},
47
+ myObj0 = {keyA: 'a0'}, myObj9 = {keyA: 'a9'};
48
+ maxHeap.add(1, myObj1);
49
+ maxHeap.has(myObj1) // true
50
+ maxHeap.has(myObj9) // false
51
+ maxHeap.add(6, myObj6);
52
+ maxHeap.has(myObj6) // true
53
+ maxHeap.add(5, myObj5);
54
+ maxHeap.has(myObj5) // true
55
+ maxHeap.add(2, myObj2);
56
+ maxHeap.has(myObj2) // true
57
+ maxHeap.has(myObj6) // true
58
+ maxHeap.add(0, myObj0);
59
+ maxHeap.has(myObj0) // true
60
+ maxHeap.has(myObj9) // false
61
+ maxHeap.add(9, myObj9);
62
+ maxHeap.has(myObj9) // true
63
+
64
+ const peek9 = maxHeap.peek(true);
65
+ peek9 && peek9.val && peek9.val.keyA // 'a9'
66
+
67
+ const heapToArr = maxHeap.toArray(true);
68
+ heapToArr.map(item => item?.val?.keyA) // ['a9', 'a2', 'a6', 'a1', 'a0', 'a5']
69
+
70
+ const values = ['a9', 'a6', 'a5', 'a2', 'a1', 'a0'];
71
+ let i = 0;
72
+ while (maxHeap.size > 0) {
73
+ const polled = maxHeap.poll(true);
74
+ polled && polled.val && polled.val.keyA // values[i]
75
+ i++;
76
+ }
22
77
  ```
78
+
23
79
  #### JS
24
- ```javascript
25
80
 
81
+ ```javascript
82
+ const {MinHeap, MaxHeap} = require('data-structure-typed');
83
+ // /* or if you prefer */ const {MinHeap, MaxHeap} = require('heap-typed');
84
+
85
+ const minNumHeap = new MinHeap();
86
+ minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
87
+ minNumHeap.poll() // 0
88
+ minNumHeap.poll() // 1
89
+ minNumHeap.peek() // 2
90
+ minNumHeap.toArray().length // 4
91
+ minNumHeap.toArray()[0] // 2
92
+ minNumHeap.toArray()[1] // 5
93
+ minNumHeap.toArray()[2] // 9
94
+ minNumHeap.toArray()[3] // 6
95
+
96
+
97
+ const maxHeap = new MaxHeap();
98
+ const myObj1 = {keyA: 'a1'}, myObj6 = {keyA: 'a6'}, myObj5 = {keyA: 'a5'}, myObj2 = {keyA: 'a2'},
99
+ myObj0 = {keyA: 'a0'}, myObj9 = {keyA: 'a9'};
100
+ maxHeap.add(1, myObj1);
101
+ maxHeap.has(myObj1) // true
102
+ maxHeap.has(myObj9) // false
103
+ maxHeap.add(6, myObj6);
104
+ maxHeap.has(myObj6) // true
105
+ maxHeap.add(5, myObj5);
106
+ maxHeap.has(myObj5) // true
107
+ maxHeap.add(2, myObj2);
108
+ maxHeap.has(myObj2) // true
109
+ maxHeap.has(myObj6) // true
110
+ maxHeap.add(0, myObj0);
111
+ maxHeap.has(myObj0) // true
112
+ maxHeap.has(myObj9) // false
113
+ maxHeap.add(9, myObj9);
114
+ maxHeap.has(myObj9) // true
115
+
116
+ const peek9 = maxHeap.peek(true);
117
+ peek9 && peek9.val && peek9.val.keyA // 'a9'
118
+
119
+ const heapToArr = maxHeap.toArray(true);
120
+ heapToArr.map(item => item?.val?.keyA) // ['a9', 'a2', 'a6', 'a1', 'a0', 'a5']
121
+
122
+ const values = ['a9', 'a6', 'a5', 'a2', 'a1', 'a0'];
123
+ let i = 0;
124
+ while (maxHeap.size > 0) {
125
+ const polled = maxHeap.poll(true);
126
+ polled && polled.val && polled.val.keyA // values[i]
127
+ i++;
128
+ }
26
129
  ```
27
130
 
28
-
29
131
  ## API docs & Examples
30
132
 
31
133
  [API Docs](https://data-structure-typed-docs.vercel.app)
@@ -227,7 +329,6 @@ yarn add heap-typed
227
329
  </tbody>
228
330
  </table>
229
331
 
230
-
231
332
  # Why
232
333
 
233
334
  ## Complexities
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heap-typed",
3
- "version": "1.19.5",
3
+ "version": "1.19.7",
4
4
  "description": "Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -57,7 +57,7 @@
57
57
  "typescript": "^4.9.5"
58
58
  },
59
59
  "dependencies": {
60
- "data-structure-typed": "^1.19.5",
60
+ "data-structure-typed": "^1.19.7",
61
61
  "zod": "^3.22.2"
62
62
  }
63
63
  }