@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.
Files changed (155) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +47 -37
  21. package/hash.md +21 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2084 -0
  31. package/json.md +608 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +191 -172
  92. package/runtime/numberUtils.md +17 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +540 -242
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
package/float64.md CHANGED
@@ -10,12 +10,28 @@ No other changes yet.
10
10
  </details>
11
11
 
12
12
  ```grain
13
- import Float64 from "float64"
13
+ from "float64" include Float64
14
14
  ```
15
15
 
16
- ## Constants
16
+ ```grain
17
+ 5.0d
18
+ ```
19
+
20
+ ```grain
21
+ -5.0d
22
+ ```
23
+
24
+ ```grain
25
+ Infinityd
26
+ ```
27
+
28
+ ```grain
29
+ NaNd
30
+ ```
31
+
32
+ ## Values
17
33
 
18
- Float64 constant values.
34
+ Functions and constants included in the Float64 module.
19
35
 
20
36
  ### Float64.**infinity**
21
37
 
@@ -29,6 +45,7 @@ infinity : Float64
29
45
  ```
30
46
 
31
47
  Infinity represented as a Float64 value.
48
+ This is an alternative to the `Infinityd` literal.
32
49
 
33
50
  ### Float64.**nan**
34
51
 
@@ -42,6 +59,7 @@ nan : Float64
42
59
  ```
43
60
 
44
61
  NaN (Not a Number) represented as a Float64 value.
62
+ This is an alternative to the `NaNd` literal.
45
63
 
46
64
  ### Float64.**pi**
47
65
 
@@ -82,10 +100,6 @@ e : Float64
82
100
 
83
101
  Euler's number represented as a Float64 value.
84
102
 
85
- ## Conversions
86
-
87
- Functions for converting between Numbers and the Float64 type.
88
-
89
103
  ### Float64.**fromNumber**
90
104
 
91
105
  <details disabled>
@@ -94,7 +108,7 @@ No other changes yet.
94
108
  </details>
95
109
 
96
110
  ```grain
97
- fromNumber : Number -> Float64
111
+ fromNumber : (number: Number) => Float64
98
112
  ```
99
113
 
100
114
  Converts a Number to a Float64.
@@ -119,7 +133,7 @@ No other changes yet.
119
133
  </details>
120
134
 
121
135
  ```grain
122
- toNumber : Float64 -> Number
136
+ toNumber : (float: Float64) => Number
123
137
  ```
124
138
 
125
139
  Converts a Float64 to a Number.
@@ -136,19 +150,22 @@ Returns:
136
150
  |----|-----------|
137
151
  |`Number`|The Float64 represented as a Number|
138
152
 
139
- ## Operations
140
-
141
- Mathematical operations for Float64 values.
142
-
143
- ### Float64.**add**
144
-
145
- <details disabled>
146
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
147
- No other changes yet.
153
+ ### Float64.**(+)**
154
+
155
+ <details>
156
+ <summary>Added in <code>0.6.0</code></summary>
157
+ <table>
158
+ <thead>
159
+ <tr><th>version</th><th>changes</th></tr>
160
+ </thead>
161
+ <tbody>
162
+ <tr><td><code>0.2.0</code></td><td>Originally named `add`</td></tr>
163
+ </tbody>
164
+ </table>
148
165
  </details>
149
166
 
150
167
  ```grain
151
- add : (Float64, Float64) -> Float64
168
+ (+) : (x: Float64, y: Float64) => Float64
152
169
  ```
153
170
 
154
171
  Computes the sum of its operands.
@@ -166,15 +183,29 @@ Returns:
166
183
  |----|-----------|
167
184
  |`Float64`|The sum of the two operands|
168
185
 
169
- ### Float64.**sub**
186
+ Examples:
170
187
 
171
- <details disabled>
172
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
173
- No other changes yet.
188
+ ```grain
189
+ use Float64.{ (+) }
190
+ assert 1.0d + 1.0d == 2.0d
191
+ ```
192
+
193
+ ### Float64.**(-)**
194
+
195
+ <details>
196
+ <summary>Added in <code>0.6.0</code></summary>
197
+ <table>
198
+ <thead>
199
+ <tr><th>version</th><th>changes</th></tr>
200
+ </thead>
201
+ <tbody>
202
+ <tr><td><code>0.2.0</code></td><td>Originally named `sub`</td></tr>
203
+ </tbody>
204
+ </table>
174
205
  </details>
