@grain/stdlib 0.5.13 → 0.6.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.
- package/CHANGELOG.md +193 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +47 -37
- package/hash.md +21 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2084 -0
- package/json.md +608 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +191 -172
- package/runtime/numberUtils.md +17 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +540 -242
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/priorityqueue.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
title: PriorityQueue
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
A
|
|
5
|
+
A priority queue is a data structure that maintains elements in a priority order. Elements with higher priority are served before elements with lower priority when extracting from the priority queue.
|
|
6
|
+
|
|
7
|
+
An immutable priority queue implementation is available in the `Immutable` submodule.
|
|
6
8
|
|
|
7
9
|
<details disabled>
|
|
8
10
|
<summary tabindex="-1">Added in <code>0.5.3</code></summary>
|
|
@@ -10,7 +12,7 @@ No other changes yet.
|
|
|
10
12
|
</details>
|
|
11
13
|
|
|
12
14
|
```grain
|
|
13
|
-
|
|
15
|
+
from "priorityqueue" include Priorityqueue
|
|
14
16
|
```
|
|
15
17
|
|
|
16
18
|
## Types
|
|
@@ -27,17 +29,24 @@ Mutable data structure which maintains a priority order for its elements.
|
|
|
27
29
|
|
|
28
30
|
## Values
|
|
29
31
|
|
|
30
|
-
Functions
|
|
32
|
+
Functions and constants included in the PriorityQueue module.
|
|
31
33
|
|
|
32
|
-
### PriorityQueue.**
|
|
34
|
+
### PriorityQueue.**make**
|
|
33
35
|
|
|
34
|
-
<details
|
|
35
|
-
<summary
|
|
36
|
-
|
|
36
|
+
<details>
|
|
37
|
+
<summary>Added in <code>0.5.3</code></summary>
|
|
38
|
+
<table>
|
|
39
|
+
<thead>
|
|
40
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
41
|
+
</thead>
|
|
42
|
+
<tbody>
|
|
43
|
+
<tr><td><code>0.6.0</code></td><td>Merged with `makeSized`; modified signature to accept size</td></tr>
|
|
44
|
+
</tbody>
|
|
45
|
+
</table>
|
|
37
46
|
</details>
|
|
38
47
|
|
|
39
48
|
```grain
|
|
40
|
-
|
|
49
|
+
make : (?compare: ((a, a) => Number), ?size: Number) => PriorityQueue<a>
|
|
41
50
|
```
|
|
42
51
|
|
|
43
52
|
Creates a new priority queue with a given internal storage size and a
|
|
@@ -47,14 +56,14 @@ priority, a positive number if the first has greater priority, and a
|
|
|
47
56
|
negative number if the first has less priority.
|
|
48
57
|
|
|
49
58
|
Generally, you won't need to care about the storage size of your priority
|
|
50
|
-
queue and can use
|
|
59
|
+
queue and can use the default size.
|
|
51
60
|
|
|
52
61
|
Parameters:
|
|
53
62
|
|
|
54
63
|
|param|type|description|
|
|
55
64
|
|-----|----|-----------|
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
|`?compare`|`(a, a) => Number`|The comparator function used to indicate priority order|
|
|
66
|
+
|`?size`|`Number`|The initial storage size of the priority queue|
|
|
58
67
|
|
|
59
68
|
Returns:
|
|
60
69
|
|
|
@@ -62,38 +71,14 @@ Returns:
|
|
|
62
71
|
|----|-----------|
|
|
63
72
|
|`PriorityQueue<a>`|An empty priority queue|
|
|
64
73
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
<details disabled>
|
|
68
|
-
<summary tabindex="-1">Added in <code>0.5.3</code></summary>
|
|
69
|
-
No other changes yet.
|
|
70
|
-
</details>
|
|
74
|
+
Examples:
|
|
71
75
|
|
|
72
76
|
```grain
|
|
73
|
-
make
|
|
77
|
+
PriorityQueue.make() // creates a min priority queue of numbers using the compare pervasive
|
|
74
78
|
```
|
|
75
79
|
|
|
76
|
-
Creates a new priority queue with a comparator function, which is used to
|
|
77
|
-
determine priority of elements. The comparator function takes two elements
|
|
78
|
-
and must return 0 if both share priority, a positive number if the first
|
|
79
|
-
has greater priority, and a negative number if the first has less priority.
|
|
80
|
-
|
|
81
|
-
Parameters:
|
|
82
|
-
|
|
83
|
-
|param|type|description|
|
|
84
|
-
|-----|----|-----------|
|
|
85
|
-
|`comp`|`(a, a) -> Number`|The comparator function used to indicate priority order|
|
|
86
|
-
|
|
87
|
-
Returns:
|
|
88
|
-
|
|
89
|
-
|type|description|
|
|
90
|
-
|----|-----------|
|
|
91
|
-
|`PriorityQueue<a>`|An empty priority queue|
|
|
92
|
-
|
|
93
|
-
Examples:
|
|
94
|
-
|
|
95
80
|
```grain
|
|
96
|
-
PriorityQueue.make(compare) // creates a min priority queue of numbers using the compare pervasive
|
|
81
|
+
PriorityQueue.make(compare=compare, size=32) // creates a min priority queue of numbers using the compare pervasive and an initial size of 32
|
|
97
82
|
```
|
|
98
83
|
|
|
99
84
|
```grain
|
|
@@ -108,7 +93,7 @@ No other changes yet.
|
|
|
108
93
|
</details>
|
|
109
94
|
|
|
110
95
|
```grain
|
|
111
|
-
size : PriorityQueue<a>
|
|
96
|
+
size : (pq: PriorityQueue<a>) => Number
|
|
112
97
|
```
|
|
113
98
|
|
|
114
99
|
Gets the number of elements in a priority queue.
|
|
@@ -133,7 +118,7 @@ No other changes yet.
|
|
|
133
118
|
</details>
|
|
134
119
|
|
|
135
120
|
```grain
|
|
136
|
-
isEmpty : PriorityQueue<a>
|
|
121
|
+
isEmpty : (pq: PriorityQueue<a>) => Bool
|
|
137
122
|
```
|
|
138
123
|
|
|
139
124
|
Determines if the priority queue contains no elements.
|
|
@@ -158,7 +143,7 @@ No other changes yet.
|
|
|
158
143
|
</details>
|
|
159
144
|
|
|
160
145
|
```grain
|
|
161
|
-
push : (a, PriorityQueue<a>)
|
|
146
|
+
push : (val: a, pq: PriorityQueue<a>) => Void
|
|
162
147
|
```
|
|
163
148
|
|
|
164
149
|
Adds a new element to the priority queue.
|
|
@@ -178,7 +163,7 @@ No other changes yet.
|
|
|
178
163
|
</details>
|
|
179
164
|
|
|
180
165
|
```grain
|
|
181
|
-
peek : PriorityQueue<a>
|
|
166
|
+
peek : (pq: PriorityQueue<a>) => Option<a>
|
|
182
167
|
```
|
|
183
168
|
|
|
184
169
|
Retrieves the highest priority element in the priority queue. It is not
|
|
@@ -204,7 +189,7 @@ No other changes yet.
|
|
|
204
189
|
</details>
|
|
205
190
|
|
|
206
191
|
```grain
|
|
207
|
-
pop : PriorityQueue<a>
|
|
192
|
+
pop : (pq: PriorityQueue<a>) => Option<a>
|
|
208
193
|
```
|
|
209
194
|
|
|
210
195
|
Removes and retrieves the highest priority element in the priority queue.
|
|
@@ -229,7 +214,7 @@ No other changes yet.
|
|
|
229
214
|
</details>
|
|
230
215
|
|
|
231
216
|
```grain
|
|
232
|
-
drain : PriorityQueue<a>
|
|
217
|
+
drain : (pq: PriorityQueue<a>) => List<a>
|
|
233
218
|
```
|
|
234
219
|
|
|
235
220
|
Clears the priority queue and produces a list of all of the elements in the priority
|
|
@@ -249,13 +234,21 @@ Returns:
|
|
|
249
234
|
|
|
250
235
|
### PriorityQueue.**fromArray**
|
|
251
236
|
|
|
252
|
-
<details
|
|
253
|
-
<summary
|
|
254
|
-
|
|
237
|
+
<details>
|
|
238
|
+
<summary>Added in <code>0.5.4</code></summary>
|
|
239
|
+
<table>
|
|
240
|
+
<thead>
|
|
241
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
242
|
+
</thead>
|
|
243
|
+
<tbody>
|
|
244
|
+
<tr><td><code>0.6.0</code></td><td>Made `compare` a default argument</td></tr>
|
|
245
|
+
</tbody>
|
|
246
|
+
</table>
|
|
255
247
|
</details>
|
|
256
248
|
|
|
257
249
|
```grain
|
|
258
|
-
fromArray :
|
|
250
|
+
fromArray :
|
|
251
|
+
(array: Array<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
|
|
259
252
|
```
|
|
260
253
|
|
|
261
254
|
Constructs a new priority queue initialized with the elements in the array
|
|
@@ -269,7 +262,7 @@ Parameters:
|
|
|
269
262
|
|param|type|description|
|
|
270
263
|
|-----|----|-----------|
|
|
271
264
|
|`array`|`Array<a>`|An array of values used to initialize the priority queue|
|
|
272
|
-
|
|
265
|
+
|`?compare`|`(a, a) => Number`|A comparator function used to assign priority to elements|
|
|
273
266
|
|
|
274
267
|
Returns:
|
|
275
268
|
|
|
@@ -279,13 +272,20 @@ Returns:
|
|
|
279
272
|
|
|
280
273
|
### PriorityQueue.**fromList**
|
|
281
274
|
|
|
282
|
-
<details
|
|
283
|
-
<summary
|
|
284
|
-
|
|
275
|
+
<details>
|
|
276
|
+
<summary>Added in <code>0.5.3</code></summary>
|
|
277
|
+
<table>
|
|
278
|
+
<thead>
|
|
279
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
280
|
+
</thead>
|
|
281
|
+
<tbody>
|
|
282
|
+
<tr><td><code>0.6.0</code></td><td>Made `compare` a default argument</td></tr>
|
|
283
|
+
</tbody>
|
|
284
|
+
</table>
|
|
285
285
|
</details>
|
|
286
286
|
|
|
287
287
|
```grain
|
|
288
|
-
fromList : (List<a>, ((a, a)
|
|
288
|
+
fromList : (list: List<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
|
|
289
289
|
```
|
|
290
290
|
|
|
291
291
|
Constructs a new priority queue initialized with the elements in the list
|
|
@@ -299,7 +299,7 @@ Parameters:
|
|
|
299
299
|
|param|type|description|
|
|
300
300
|
|-----|----|-----------|
|
|
301
301
|
|`list`|`List<a>`|A list of values used to initialize the priority queue|
|
|
302
|
-
|
|
302
|
+
|`?compare`|`(a, a) => Number`|A comparator function used to assign priority to elements|
|
|
303
303
|
|
|
304
304
|
Returns:
|
|
305
305
|
|
|
@@ -307,3 +307,371 @@ Returns:
|
|
|
307
307
|
|----|-----------|
|
|
308
308
|
|`PriorityQueue<a>`|A priority queue containing the elements from the list|
|
|
309
309
|
|
|
310
|
+
## PriorityQueue.Immutable
|
|
311
|
+
|
|
312
|
+
An immutable priority queue implementation.
|
|
313
|
+
|
|
314
|
+
<details>
|
|
315
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
316
|
+
<table>
|
|
317
|
+
<thead>
|
|
318
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
319
|
+
</thead>
|
|
320
|
+
<tbody>
|
|
321
|
+
<tr><td><code>0.5.4</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
322
|
+
</tbody>
|
|
323
|
+
</table>
|
|
324
|
+
</details>
|
|
325
|
+
|
|
326
|
+
### Types
|
|
327
|
+
|
|
328
|
+
Type declarations included in the PriorityQueue.Immutable module.
|
|
329
|
+
|
|
330
|
+
#### PriorityQueue.Immutable.**PriorityQueue**
|
|
331
|
+
|
|
332
|
+
```grain
|
|
333
|
+
type PriorityQueue<a>
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Immutable data structure which maintains a priority order for its elements.
|
|
337
|
+
|
|
338
|
+
### Values
|
|
339
|
+
|
|
340
|
+
Functions and constants included in the PriorityQueue.Immutable module.
|
|
341
|
+
|
|
342
|
+
#### PriorityQueue.Immutable.**empty**
|
|
343
|
+
|
|
344
|
+
<details>
|
|
345
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
346
|
+
<table>
|
|
347
|
+
<thead>
|
|
348
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
349
|
+
</thead>
|
|
350
|
+
<tbody>
|
|
351
|
+
<tr><td><code>0.5.4</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
352
|
+
</tbody>
|
|
353
|
+
</table>
|
|
354
|
+
</details>
|
|
355
|
+
|
|
356
|
+
```grain
|
|
357
|
+
empty : PriorityQueue<a>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
An empty priority queue with the default `compare` comparator.
|
|
361
|
+
|
|
362
|
+
#### PriorityQueue.Immutable.**make**
|
|
363
|
+
|
|
364
|
+
<details>
|
|
365
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
366
|
+
<table>
|
|
367
|
+
<thead>
|
|
368
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
369
|
+
</thead>
|
|
370
|
+
<tbody>
|
|
371
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module with `compare` being a required argument</td></tr>
|
|
372
|
+
</tbody>
|
|
373
|
+
</table>
|
|
374
|
+
</details>
|
|
375
|
+
|
|
376
|
+
```grain
|
|
377
|
+
make : (?compare: ((a, a) => Number)) => PriorityQueue<a>
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Creates a new priority queue with a comparator function, which is used to
|
|
381
|
+
determine priority of elements. The comparator function takes two elements
|
|
382
|
+
and must return 0 if both share priority, a positive number if the first
|
|
383
|
+
has greater priority, and a negative number if the first has less priority.
|
|
384
|
+
|
|
385
|
+
Parameters:
|
|
386
|
+
|
|
387
|
+
|param|type|description|
|
|
388
|
+
|-----|----|-----------|
|
|
389
|
+
|`?compare`|`(a, a) => Number`|The comparator function used to indicate priority order|
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
|
|
393
|
+
|type|description|
|
|
394
|
+
|----|-----------|
|
|
395
|
+
|`PriorityQueue<a>`|An empty priority queue|
|
|
396
|
+
|
|
397
|
+
Examples:
|
|
398
|
+
|
|
399
|
+
```grain
|
|
400
|
+
PriorityQueue.Immutable.make(compare) // creates a min priority queue of numbers using the compare pervasive
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
```grain
|
|
404
|
+
PriorityQueue.Immutable.make((a, b) => String.length(b) - String.length(a)) // creates a priority queue by string length (longest to shortest)
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
#### PriorityQueue.Immutable.**size**
|
|
408
|
+
|
|
409
|
+
<details>
|
|
410
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
411
|
+
<table>
|
|
412
|
+
<thead>
|
|
413
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
414
|
+
</thead>
|
|
415
|
+
<tbody>
|
|
416
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
417
|
+
</tbody>
|
|
418
|
+
</table>
|
|
419
|
+
</details>
|
|
420
|
+
|
|
421
|
+
```grain
|
|
422
|
+
size : (pq: PriorityQueue<a>) => Number
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Gets the number of elements in a priority queue.
|
|
426
|
+
|
|
427
|
+
Parameters:
|
|
428
|
+
|
|
429
|
+
|param|type|description|
|
|
430
|
+
|-----|----|-----------|
|
|
431
|
+
|`pq`|`PriorityQueue<a>`|The priority queue to inspect|
|
|
432
|
+
|
|
433
|
+
Returns:
|
|
434
|
+
|
|
435
|
+
|type|description|
|
|
436
|
+
|----|-----------|
|
|
437
|
+
|`Number`|The number of elements in the priority queue|
|
|
438
|
+
|
|
439
|
+
#### PriorityQueue.Immutable.**isEmpty**
|
|
440
|
+
|
|
441
|
+
<details>
|
|
442
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
443
|
+
<table>
|
|
444
|
+
<thead>
|
|
445
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
446
|
+
</thead>
|
|
447
|
+
<tbody>
|
|
448
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
449
|
+
</tbody>
|
|
450
|
+
</table>
|
|
451
|
+
</details>
|
|
452
|
+
|
|
453
|
+
```grain
|
|
454
|
+
isEmpty : (pq: PriorityQueue<a>) => Bool
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
Determines if the priority queue contains no elements.
|
|
458
|
+
|
|
459
|
+
Parameters:
|
|
460
|
+
|
|
461
|
+
|param|type|description|
|
|
462
|
+
|-----|----|-----------|
|
|
463
|
+
|`pq`|`PriorityQueue<a>`|The priority queue to check|
|
|
464
|
+
|
|
465
|
+
Returns:
|
|
466
|
+
|
|
467
|
+
|type|description|
|
|
468
|
+
|----|-----------|
|
|
469
|
+
|`Bool`|`true` if the priority queue is empty and `false` otherwise|
|
|
470
|
+
|
|
471
|
+
#### PriorityQueue.Immutable.**push**
|
|
472
|
+
|
|
473
|
+
<details>
|
|
474
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
475
|
+
<table>
|
|
476
|
+
<thead>
|
|
477
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
478
|
+
</thead>
|
|
479
|
+
<tbody>
|
|
480
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
481
|
+
</tbody>
|
|
482
|
+
</table>
|
|
483
|
+
</details>
|
|
484
|
+
|
|
485
|
+
```grain
|
|
486
|
+
push : (val: a, pq: PriorityQueue<a>) => PriorityQueue<a>
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Produces a new priority queue by inserting the given element into the given priority queue.
|
|
490
|
+
|
|
491
|
+
Parameters:
|
|
492
|
+
|
|
493
|
+
|param|type|description|
|
|
494
|
+
|-----|----|-----------|
|
|
495
|
+
|`val`|`a`|The value to add into the priority queue|
|
|
496
|
+
|`pq`|`PriorityQueue<a>`|The priority queue|
|
|
497
|
+
|
|
498
|
+
Returns:
|
|
499
|
+
|
|
500
|
+
|type|description|
|
|
501
|
+
|----|-----------|
|
|
502
|
+
|`PriorityQueue<a>`|A new priority queue with the given element inserted|
|
|
503
|
+
|
|
504
|
+
#### PriorityQueue.Immutable.**peek**
|
|
505
|
+
|
|
506
|
+
<details>
|
|
507
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
508
|
+
<table>
|
|
509
|
+
<thead>
|
|
510
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
511
|
+
</thead>
|
|
512
|
+
<tbody>
|
|
513
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
514
|
+
</tbody>
|
|
515
|
+
</table>
|
|
516
|
+
</details>
|
|
517
|
+
|
|
518
|
+
```grain
|
|
519
|
+
peek : (pq: PriorityQueue<a>) => Option<a>
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
Retrieves the highest priority element in the priority queue. It is not
|
|
523
|
+
removed from the queue.
|
|
524
|
+
|
|
525
|
+
Parameters:
|
|
526
|
+
|
|
527
|
+
|param|type|description|
|
|
528
|
+
|-----|----|-----------|
|
|
529
|
+
|`pq`|`PriorityQueue<a>`|The priority queue to inspect|
|
|
530
|
+
|
|
531
|
+
Returns:
|
|
532
|
+
|
|
533
|
+
|type|description|
|
|
534
|
+
|----|-----------|
|
|
535
|
+
|`Option<a>`|`Some(value)` containing the highest priority element or `None` if the priority queue is empty|
|
|
536
|
+
|
|
537
|
+
#### PriorityQueue.Immutable.**pop**
|
|
538
|
+
|
|
539
|
+
<details>
|
|
540
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
541
|
+
<table>
|
|
542
|
+
<thead>
|
|
543
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
544
|
+
</thead>
|
|
545
|
+
<tbody>
|
|
546
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
547
|
+
</tbody>
|
|
548
|
+
</table>
|
|
549
|
+
</details>
|
|
550
|
+
|
|
551
|
+
```grain
|
|
552
|
+
pop : (pq: PriorityQueue<a>) => PriorityQueue<a>
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
Produces a new priority queue without the highest priority element in the
|
|
556
|
+
given priority queue. If the input priority queue is empty, this function will
|
|
557
|
+
return it.
|
|
558
|
+
|
|
559
|
+
Parameters:
|
|
560
|
+
|
|
561
|
+
|param|type|description|
|
|
562
|
+
|-----|----|-----------|
|
|
563
|
+
|`pq`|`PriorityQueue<a>`|The priority queue|
|
|
564
|
+
|
|
565
|
+
Returns:
|
|
566
|
+
|
|
567
|
+
|type|description|
|
|
568
|
+
|----|-----------|
|
|
569
|
+
|`PriorityQueue<a>`|A new priority queue without the highest priority element|
|
|
570
|
+
|
|
571
|
+
#### PriorityQueue.Immutable.**drain**
|
|
572
|
+
|
|
573
|
+
<details>
|
|
574
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
575
|
+
<table>
|
|
576
|
+
<thead>
|
|
577
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
578
|
+
</thead>
|
|
579
|
+
<tbody>
|
|
580
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module</td></tr>
|
|
581
|
+
</tbody>
|
|
582
|
+
</table>
|
|
583
|
+
</details>
|
|
584
|
+
|
|
585
|
+
```grain
|
|
586
|
+
drain : (pq: PriorityQueue<a>) => List<a>
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
Produces a list of all elements in the priority queue in priority order.
|
|
590
|
+
|
|
591
|
+
Parameters:
|
|
592
|
+
|
|
593
|
+
|param|type|description|
|
|
594
|
+
|-----|----|-----------|
|
|
595
|
+
|`pq`|`PriorityQueue<a>`|The priority queue to drain|
|
|
596
|
+
|
|
597
|
+
Returns:
|
|
598
|
+
|
|
599
|
+
|type|description|
|
|
600
|
+
|----|-----------|
|
|
601
|
+
|`List<a>`|A list of all elements in the priority in priority order|
|
|
602
|
+
|
|
603
|
+
#### PriorityQueue.Immutable.**fromList**
|
|
604
|
+
|
|
605
|
+
<details>
|
|
606
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
607
|
+
<table>
|
|
608
|
+
<thead>
|
|
609
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
610
|
+
</thead>
|
|
611
|
+
<tbody>
|
|
612
|
+
<tr><td><code>0.5.3</code></td><td>Originally in `"immutablepriorityqueue"` module with `compare` being a required argument</td></tr>
|
|
613
|
+
</tbody>
|
|
614
|
+
</table>
|
|
615
|
+
</details>
|
|
616
|
+
|
|
617
|
+
```grain
|
|
618
|
+
fromList : (list: List<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
Constructs a new priority queue initialized with the elements in the list
|
|
622
|
+
using a custom comparator function, which is used to determine priority of
|
|
623
|
+
elements. The comparator function takes two elements and must return 0 if
|
|
624
|
+
both share priority, a positive number if the first has greater priority,
|
|
625
|
+
and a negative number if the first has less priority.
|
|
626
|
+
|
|
627
|
+
Parameters:
|
|
628
|
+
|
|
629
|
+
|param|type|description|
|
|
630
|
+
|-----|----|-----------|
|
|
631
|
+
|`list`|`List<a>`|A list of values used to initialize the priority queue|
|
|
632
|
+
|`?compare`|`(a, a) => Number`|A comparator function used to assign priority to elements|
|
|
633
|
+
|
|
634
|
+
Returns:
|
|
635
|
+
|
|
636
|
+
|type|description|
|
|
637
|
+
|----|-----------|
|
|
638
|
+
|`PriorityQueue<a>`|A priority queue containing the elements from the list|
|
|
639
|
+
|
|
640
|
+
#### PriorityQueue.Immutable.**fromArray**
|
|
641
|
+
|
|
642
|
+
<details>
|
|
643
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
644
|
+
<table>
|
|
645
|
+
<thead>
|
|
646
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
647
|
+
</thead>
|
|
648
|
+
<tbody>
|
|
649
|
+
<tr><td><code>0.5.4</code></td><td>Originally in `"immutablepriorityqueue"` module with `compare` being a required argument</td></tr>
|
|
650
|
+
</tbody>
|
|
651
|
+
</table>
|
|
652
|
+
</details>
|
|
653
|
+
|
|
654
|
+
```grain
|
|
655
|
+
fromArray :
|
|
656
|
+
(array: Array<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
Constructs a new priority queue initialized with the elements in the array
|
|
660
|
+
using a custom comparator function, which is used to determine priority of
|
|
661
|
+
elements. The comparator function takes two elements and must return 0 if
|
|
662
|
+
both share priority, a positive number if the first has greater priority,
|
|
663
|
+
and a negative number if the first has less priority.
|
|
664
|
+
|
|
665
|
+
Parameters:
|
|
666
|
+
|
|
667
|
+
|param|type|description|
|
|
668
|
+
|-----|----|-----------|
|
|
669
|
+
|`array`|`Array<a>`|An array of values used to initialize the priority queue|
|
|
670
|
+
|`?compare`|`(a, a) => Number`|A comparator function used to assign priority to elements|
|
|
671
|
+
|
|
672
|
+
Returns:
|
|
673
|
+
|
|
674
|
+
|type|description|
|
|
675
|
+
|----|-----------|
|
|
676
|
+
|`PriorityQueue<a>`|A priority queue containing the elements from the array|
|
|
677
|
+
|