@waku/sds 0.0.1

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.
@@ -0,0 +1,998 @@
1
+ /* Generated by the Nim Compiler v2.2.0 */
2
+ var excHandler = 0;
3
+ var NTI134217745 = {
4
+ size: 0,
5
+ kind: 17,
6
+ base: null,
7
+ node: null,
8
+ finalizer: null
9
+ };
10
+ var NTI134217749 = {
11
+ size: 0,
12
+ kind: 17,
13
+ base: null,
14
+ node: null,
15
+ finalizer: null
16
+ };
17
+ var NTI134217751 = {
18
+ size: 0,
19
+ kind: 17,
20
+ base: null,
21
+ node: null,
22
+ finalizer: null
23
+ };
24
+ var NTI134217743 = {
25
+ size: 0,
26
+ kind: 17,
27
+ base: null,
28
+ node: null,
29
+ finalizer: null
30
+ };
31
+ var NTI33555167 = {
32
+ size: 0,
33
+ kind: 17,
34
+ base: null,
35
+ node: null,
36
+ finalizer: null
37
+ };
38
+ var NTI33555175 = {
39
+ size: 0,
40
+ kind: 22,
41
+ base: null,
42
+ node: null,
43
+ finalizer: null
44
+ };
45
+ var NTI33554449 = {
46
+ size: 0,
47
+ kind: 28,
48
+ base: null,
49
+ node: null,
50
+ finalizer: null
51
+ };
52
+ var NTI33554450 = {
53
+ size: 0,
54
+ kind: 29,
55
+ base: null,
56
+ node: null,
57
+ finalizer: null
58
+ };
59
+ var NTI33555174 = {
60
+ size: 0,
61
+ kind: 22,
62
+ base: null,
63
+ node: null,
64
+ finalizer: null
65
+ };
66
+ var NTI33555171 = {
67
+ size: 0,
68
+ kind: 17,
69
+ base: null,
70
+ node: null,
71
+ finalizer: null
72
+ };
73
+ var NTI33555172 = {
74
+ size: 0,
75
+ kind: 17,
76
+ base: null,
77
+ node: null,
78
+ finalizer: null
79
+ };
80
+ var NTI134217741 = {
81
+ size: 0,
82
+ kind: 17,
83
+ base: null,
84
+ node: null,
85
+ finalizer: null
86
+ };
87
+ var NTI134217742 = {
88
+ size: 0,
89
+ kind: 17,
90
+ base: null,
91
+ node: null,
92
+ finalizer: null
93
+ };
94
+ var NNI134217742 = {
95
+ kind: 2,
96
+ len: 0,
97
+ offset: 0,
98
+ typ: null,
99
+ name: null,
100
+ sons: []
101
+ };
102
+ NTI134217742.node = NNI134217742;
103
+ var NNI134217741 = {
104
+ kind: 2,
105
+ len: 0,
106
+ offset: 0,
107
+ typ: null,
108
+ name: null,
109
+ sons: []
110
+ };
111
+ NTI134217741.node = NNI134217741;
112
+ var NNI33555172 = {
113
+ kind: 2,
114
+ len: 0,
115
+ offset: 0,
116
+ typ: null,
117
+ name: null,
118
+ sons: []
119
+ };
120
+ NTI33555172.node = NNI33555172;
121
+ NTI33555174.base = NTI33555171;
122
+ NTI33555175.base = NTI33555171;
123
+ var NNI33555171 = {
124
+ kind: 2,
125
+ len: 5,
126
+ offset: 0,
127
+ typ: null,
128
+ name: null,
129
+ sons: [
130
+ {
131
+ kind: 1,
132
+ offset: "parent",
133
+ len: 0,
134
+ typ: NTI33555174,
135
+ name: "parent",
136
+ sons: null
137
+ },
138
+ {
139
+ kind: 1,
140
+ offset: "name",
141
+ len: 0,
142
+ typ: NTI33554450,
143
+ name: "name",
144
+ sons: null
145
+ },
146
+ {
147
+ kind: 1,
148
+ offset: "message",
149
+ len: 0,
150
+ typ: NTI33554449,
151
+ name: "msg",
152
+ sons: null
153
+ },
154
+ {
155
+ kind: 1,
156
+ offset: "trace",
157
+ len: 0,
158
+ typ: NTI33554449,
159
+ name: "trace",
160
+ sons: null
161
+ },
162
+ { kind: 1, offset: "up", len: 0, typ: NTI33555175, name: "up", sons: null }
163
+ ]
164
+ };
165
+ NTI33555171.node = NNI33555171;
166
+ var NNI33555167 = {
167
+ kind: 2,
168
+ len: 0,
169
+ offset: 0,
170
+ typ: null,
171
+ name: null,
172
+ sons: []
173
+ };
174
+ NTI33555167.node = NNI33555167;
175
+ NTI33555171.base = NTI33555167;
176
+ NTI33555172.base = NTI33555171;
177
+ NTI134217741.base = NTI33555172;
178
+ NTI134217742.base = NTI134217741;
179
+ var NNI134217743 = {
180
+ kind: 2,
181
+ len: 0,
182
+ offset: 0,
183
+ typ: null,
184
+ name: null,
185
+ sons: []
186
+ };
187
+ NTI134217743.node = NNI134217743;
188
+ NTI134217743.base = NTI134217741;
189
+ var NNI134217751 = {
190
+ kind: 2,
191
+ len: 0,
192
+ offset: 0,
193
+ typ: null,
194
+ name: null,
195
+ sons: []
196
+ };
197
+ NTI134217751.node = NNI134217751;
198
+ NTI134217751.base = NTI33555172;
199
+ var NNI134217749 = {
200
+ kind: 2,
201
+ len: 0,
202
+ offset: 0,
203
+ typ: null,
204
+ name: null,
205
+ sons: []
206
+ };
207
+ NTI134217749.node = NNI134217749;
208
+ NTI134217749.base = NTI33555172;
209
+ var NNI134217745 = {
210
+ kind: 2,
211
+ len: 0,
212
+ offset: 0,
213
+ typ: null,
214
+ name: null,
215
+ sons: []
216
+ };
217
+ NTI134217745.node = NNI134217745;
218
+ NTI134217745.base = NTI33555172;
219
+ function toJSStr(s_p0) {
220
+ var result_33556911 = null;
221
+ var res_33556965 = newSeq__system_u2508(s_p0.length);
222
+ var i_33556966 = 0;
223
+ var j_33556967 = 0;
224
+ {
225
+ Label2: while (true) {
226
+ if (!(i_33556966 < s_p0.length))
227
+ break Label2;
228
+ var c_33556968 = s_p0[i_33556966];
229
+ if (c_33556968 < 128) {
230
+ res_33556965[j_33556967] = String.fromCharCode(c_33556968);
231
+ i_33556966 += 1;
232
+ }
233
+ else {
234
+ var helper_33556994 = newSeq__system_u2508(0);
235
+ Label3: {
236
+ while (true) {
237
+ var code_33556995 = c_33556968.toString(16);
238
+ if ((code_33556995 == null ? 0 : code_33556995.length) == 1) {
239
+ helper_33556994.push("%0");
240
+ }
241
+ else {
242
+ helper_33556994.push("%");
243
+ }
244
+ helper_33556994.push(code_33556995);
245
+ i_33556966 += 1;
246
+ if (s_p0.length <= i_33556966 || s_p0[i_33556966] < 128) {
247
+ break Label3;
248
+ }
249
+ c_33556968 = s_p0[i_33556966];
250
+ }
251
+ }
252
+ ++excHandler;
253
+ try {
254
+ res_33556965[j_33556967] = decodeURIComponent(helper_33556994.join(""));
255
+ --excHandler;
256
+ }
257
+ catch (EXCEPTION) {
258
+ --excHandler;
259
+ res_33556965[j_33556967] = helper_33556994.join("");
260
+ }
261
+ finally {
262
+ }
263
+ }
264
+ j_33556967 += 1;
265
+ }
266
+ }
267
+ if (res_33556965.length < j_33556967) {
268
+ for (var i = res_33556965.length; i < j_33556967; ++i)
269
+ res_33556965.push(null);
270
+ }
271
+ else {
272
+ res_33556965.length = j_33556967;
273
+ }
274
+ result_33556911 = res_33556965.join("");
275
+ return result_33556911;
276
+ }
277
+ function raiseException(e_p0, ename_p1) {
278
+ e_p0.name = ename_p1;
279
+ if (excHandler == 0) {
280
+ unhandledException(e_p0);
281
+ }
282
+ throw e_p0;
283
+ }
284
+ function modInt(a_p0, b_p1) {
285
+ if (b_p1 == 0)
286
+ raiseDivByZero();
287
+ if (b_p1 == -1 && a_p0 == 2147483647)
288
+ raiseOverflow();
289
+ return Math.trunc(a_p0 % b_p1);
290
+ }
291
+ function absInt(a_p0) {
292
+ var Temporary1;
293
+ var result_33557134 = 0;
294
+ if (a_p0 < 0) {
295
+ Temporary1 = a_p0 * -1;
296
+ }
297
+ else {
298
+ Temporary1 = a_p0;
299
+ }
300
+ result_33557134 = Temporary1;
301
+ return result_33557134;
302
+ }
303
+ function divInt(a_p0, b_p1) {
304
+ if (b_p1 == 0)
305
+ raiseDivByZero();
306
+ if (b_p1 == -1 && a_p0 == 2147483647)
307
+ raiseOverflow();
308
+ return Math.trunc(a_p0 / b_p1);
309
+ }
310
+ function mulInt(a_p0, b_p1) {
311
+ var result = a_p0 * b_p1;
312
+ checkOverflowInt(result);
313
+ return result;
314
+ }
315
+ function subInt(a_p0, b_p1) {
316
+ var result = a_p0 - b_p1;
317
+ checkOverflowInt(result);
318
+ return result;
319
+ }
320
+ function addInt(a_p0, b_p1) {
321
+ var result = a_p0 + b_p1;
322
+ checkOverflowInt(result);
323
+ return result;
324
+ }
325
+ function chckRange(i_p0, a_p1, b_p2) {
326
+ var result_33557358 = 0;
327
+ BeforeRet: {
328
+ if (a_p1 <= i_p0 && i_p0 <= b_p2) {
329
+ result_33557358 = i_p0;
330
+ break BeforeRet;
331
+ }
332
+ else {
333
+ raiseRangeError();
334
+ }
335
+ }
336
+ return result_33557358;
337
+ }
338
+ function setConstr() {
339
+ var result = {};
340
+ for (var i = 0; i < arguments.length; ++i) {
341
+ var x = arguments[i];
342
+ if (typeof x == "object") {
343
+ for (var j = x[0]; j <= x[1]; ++j) {
344
+ result[j] = true;
345
+ }
346
+ }
347
+ else {
348
+ result[x] = true;
349
+ }
350
+ }
351
+ return result;
352
+ }
353
+ var ConstSet1 = setConstr(17, 16, 4, 18, 27, 19, 23, 22, 21);
354
+ function nimCopy(dest_p0, src_p1, ti_p2) {
355
+ var result_33557318 = null;
356
+ switch (ti_p2.kind) {
357
+ case 21:
358
+ case 22:
359
+ case 23:
360
+ case 5:
361
+ if (!isFatPointer__system_u2866(ti_p2)) {
362
+ result_33557318 = src_p1;
363
+ }
364
+ else {
365
+ result_33557318 = [src_p1[0], src_p1[1]];
366
+ }
367
+ break;
368
+ case 19:
369
+ if (dest_p0 === null || dest_p0 === undefined) {
370
+ dest_p0 = {};
371
+ }
372
+ else {
373
+ for (var key in dest_p0) {
374
+ delete dest_p0[key];
375
+ }
376
+ }
377
+ for (var key in src_p1) {
378
+ dest_p0[key] = src_p1[key];
379
+ }
380
+ result_33557318 = dest_p0;
381
+ break;
382
+ case 18:
383
+ case 17:
384
+ if (!(ti_p2.base == null)) {
385
+ result_33557318 = nimCopy(dest_p0, src_p1, ti_p2.base);
386
+ }
387
+ else {
388
+ if (ti_p2.kind == 17) {
389
+ result_33557318 =
390
+ dest_p0 === null || dest_p0 === undefined
391
+ ? { m_type: ti_p2 }
392
+ : dest_p0;
393
+ }
394
+ else {
395
+ result_33557318 =
396
+ dest_p0 === null || dest_p0 === undefined ? {} : dest_p0;
397
+ }
398
+ }
399
+ nimCopyAux(result_33557318, src_p1, ti_p2.node);
400
+ break;
401
+ case 4:
402
+ case 16:
403
+ if (ArrayBuffer.isView(src_p1)) {
404
+ if (dest_p0 === null ||
405
+ dest_p0 === undefined ||
406
+ dest_p0.length != src_p1.length) {
407
+ dest_p0 = new src_p1.constructor(src_p1);
408
+ }
409
+ else {
410
+ dest_p0.set(src_p1, 0);
411
+ }
412
+ result_33557318 = dest_p0;
413
+ }
414
+ else {
415
+ if (src_p1 === null) {
416
+ result_33557318 = null;
417
+ }
418
+ else {
419
+ if (dest_p0 === null ||
420
+ dest_p0 === undefined ||
421
+ dest_p0.length != src_p1.length) {
422
+ dest_p0 = new Array(src_p1.length);
423
+ }
424
+ result_33557318 = dest_p0;
425
+ for (var i = 0; i < src_p1.length; ++i) {
426
+ result_33557318[i] = nimCopy(result_33557318[i], src_p1[i], ti_p2.base);
427
+ }
428
+ }
429
+ }
430
+ break;
431
+ case 24:
432
+ case 27:
433
+ if (src_p1 === null) {
434
+ result_33557318 = null;
435
+ }
436
+ else {
437
+ if (dest_p0 === null ||
438
+ dest_p0 === undefined ||
439
+ dest_p0.length != src_p1.length) {
440
+ dest_p0 = new Array(src_p1.length);
441
+ }
442
+ result_33557318 = dest_p0;
443
+ for (var i = 0; i < src_p1.length; ++i) {
444
+ result_33557318[i] = nimCopy(result_33557318[i], src_p1[i], ti_p2.base);
445
+ }
446
+ }
447
+ break;
448
+ case 28:
449
+ if (src_p1 !== null) {
450
+ result_33557318 = src_p1.slice(0);
451
+ }
452
+ break;
453
+ default:
454
+ result_33557318 = src_p1;
455
+ break;
456
+ }
457
+ return result_33557318;
458
+ }
459
+ function chckIndx(i_p0, a_p1, b_p2) {
460
+ var result_33557353 = 0;
461
+ BeforeRet: {
462
+ if (a_p1 <= i_p0 && i_p0 <= b_p2) {
463
+ result_33557353 = i_p0;
464
+ break BeforeRet;
465
+ }
466
+ else {
467
+ raiseIndexError(i_p0, a_p1, b_p2);
468
+ }
469
+ }
470
+ return result_33557353;
471
+ }
472
+ function add__system_u1943(x_p0, x_p0_Idx, y_p1) {
473
+ if (x_p0[x_p0_Idx] === null) {
474
+ x_p0[x_p0_Idx] = [];
475
+ }
476
+ var off = x_p0[x_p0_Idx].length;
477
+ x_p0[x_p0_Idx].length += y_p1.length;
478
+ for (var i = 0; i < y_p1.length; ++i) {
479
+ x_p0[x_p0_Idx][off + i] = y_p1.charCodeAt(i);
480
+ }
481
+ }
482
+ function newSeq__system_u2508(len_p0) {
483
+ var result_33556944 = [];
484
+ result_33556944 = new Array(len_p0);
485
+ for (var i = 0; i < len_p0; ++i) {
486
+ result_33556944[i] = null;
487
+ }
488
+ return result_33556944;
489
+ }
490
+ function unhandledException(e_p0) {
491
+ var buf_33556659 = [[]];
492
+ if (!(e_p0.message.length == 0)) {
493
+ buf_33556659[0].push.apply(buf_33556659[0], [
494
+ 69, 114, 114, 111, 114, 58, 32, 117, 110, 104, 97, 110, 100, 108, 101,
495
+ 100, 32, 101, 120, 99, 101, 112, 116, 105, 111, 110, 58, 32
496
+ ]);
497
+ buf_33556659[0].push.apply(buf_33556659[0], e_p0.message);
498
+ }
499
+ else {
500
+ buf_33556659[0].push.apply(buf_33556659[0], [
501
+ 69, 114, 114, 111, 114, 58, 32, 117, 110, 104, 97, 110, 100, 108, 101,
502
+ 100, 32, 101, 120, 99, 101, 112, 116, 105, 111, 110
503
+ ]);
504
+ }
505
+ buf_33556659[0].push.apply(buf_33556659[0], [32, 91]);
506
+ add__system_u1943(buf_33556659, 0, e_p0.name);
507
+ buf_33556659[0].push.apply(buf_33556659[0], [93, 10]);
508
+ var cbuf_33556660 = toJSStr(buf_33556659[0]);
509
+ if (typeof Error !== "undefined") {
510
+ throw new Error(cbuf_33556660);
511
+ }
512
+ else {
513
+ throw cbuf_33556660;
514
+ }
515
+ }
516
+ function raiseDivByZero() {
517
+ raiseException({
518
+ message: [
519
+ 100, 105, 118, 105, 115, 105, 111, 110, 32, 98, 121, 32, 122, 101, 114,
520
+ 111
521
+ ],
522
+ parent: null,
523
+ m_type: NTI134217742,
524
+ name: null,
525
+ trace: [],
526
+ up: null
527
+ }, "DivByZeroDefect");
528
+ }
529
+ function raiseOverflow() {
530
+ raiseException({
531
+ message: [
532
+ 111, 118, 101, 114, 45, 32, 111, 114, 32, 117, 110, 100, 101, 114, 102,
533
+ 108, 111, 119
534
+ ],
535
+ parent: null,
536
+ m_type: NTI134217743,
537
+ name: null,
538
+ trace: [],
539
+ up: null
540
+ }, "OverflowDefect");
541
+ }
542
+ function checkOverflowInt(a_p0) {
543
+ if (a_p0 > 2147483647 || a_p0 < -2147483648)
544
+ raiseOverflow();
545
+ }
546
+ function raiseRangeError() {
547
+ raiseException({
548
+ message: [
549
+ 118, 97, 108, 117, 101, 32, 111, 117, 116, 32, 111, 102, 32, 114, 97,
550
+ 110, 103, 101
551
+ ],
552
+ parent: null,
553
+ m_type: NTI134217751,
554
+ name: null,
555
+ trace: [],
556
+ up: null
557
+ }, "RangeDefect");
558
+ }
559
+ function addChars__stdZprivateZdigitsutils_u202(result_p0, result_p0_Idx, x_p1, start_p2, n_p3) {
560
+ var Temporary1;
561
+ var old_301990096 = result_p0[result_p0_Idx].length;
562
+ if (result_p0[result_p0_Idx].length <
563
+ ((Temporary1 = chckRange(addInt(old_301990096, n_p3), 0, 2147483647)),
564
+ Temporary1)) {
565
+ for (var i = result_p0[result_p0_Idx].length; i < Temporary1; ++i)
566
+ result_p0[result_p0_Idx].push(0);
567
+ }
568
+ else {
569
+ result_p0[result_p0_Idx].length = Temporary1;
570
+ }
571
+ {
572
+ var iHEX60gensym4_301990110 = 0;
573
+ var i_536870936 = 0;
574
+ {
575
+ Label4: while (true) {
576
+ if (!(i_536870936 < n_p3))
577
+ break Label4;
578
+ iHEX60gensym4_301990110 = i_536870936;
579
+ result_p0[result_p0_Idx][chckIndx(addInt(old_301990096, iHEX60gensym4_301990110), 0, result_p0[result_p0_Idx].length - 1)] = x_p1.charCodeAt(chckIndx(addInt(start_p2, iHEX60gensym4_301990110), 0, x_p1.length - 1));
580
+ i_536870936 = addInt(i_536870936, 1);
581
+ }
582
+ }
583
+ }
584
+ }
585
+ function addChars__stdZprivateZdigitsutils_u198(result_p0, result_p0_Idx, x_p1) {
586
+ addChars__stdZprivateZdigitsutils_u202(result_p0, result_p0_Idx, x_p1, 0, x_p1 == null ? 0 : x_p1.length);
587
+ }
588
+ function addInt__stdZprivateZdigitsutils_u223(result_p0, result_p0_Idx, x_p1) {
589
+ addChars__stdZprivateZdigitsutils_u198(result_p0, result_p0_Idx, x_p1 + "");
590
+ }
591
+ function addInt__stdZprivateZdigitsutils_u241(result_p0, result_p0_Idx, x_p1) {
592
+ addInt__stdZprivateZdigitsutils_u223(result_p0, result_p0_Idx, x_p1);
593
+ }
594
+ function HEX24__systemZdollars_u8(x_p0) {
595
+ var result_385875978 = [[]];
596
+ addInt__stdZprivateZdigitsutils_u241(result_385875978, 0, x_p0);
597
+ return result_385875978[0];
598
+ }
599
+ function isFatPointer__system_u2866(ti_p0) {
600
+ var result_33557300 = false;
601
+ BeforeRet: {
602
+ result_33557300 = !(ConstSet1[ti_p0.base.kind] != undefined);
603
+ break BeforeRet;
604
+ }
605
+ return result_33557300;
606
+ }
607
+ function nimCopyAux(dest_p0, src_p1, n_p2) {
608
+ switch (n_p2.kind) {
609
+ case 0:
610
+ break;
611
+ case 1:
612
+ dest_p0[n_p2.offset] = nimCopy(dest_p0[n_p2.offset], src_p1[n_p2.offset], n_p2.typ);
613
+ break;
614
+ case 2:
615
+ for (var i = 0; i < n_p2.sons.length; i++) {
616
+ nimCopyAux(dest_p0, src_p1, n_p2.sons[i]);
617
+ }
618
+ break;
619
+ case 3:
620
+ dest_p0[n_p2.offset] = nimCopy(dest_p0[n_p2.offset], src_p1[n_p2.offset], n_p2.typ);
621
+ for (var i = 0; i < n_p2.sons.length; ++i) {
622
+ nimCopyAux(dest_p0, src_p1, n_p2.sons[i][1]);
623
+ }
624
+ break;
625
+ }
626
+ }
627
+ function raiseIndexError(i_p0, a_p1, b_p2) {
628
+ var Temporary1;
629
+ if (b_p2 < a_p1) {
630
+ Temporary1 = [
631
+ 105, 110, 100, 101, 120, 32, 111, 117, 116, 32, 111, 102, 32, 98, 111,
632
+ 117, 110, 100, 115, 44, 32, 116, 104, 101, 32, 99, 111, 110, 116, 97, 105,
633
+ 110, 101, 114, 32, 105, 115, 32, 101, 109, 112, 116, 121
634
+ ];
635
+ }
636
+ else {
637
+ Temporary1 = [105, 110, 100, 101, 120, 32].concat(HEX24__systemZdollars_u8(i_p0), [32, 110, 111, 116, 32, 105, 110, 32], HEX24__systemZdollars_u8(a_p1), [32, 46, 46, 32], HEX24__systemZdollars_u8(b_p2));
638
+ }
639
+ raiseException({
640
+ message: nimCopy(null, Temporary1, NTI33554449),
641
+ parent: null,
642
+ m_type: NTI134217749,
643
+ name: null,
644
+ trace: [],
645
+ up: null
646
+ }, "IndexDefect");
647
+ }
648
+ function imul__pureZhashes_u340(a_p0, b_p1) {
649
+ var result_671088983 = 0;
650
+ var mask_671088984 = 65535;
651
+ var aHi_671088989 = ((a_p0 >>> 16) & mask_671088984) >>> 0;
652
+ var aLo_671088990 = (a_p0 & mask_671088984) >>> 0;
653
+ var bHi_671088995 = ((b_p1 >>> 16) & mask_671088984) >>> 0;
654
+ var bLo_671088996 = (b_p1 & mask_671088984) >>> 0;
655
+ result_671088983 =
656
+ (((aLo_671088990 * bLo_671088996) >>> 0) +
657
+ ((((((aHi_671088989 * bLo_671088996) >>> 0) +
658
+ ((aLo_671088990 * bHi_671088995) >>> 0)) >>>
659
+ 0) <<
660
+ 16) >>>
661
+ 0)) >>>
662
+ 0;
663
+ return result_671088983;
664
+ }
665
+ function rotl32__pureZhashes_u361(x_p0, r_p1) {
666
+ var result_671089004 = 0;
667
+ result_671089004 =
668
+ (((x_p0 << r_p1) >>> 0) | (x_p0 >>> subInt(32, r_p1))) >>> 0;
669
+ return result_671089004;
670
+ }
671
+ function murmurHash__pureZhashes_u373(x_p0) {
672
+ var result_671089015 = 0;
673
+ BeforeRet: {
674
+ var size_671089024 = x_p0.length;
675
+ var stepSize_671089025 = 4;
676
+ var n_671089026 = divInt(size_671089024, stepSize_671089025);
677
+ var h1_671089027 = 0;
678
+ var i_671089028 = 0;
679
+ {
680
+ Label2: while (true) {
681
+ if (!(i_671089028 < mulInt(n_671089026, stepSize_671089025)))
682
+ break Label2;
683
+ var k1_671089031 = 0;
684
+ var jHEX60gensym11_671089048 = stepSize_671089025;
685
+ {
686
+ Label4: while (true) {
687
+ if (!(0 < jHEX60gensym11_671089048))
688
+ break Label4;
689
+ jHEX60gensym11_671089048 = subInt(jHEX60gensym11_671089048, 1);
690
+ k1_671089031 =
691
+ (((k1_671089031 << 8) >>> 0) |
692
+ Number(BigInt.asUintN(32, BigInt(x_p0[chckIndx(addInt(i_671089028, jHEX60gensym11_671089048), 0, x_p0.length - 1)])))) >>>
693
+ 0;
694
+ }
695
+ }
696
+ i_671089028 = addInt(i_671089028, stepSize_671089025);
697
+ k1_671089031 = imul__pureZhashes_u340(k1_671089031, 3432918353);
698
+ k1_671089031 = rotl32__pureZhashes_u361(k1_671089031, 15);
699
+ k1_671089031 = imul__pureZhashes_u340(k1_671089031, 461845907);
700
+ h1_671089027 = (h1_671089027 ^ k1_671089031) >>> 0;
701
+ h1_671089027 = rotl32__pureZhashes_u361(h1_671089027, 13);
702
+ h1_671089027 = (((h1_671089027 * 5) >>> 0) + 3864292196) >>> 0;
703
+ }
704
+ }
705
+ var k1_671089066 = 0;
706
+ var rem_671089067 = modInt(size_671089024, stepSize_671089025);
707
+ {
708
+ Label6: while (true) {
709
+ if (!(0 < rem_671089067))
710
+ break Label6;
711
+ rem_671089067 = subInt(rem_671089067, 1);
712
+ k1_671089066 =
713
+ (((k1_671089066 << 8) >>> 0) |
714
+ Number(BigInt.asUintN(32, BigInt(x_p0[chckIndx(addInt(i_671089028, rem_671089067), 0, x_p0.length - 1)])))) >>>
715
+ 0;
716
+ }
717
+ }
718
+ k1_671089066 = imul__pureZhashes_u340(k1_671089066, 3432918353);
719
+ k1_671089066 = rotl32__pureZhashes_u361(k1_671089066, 15);
720
+ k1_671089066 = imul__pureZhashes_u340(k1_671089066, 461845907);
721
+ h1_671089027 = (h1_671089027 ^ k1_671089066) >>> 0;
722
+ h1_671089027 =
723
+ (h1_671089027 ^ Number(BigInt.asUintN(32, BigInt(size_671089024)))) >>> 0;
724
+ h1_671089027 = (h1_671089027 ^ (h1_671089027 >>> 16)) >>> 0;
725
+ h1_671089027 = imul__pureZhashes_u340(h1_671089027, 2246822507);
726
+ h1_671089027 = (h1_671089027 ^ (h1_671089027 >>> 13)) >>> 0;
727
+ h1_671089027 = imul__pureZhashes_u340(h1_671089027, 3266489909);
728
+ h1_671089027 = (h1_671089027 ^ (h1_671089027 >>> 16)) >>> 0;
729
+ result_671089015 = Number(BigInt.asIntN(32, BigInt(h1_671089027)));
730
+ break BeforeRet;
731
+ }
732
+ return result_671089015;
733
+ }
734
+ function hash__pureZhashes_u782(x_p0) {
735
+ var result_671089424 = 0;
736
+ result_671089424 = murmurHash__pureZhashes_u373(x_p0.slice(0, x_p0.length - 1 + 1));
737
+ return result_671089424;
738
+ }
739
+ function hashN__nim95hash_u2(item_p0, n_p1, maxValue_p2) {
740
+ var result_536870918 = 0;
741
+ var hashA_536870919 = modInt(absInt(hash__pureZhashes_u782(item_p0)), maxValue_p2);
742
+ var hashB_536870920 = modInt(absInt(hash__pureZhashes_u782(item_p0.concat([32, 98]))), maxValue_p2);
743
+ result_536870918 = modInt(absInt(addInt(hashA_536870919, mulInt(n_p1, hashB_536870920))), maxValue_p2);
744
+ return result_536870918;
745
+ }
746
+ function sysFatal__stdZassertions_u45(message_p1) {
747
+ raiseException({
748
+ message: nimCopy(null, message_p1, NTI33554449),
749
+ m_type: NTI134217745,
750
+ parent: null,
751
+ name: null,
752
+ trace: [],
753
+ up: null
754
+ }, "AssertionDefect");
755
+ }
756
+ function raiseAssert__stdZassertions_u43(msg_p0) {
757
+ sysFatal__stdZassertions_u45(msg_p0);
758
+ }
759
+ function failedAssertImpl__stdZassertions_u85(msg_p0) {
760
+ raiseAssert__stdZassertions_u43(msg_p0);
761
+ }
762
+ if (!(hashN__nim95hash_u2([100, 117, 109, 109, 121], 0, 1) == 0)) {
763
+ failedAssertImpl__stdZassertions_u85([
764
+ 110, 105, 109, 95, 104, 97, 115, 104, 46, 110, 105, 109, 40, 50, 54, 44, 32,
765
+ 51, 41, 32, 96, 104, 97, 115, 104, 78, 40, 34, 100, 117, 109, 109, 121, 34,
766
+ 44, 32, 48, 44, 32, 49, 41, 32, 61, 61, 32, 48, 96, 32
767
+ ]);
768
+ }
769
+
770
+ // This file contains the probability tables used to determine the optimal number of
771
+ // hash functions (k) and bits per element (m/n) for a Bloom filter.
772
+ //
773
+ // These are used to determine how to construct a Bloom filter that can perform
774
+ // lookups with false-positive rate low enough to be satisfactory.
775
+ /**
776
+ * Table of false positive rates for values of k from 0 to 12, and bits-per-element
777
+ * ratios ranging from 0 up to around 32. Each Float32Array is indexed by mOverN,
778
+ * so kErrors[k][mOverN] gives the estimated false-positive probability.
779
+ *
780
+ * These values mirror commonly used reference data found in Bloom filter literature,
781
+ * such as:
782
+ * https://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
783
+ * https://dl.acm.org/doi/pdf/10.1145/362686.362692
784
+ */
785
+ // prettier-ignore
786
+ const kErrors = [
787
+ new Float32Array([1.0]),
788
+ new Float32Array([1.0, 1.0, 0.3930000000, 0.2830000000, 0.2210000000, 0.1810000000,
789
+ 0.1540000000, 0.1330000000, 0.1180000000, 0.1050000000, 0.0952000000,
790
+ 0.0869000000, 0.0800000000, 0.0740000000, 0.0689000000, 0.0645000000,
791
+ 0.0606000000, 0.0571000000, 0.0540000000, 0.0513000000, 0.0488000000,
792
+ 0.0465000000, 0.0444000000, 0.0425000000, 0.0408000000, 0.0392000000,
793
+ 0.0377000000, 0.0364000000, 0.0351000000, 0.0339000000, 0.0328000000,
794
+ 0.0317000000, 0.0308000000]),
795
+ new Float32Array([1.0, 1.0, 0.4000000000, 0.2370000000, 0.1550000000, 0.1090000000,
796
+ 0.0804000000, 0.0618000000, 0.0489000000, 0.0397000000, 0.0329000000,
797
+ 0.0276000000, 0.0236000000, 0.0203000000, 0.0177000000, 0.0156000000,
798
+ 0.0138000000, 0.0123000000, 0.0111000000, 0.0099800000, 0.0090600000,
799
+ 0.0082500000, 0.0075500000, 0.0069400000, 0.0063900000, 0.0059100000,
800
+ 0.0054800000, 0.0051000000, 0.0047500000, 0.0044400000, 0.0041600000,
801
+ 0.0039000000, 0.0036700000]),
802
+ new Float32Array([1.0, 1.0, 1.0, 0.2530000000, 0.1470000000, 0.0920000000,
803
+ 0.0609000000, 0.0423000000, 0.0306000000, 0.0228000000, 0.0174000000,
804
+ 0.0136000000, 0.0108000000, 0.0087500000, 0.0071800000, 0.0059600000,
805
+ 0.0108000000, 0.0087500000, 0.0071800000, 0.0059600000, 0.0050000000,
806
+ 0.0042300000, 0.0036200000, 0.0031200000, 0.0027000000, 0.0023600000,
807
+ 0.0020700000, 0.0018300000, 0.0016200000, 0.0014500000, 0.0012900000,
808
+ 0.0011600000, 0.0010500000, 0.0009490000, 0.0008620000, 0.0007850000,
809
+ 0.0007170000]),
810
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 0.1600000000, 0.0920000000, 0.0561000000, 0.0359000000,
811
+ 0.0240000000, 0.0166000000, 0.0118000000, 0.0086400000, 0.0064600000,
812
+ 0.0049200000, 0.0038100000, 0.0030000000, 0.0023900000, 0.0019300000,
813
+ 0.0015800000, 0.0013000000, 0.0010800000, 0.0009050000, 0.0007640000,
814
+ 0.0006490000, 0.0005550000, 0.0004780000, 0.0004130000, 0.0003590000,
815
+ 0.0003140000, 0.0002760000, 0.0002430000, 0.0002150000, 0.0001910000]),
816
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 0.1010000000, 0.0578000000, 0.0347000000,
817
+ 0.0217000000, 0.0141000000, 0.0094300000, 0.0065000000, 0.0045900000,
818
+ 0.0033200000, 0.0024400000, 0.0018300000, 0.0013900000, 0.0010700000,
819
+ 0.0008390000, 0.0006630000, 0.0005300000, 0.0004270000, 0.0003470000,
820
+ 0.0002850000, 0.0002350000, 0.0001960000, 0.0001640000, 0.0001380000,
821
+ 0.0001170000, 0.0000996000, 0.0000853000, 0.0000733000, 0.0000633000]),
822
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0638000000, 0.0364000000, 0.0216000000,
823
+ 0.0133000000, 0.0084400000, 0.0055200000, 0.0037100000, 0.0025500000,
824
+ 0.0017900000, 0.0012800000, 0.0009350000, 0.0006920000, 0.0005190000,
825
+ 0.0003940000, 0.0003030000, 0.0002360000, 0.0001850000, 0.0001470000,
826
+ 0.0001170000, 0.0000944000, 0.0000766000, 0.0000626000, 0.0000515000,
827
+ 0.0000426000, 0.0000355000, 0.0000297000, 0.0000250000]),
828
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0229000000, 0.0135000000, 0.0081900000,
829
+ 0.0051300000, 0.0032900000, 0.0021700000, 0.0014600000, 0.0010000000,
830
+ 0.0007020000, 0.0004990000, 0.0003600000, 0.0002640000, 0.0001960000,
831
+ 0.0001470000, 0.0001120000, 0.0000856000, 0.0000663000, 0.0000518000,
832
+ 0.0000408000, 0.0000324000, 0.0000259000, 0.0000209000, 0.0000169000,
833
+ 0.0000138000, 0.0000113000]),
834
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
835
+ 1.0, 0.0145000000, 0.0084600000, 0.0050900000, 0.0031400000, 0.0019900000,
836
+ 0.0012900000, 0.0008520000, 0.0005740000, 0.0003940000, 0.0002750000,
837
+ 0.0001940000, 0.0001400000, 0.0001010000, 0.0000746000, 0.0000555000,
838
+ 0.0000417000, 0.0000316000, 0.0000242000, 0.0000187000, 0.0000146000,
839
+ 0.0000114000, 0.0000090100, 0.0000071600, 0.0000057300]),
840
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0053100000, 0.0031700000,
841
+ 0.0019400000, 0.0012100000, 0.0007750000, 0.0005050000, 0.0003350000,
842
+ 0.0002260000, 0.0001550000, 0.0001080000, 0.0000759000, 0.0000542000,
843
+ 0.0000392000, 0.0000286000, 0.0000211000, 0.0000157000, 0.0000118000,
844
+ 0.0000089600, 0.0000068500, 0.0000052800, 0.0000041000, 0.0000032000]),
845
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0033400000,
846
+ 0.0019800000, 0.0012000000, 0.0007440000, 0.0004700000, 0.0003020000,
847
+ 0.0001980000, 0.0001320000, 0.0000889000, 0.0000609000, 0.0000423000,
848
+ 0.0000297000, 0.0000211000, 0.0000152000, 0.0000110000, 0.0000080700,
849
+ 0.0000059700, 0.0000044500, 0.0000033500, 0.0000025400, 0.0000019400]),
850
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
851
+ 0.0021000000, 0.0012400000, 0.0007470000, 0.0004590000, 0.0002870000,
852
+ 0.0001830000, 0.0001180000, 0.0000777000, 0.0000518000, 0.0000350000,
853
+ 0.0000240000, 0.0000166000, 0.0000116000, 0.0000082300, 0.0000058900,
854
+ 0.0000042500, 0.0000031000, 0.0000022800, 0.0000016900, 0.0000012600]),
855
+ new Float32Array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
856
+ 0.0007780000, 0.0004660000, 0.0002840000, 0.0001760000, 0.0001110000,
857
+ 0.0000712000, 0.0000463000, 0.0000305000, 0.0000204000, 0.0000138000,
858
+ 0.0000094200, 0.0000065200, 0.0000045600, 0.0000032200, 0.0000022900,
859
+ 0.0000016500, 0.0000012000, 0.0000008740]),
860
+ ];
861
+ const KTooLargeError = "K must be <= 12";
862
+ const NoSuitableRatioError = "Specified value of k and error rate not achievable using less than 4 bytes / element.";
863
+ /**
864
+ * Given a number of hash functions (k) and a target false-positive rate (targetError),
865
+ * determines the minimum (m/n) bits-per-element that satisfies the error threshold.
866
+ *
867
+ * In the context of a Bloom filter:
868
+ * - m is the total number of bits in the filter.
869
+ * - n is the number of elements you expect to insert.
870
+ * Thus, (m/n) describes how many bits are assigned per inserted element.
871
+ *
872
+ * Example:
873
+ * ```ts
874
+ * // We want to use 3 hash functions (k=3) and a false-positive rate of 1% (targetError=0.01).
875
+ * const mOverN = getMOverNBitsForK(3, 0.01);
876
+ * // The function will iterate through the error tables and find the smallest m/n that satisfies the error threshold.
877
+ * // In this case, kErrors[3][5] is the first value in the vector kErrors[3] that is less than 0.01 (0.0920000000).
878
+ * console.log(mOverN); // 5
879
+ * ```
880
+ *
881
+ * @param k - The number of hash functions.
882
+ * @param targetError - The desired maximum false-positive rate.
883
+ * @param probabilityTable - An optional table of false-positive probabilities indexed by k.
884
+ * @returns The smallest (m/n) bit ratio for which the false-positive rate is below targetError.
885
+ * @throws If k is out of range or if no suitable ratio can be found.
886
+ */
887
+ function getMOverNBitsForK(k, targetError, probabilityTable = kErrors) {
888
+ // Returns the optimal number of m/n bits for a given k.
889
+ if (k < 0 || k > 12) {
890
+ throw new Error(KTooLargeError);
891
+ }
892
+ for (let mOverN = 2; mOverN < probabilityTable[k].length; mOverN++) {
893
+ if (probabilityTable[k][mOverN] < targetError) {
894
+ return mOverN;
895
+ }
896
+ }
897
+ throw new Error(NoSuitableRatioError);
898
+ }
899
+
900
+ const sizeOfInt = 8;
901
+ /**
902
+ * A probabilistic data structure that tracks memberships in a set.
903
+ * Supports time and space efficient lookups, but may return false-positives.
904
+ * Can never return false-negatives.
905
+ * A bloom filter can tell us if an element is:
906
+ * - Definitely not in the set
907
+ * - Potentially in the set (with a probability depending on the false-positive rate)
908
+ */
909
+ class BloomFilter {
910
+ totalBits;
911
+ data = [];
912
+ kHashes;
913
+ errorRate;
914
+ options;
915
+ hashN;
916
+ constructor(options, hashN) {
917
+ this.options = options;
918
+ let nBitsPerElem;
919
+ let k = options.kHashes ?? 0;
920
+ const forceNBitsPerElem = options.forceNBitsPerElem ?? 0;
921
+ if (k < 1) {
922
+ // Calculate optimal k based on target error rate
923
+ const bitsPerElem = Math.ceil(-1 * (Math.log(options.errorRate) / Math.pow(Math.log(2), 2)));
924
+ k = Math.round(Math.log(2) * bitsPerElem);
925
+ nBitsPerElem = Math.round(bitsPerElem);
926
+ }
927
+ else {
928
+ // Use specified k if possible
929
+ if (forceNBitsPerElem < 1) {
930
+ // Use lookup table
931
+ nBitsPerElem = getMOverNBitsForK(k, options.errorRate);
932
+ }
933
+ else {
934
+ nBitsPerElem = forceNBitsPerElem;
935
+ }
936
+ }
937
+ const mBits = options.capacity * nBitsPerElem;
938
+ const mInts = 1 + Math.floor(mBits / (sizeOfInt * 8));
939
+ this.totalBits = mBits;
940
+ this.data = new Array(mInts);
941
+ this.data.fill(BigInt(0));
942
+ this.kHashes = k;
943
+ this.hashN = hashN;
944
+ this.errorRate = options.errorRate;
945
+ }
946
+ computeHashes(item) {
947
+ const hashes = new Array(this.kHashes);
948
+ for (let i = 0; i < this.kHashes; i++) {
949
+ hashes[i] = this.hashN(item, i, this.totalBits);
950
+ }
951
+ return hashes;
952
+ }
953
+ // Adds an item to the bloom filter by computing its hash values
954
+ // and setting corresponding bits in "data".
955
+ insert(item) {
956
+ const hashSet = this.computeHashes(item);
957
+ for (const h of hashSet) {
958
+ const intAddress = Math.floor(h / (sizeOfInt * 8));
959
+ const bitOffset = h % (sizeOfInt * 8);
960
+ this.data[intAddress] =
961
+ this.data[intAddress] | (BigInt(1) << BigInt(bitOffset));
962
+ }
963
+ }
964
+ // Checks if the item is potentially in the bloom filter.
965
+ // The method is guaranteed to return "true" for items that were inserted,
966
+ // but might also return "true" for items that were never inserted
967
+ // (purpose of false-positive probability).
968
+ lookup(item) {
969
+ const hashSet = this.computeHashes(item);
970
+ for (const h of hashSet) {
971
+ const intAddress = Math.floor(h / (sizeOfInt * 8));
972
+ const bitOffset = h % (sizeOfInt * 8);
973
+ const currentInt = this.data[intAddress];
974
+ if (currentInt != (currentInt | (BigInt(1) << BigInt(bitOffset)))) {
975
+ return false;
976
+ }
977
+ }
978
+ return true;
979
+ }
980
+ toBytes() {
981
+ const buffer = new ArrayBuffer(this.data.length * 8);
982
+ const view = new DataView(buffer);
983
+ for (let i = 0; i < this.data.length; i++) {
984
+ view.setBigInt64(i * 8, this.data[i]);
985
+ }
986
+ return new Uint8Array(buffer);
987
+ }
988
+ static fromBytes(bytes, options, hashN) {
989
+ const bloomFilter = new BloomFilter(options, hashN);
990
+ const view = new DataView(bytes.buffer);
991
+ for (let i = 0; i < bloomFilter.data.length; i++) {
992
+ bloomFilter.data[i] = view.getBigUint64(i * 8, false);
993
+ }
994
+ return bloomFilter;
995
+ }
996
+ }
997
+
998
+ export { BloomFilter };