175
206
 
176
207
  ```grain
177
- sub : (Float64, Float64) -> Float64
208
+ (-) : (x: Float64, y: Float64) => Float64
178
209
  ```
179
210
 
180
211
  Computes the difference of its operands.
@@ -192,15 +223,29 @@ Returns:
192
223
  |----|-----------|
193
224
  |`Float64`|The difference of the two operands|
194
225
 
195
- ### Float64.**mul**
226
+ Examples:
196
227
 
197
- <details disabled>
198
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
199
- No other changes yet.
228
+ ```grain
229
+ use Float64.{ (-) }
230
+ assert 5.0d - 4.0d == 1.0d
231
+ ```
232
+
233
+ ### Float64.**(*)**
234
+
235
+ <details>
236
+ <summary>Added in <code>0.6.0</code></summary>
237
+ <table>
238
+ <thead>
239
+ <tr><th>version</th><th>changes</th></tr>
240
+ </thead>
241
+ <tbody>
242
+ <tr><td><code>0.2.0</code></td><td>Originally named `mul`</td></tr>
243
+ </tbody>
244
+ </table>
200
245
  </details>
201
246
 
202
247
  ```grain
203
- mul : (Float64, Float64) -> Float64
248
+ (*) : (x: Float64, y: Float64) => Float64
204
249
  ```
205
250
 
206
251
  Computes the product of its operands.
@@ -218,15 +263,29 @@ Returns:
218
263
  |----|-----------|
219
264
  |`Float64`|The product of the two operands|
220
265
 
221
- ### Float64.**div**
266
+ Examples:
222
267
 
223
- <details disabled>
224
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
225
- No other changes yet.
268
+ ```grain
269
+ use Float64.{ (*) }
270
+ assert -5.0d * 4.0d == -20.0d
271
+ ```
272
+
273
+ ### Float64.**(/)**
274
+
275
+ <details>
276
+ <summary>Added in <code>0.6.0</code></summary>
277
+ <table>
278
+ <thead>
279
+ <tr><th>version</th><th>changes</th></tr>
280
+ </thead>
281
+ <tbody>
282
+ <tr><td><code>0.2.0</code></td><td>Originally named `div`</td></tr>
283
+ </tbody>
284
+ </table>
226
285
  </details>
227
286
 
228
287
  ```grain
229
- div : (Float64, Float64) -> Float64
288
+ (/) : (x: Float64, y: Float64) => Float64
230
289
  ```
231
290
 
232
291
  Computes the quotient of its operands.
@@ -244,19 +303,29 @@ Returns:
244
303
  |----|-----------|
245
304
  |`Float64`|The quotient of the two operands|
246
305
 
247
- ## Comparisons
248
-
249
- Functions for comparing Float64 values.
306
+ Examples:
250
307
 
251
- ### Float64.**lt**
308
+ ```grain
309
+ use Float64.{ (/) }
310
+ assert 25.0d / 4.0d == 6.25d
311
+ ```
252
312
 
253
- <details disabled>
254
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
255
- No other changes yet.
313
+ ### Float64.**(<)**
314
+
315
+ <details>
316
+ <summary>Added in <code>0.6.0</code></summary>
317
+ <table>
318
+ <thead>
319
+ <tr><th>version</th><th>changes</th></tr>
320
+ </thead>
321
+ <tbody>
322
+ <tr><td><code>0.2.0</code></td><td>Originally named `lt`</td></tr>
323
+ </tbody>
324
+ </table>
256
325
  </details>
257
326
 
258
327
  ```grain
259
- lt : (Float64, Float64) -> Bool
328
+ (<) : (x: Float64, y: Float64) => Bool
260
329
  ```
261
330
 
262
331
  Checks if the first value is less than the second value.
@@ -274,15 +343,29 @@ Returns:
274
343
  |----|-----------|
275
344
  |`Bool`|`true` if the first value is less than the second value or `false` otherwise|
276
345
 
277
- ### Float64.**gt**
346
+ Examples:
278
347
 
279
- <details disabled>
280
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
281
- No other changes yet.
348
+ ```grain
349
+ use Float64.{ (<) }
350
+ assert -5.0d < 5.0d
351
+ ```
352
+
353
+ ### Float64.**(>)**
354
+
355
+ <details>
356
+ <summary>Added in <code>0.6.0</code></summary>
357
+ <table>
358
+ <thead>
359
+ <tr><th>version</th><th>changes</th></tr>
360
+ </thead>
361
+ <tbody>
362
+ <tr><td><code>0.2.0</code></td><td>Originally named `gt`</td></tr>
363
+ </tbody>
364
+ </table>
282
365
  </details>
283
366
 
284
367
  ```grain
285
- gt : (Float64, Float64) -> Bool
368
+ (>) : (x: Float64, y: Float64) => Bool
286
369
  ```
287
370
 
288
371
  Checks if the first value is greater than the second value.
@@ -300,15 +383,29 @@ Returns:
300
383
  |----|-----------|
301
384
  |`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
302
385
 
303
- ### Float64.**lte**
386
+ Examples:
304
387
 
305
- <details disabled>
306
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
307
- No other changes yet.
388
+ ```grain
389
+ use Float64.{ (>) }
390
+ assert 6.0d > 5.0d
391
+ ```
392
+
393
+ ### Float64.**(<=)**
394
+
395
+ <details>
396
+ <summary>Added in <code>0.6.0</code></summary>
397
+ <table>
398
+ <thead>
399
+ <tr><th>version</th><th>changes</th></tr>
400
+ </thead>
401
+ <tbody>
402
+ <tr><td><code>0.2.0</code></td><td>Originally named `lte`</td></tr>
403
+ </tbody>
404
+ </table>
308
405
  </details>
309
406
 
310
407
  ```grain
311
- lte : (Float64, Float64) -> Bool
408
+ (<=) : (x: Float64, y: Float64) => Bool
312
409
  ```
313
410
 
314
411
  Checks if the first value is less than or equal to the second value.
@@ -326,15 +423,34 @@ Returns:
326
423
  |----|-----------|
327
424
  |`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
328
425
 
329
- ### Float64.**gte**
426
+ Examples:
330
427
 
331
- <details disabled>
332
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
333
- No other changes yet.
428
+ ```grain
429
+ use Float64.{ (<=) }
430
+ assert 1.0d <= 2.0d
431
+ ```
432
+
433
+ ```grain
434
+ use Float64.{ (<=) }
435
+ assert 2.0d <= 2.0d
436
+ ```
437
+
438
+ ### Float64.**(>=)**
439
+
440
+ <details>
441
+ <summary>Added in <code>0.6.0</code></summary>
442
+ <table>
443
+ <thead>
444
+ <tr><th>version</th><th>changes</th></tr>
445
+ </thead>
446
+ <tbody>
447
+ <tr><td><code>0.2.0</code></td><td>Originally named `gte`</td></tr>
448
+ </tbody>
449
+ </table>
334
450
  </details>
335
451
 
336
452
  ```grain
337
- gte : (Float64, Float64) -> Bool
453
+ (>=) : (x: Float64, y: Float64) => Bool
338
454
  ```
339
455
 
340
456
  Checks if the first value is greater than or equal to the second value.
@@ -352,3 +468,15 @@ Returns:
352
468
  |----|-----------|
353
469
  |`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
354
470
 
471
+ Examples:
472
+
473
+ ```grain
474
+ use Float64.{ (>=) }
475
+ assert 5.0d >= 2.0d
476
+ ```
477
+
478
+ ```grain
479
+ use Float64.{ (>=) }
480
+ assert -1.0d >= -1.0d
481
+ ```
482
+
package/hash.gr CHANGED
@@ -1,39 +1,46 @@
1
1
  /**
2
- * @module Hash: Utilities for hashing any value.
3
- * @example import Hash from "hash"
2
+ * Utilities for hashing any value.
3
+ *
4
+ * @example from "hash" include Hash
5
+ *
6
+ * @example Hash.hash(1)
7
+ * @example Hash.hash("Hello World")
4
8
  *
5
9
  * @since v0.1.0
6
10
  */
11
+ module Hash
7
12
 
8
13
  /**
9
14
  This module implements MurmurHash3 for Grain data types.
10
15
  https://en.wikipedia.org/wiki/MurmurHash
11
16
  */
12
-
13
- import WasmI32, {
14
- add as (+),
15
- sub as (-),
16
- mul as (*),
17
+ from "runtime/unsafe/wasmi32" include WasmI32
18
+ use WasmI32.{
19
+ (+),
20
+ (-),
21
+ (*),
17
22
  remU as (%),
18
- xor as (^),
19
- shrU as (>>>),
20
- shl as (<<),
21
- and as (&),
22
- or as (|),
23
- eq as (==),
24
- ne as (!=),
23
+ (^),
24
+ (>>>),
25
+ (<<),
26
+ (&),
27
+ (|),
28
+ (==),
29
+ (!=),
25
30
  gtU as (>),
26
31
  ltU as (<),
27
- } from "runtime/unsafe/wasmi32"
28
- import WasmI64 from "runtime/unsafe/wasmi64"
29
- import Tags from "runtime/unsafe/tags"
32
+ }
33
+ from "runtime/unsafe/wasmi64" include WasmI64
34
+ from "runtime/unsafe/tags" include Tags
30
35
 
31
- import { tagSimpleNumber } from "runtime/dataStructures"
32
- import { coerceNumberToWasmI32 } from "runtime/numbers"
33
- import BI from "runtime/bigint"
36
+ from "runtime/dataStructures" include DataStructures
37
+ use DataStructures.{ tagSimpleNumber }
38
+ from "runtime/numbers" include Numbers
39
+ use Numbers.{ coerceNumberToWasmI32 }
40
+ from "runtime/bigint" include Bigint as BI
34
41
 
35
- import Random from "sys/random"
36
- import Result from "result"
42
+ from "wasi/random" include Random
43
+ from "result" include Result
37
44
 
38
45
  @unsafe
39
46
  let seed = {
@@ -73,9 +80,10 @@ let hash32 = k => {
73
80
 
74
81
  @unsafe
75
82
  let hash64 = k => {
83
+ use WasmI64.{ (>>>) }
76
84
  // convenience function for hashing 64-bit values
77
85
  hash32(WasmI32.wrapI64(k))
78
- hash32(WasmI32.wrapI64(WasmI64.shrU(k, 32N)))
86
+ hash32(WasmI32.wrapI64(k >>> 32N))
79
87
  }
80
88
 
81
89
  @unsafe
@@ -107,13 +115,12 @@ let rec hashOne = (val, depth) => {
107
115
  } else if ((val & Tags._GRAIN_NUMBER_TAG_MASK) != 0n) {
108
116
  hash32(val)
109
117
  } else if (
110
- (val & Tags._GRAIN_GENERIC_TAG_MASK) == Tags._GRAIN_GENERIC_HEAP_TAG_TYPE
118
+ (val & Tags._GRAIN_GENERIC_TAG_MASK) ==
119
+ Tags._GRAIN_GENERIC_HEAP_TAG_TYPE
111
120
  ) {
112
121
  let heapPtr = val
113
122
  match (WasmI32.load(heapPtr, 0n)) {
114
- t when (
115
- t == Tags._GRAIN_STRING_HEAP_TAG || t == Tags._GRAIN_BYTES_HEAP_TAG
116
- ) => {
123
+ t when t == Tags._GRAIN_STRING_HEAP_TAG || t == Tags._GRAIN_BYTES_HEAP_TAG => {
117
124
  let length = WasmI32.load(heapPtr, 4n)
118
125
  let extra = length % 4n
119
126
  let l = length - extra
@@ -182,9 +189,6 @@ let rec hashOne = (val, depth) => {
182
189
  t when t == Tags._GRAIN_BOXED_NUM_HEAP_TAG => {
183
190
  let tag = WasmI32.load(heapPtr, 4n)
184
191
  match (tag) {
185
- t when t == Tags._GRAIN_INT32_BOXED_NUM_TAG => {
186
- hash32(WasmI32.load(heapPtr, 8n))
187
- },
188
192
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
189
193
  hash32(WasmI32.load(heapPtr, 8n))
190
194
  hash32(WasmI32.load(heapPtr, 12n))
@@ -198,9 +202,6 @@ let rec hashOne = (val, depth) => {
198
202
  hash64(BI.getLimb(heapPtr, i))
199
203
  }
200
204
  },
201
- t when t == Tags._GRAIN_FLOAT32_BOXED_NUM_TAG => {
202
- hash32(WasmI32.load(heapPtr, 8n))
203
- },
204
205
  t when t == Tags._GRAIN_FLOAT64_BOXED_NUM_TAG => {
205
206
  hash32(WasmI32.load(heapPtr, 8n))
206
207
  hash32(WasmI32.load(heapPtr, 12n))
@@ -214,6 +215,15 @@ let rec hashOne = (val, depth) => {
214
215
  },
215
216
  }
216
217
  },
218
+ t when t == Tags._GRAIN_INT32_HEAP_TAG ||
219
+ t == Tags._GRAIN_FLOAT32_HEAP_TAG ||
220
+ t == Tags._GRAIN_UINT32_HEAP_TAG => {
221
+ hash32(WasmI32.load(heapPtr, 4n))
222
+ },
223
+ t when t == Tags._GRAIN_UINT64_HEAP_TAG => {
224
+ hash32(WasmI32.load(heapPtr, 8n))
225
+ hash32(WasmI32.load(heapPtr, 12n))
226
+ },
217
227
  _ => {
218
228
  hash32(heapPtr)
219
229
  },
@@ -223,9 +233,6 @@ let rec hashOne = (val, depth) => {
223
233
  hash32(val)
224
234
  }
225
235
  }
226
- /**
227
- * @section Values: Functions for hashing.
228
- */
229
236
 
230
237
  /**
231
238
  * A generic hash function that produces an integer from any value. If `a == b` then `Hash.hash(a) == Hash.hash(b)`.
@@ -233,10 +240,13 @@ let rec hashOne = (val, depth) => {
233
240
  * @param anything: The value to hash
234
241
  * @returns A hash for the given value
235
242
  *
243
+ * @example assert Hash.hash(1) == Hash.hash(1)
244
+ * @example assert Hash.hash("Hello World") == Hash.hash("Hello World")
245
+ *
236
246
  * @since v0.1.0
237
247
  */
238
248
  @unsafe
239
- export let hash = anything => {
249
+ provide let hash = anything => {
240
250
  h = seed
241
251
 
242
252
  hashOne(WasmI32.fromGrain(anything), 0n)
package/hash.md CHANGED
@@ -10,12 +10,20 @@ No other changes yet.
10
10
  </details>
11
11
 
12
12
  ```grain
13
- import Hash from "hash"
13
+ from "hash" include Hash
14
+ ```
15
+
16
+ ```grain
17
+ Hash.hash(1)
18
+ ```
19
+
20
+ ```grain
21
+ Hash.hash("Hello World")
14
22
  ```
15
23
 
16
24
  ## Values
17
25
 
18
- Functions for hashing.
26
+ Functions and constants included in the Hash module.
19
27
 
20
28
  ### Hash.**hash**
21
29
 
@@ -25,7 +33,7 @@ No other changes yet.
25
33
  </details>
26
34
 
27
35
  ```grain
28
- hash : a -> Number
36
+ hash : (anything: a) => Number
29
37
  ```
30
38
 
31
39
  A generic hash function that produces an integer from any value. If `a == b` then `Hash.hash(a) == Hash.hash(b)`.
@@ -42,3 +50,13 @@ Returns:
42
50
  |----|-----------|
43
51
  |`Number`|A hash for the given value|
44
52
 
53
+ Examples:
54
+
55
+ ```grain
56
+ assert Hash.hash(1) == Hash.hash(1)
57
+ ```
58
+
59
+ ```grain
60
+ assert Hash.hash("Hello World") == Hash.hash("Hello World")
61
+ ```
62
+