next 13.4.2 → 13.4.3-canary.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.
Files changed (96) hide show
  1. package/dist/bin/next +1 -1
  2. package/dist/build/index.js +1 -1
  3. package/dist/build/swc/index.js +1 -1
  4. package/dist/build/webpack/plugins/profiling-plugin.d.ts +2 -2
  5. package/dist/build/webpack/plugins/profiling-plugin.js +117 -28
  6. package/dist/build/webpack/plugins/profiling-plugin.js.map +1 -1
  7. package/dist/build/webpack-config.js +2 -2
  8. package/dist/client/app-bootstrap.js +1 -1
  9. package/dist/client/image.js +1 -0
  10. package/dist/client/image.js.map +1 -1
  11. package/dist/client/index.js +1 -1
  12. package/dist/client/legacy/image.js +2 -1
  13. package/dist/client/legacy/image.js.map +1 -1
  14. package/dist/esm/build/index.js +1 -1
  15. package/dist/esm/build/swc/index.js +1 -1
  16. package/dist/esm/build/webpack/plugins/profiling-plugin.js +117 -28
  17. package/dist/esm/build/webpack/plugins/profiling-plugin.js.map +1 -1
  18. package/dist/esm/build/webpack-config.js +2 -2
  19. package/dist/esm/client/app-bootstrap.js +1 -1
  20. package/dist/esm/client/image.js +1 -0
  21. package/dist/esm/client/image.js.map +1 -1
  22. package/dist/esm/client/index.js +1 -1
  23. package/dist/esm/client/legacy/image.js +2 -1
  24. package/dist/esm/client/legacy/image.js.map +1 -1
  25. package/dist/esm/lib/create-client-router-filter.js +1 -2
  26. package/dist/esm/lib/create-client-router-filter.js.map +1 -1
  27. package/dist/esm/lib/server-external-packages.json +1 -0
  28. package/dist/esm/server/dev/hot-reloader.js +1 -1
  29. package/dist/esm/server/lib/incremental-cache/index.js +1 -1
  30. package/dist/esm/server/lib/incremental-cache/index.js.map +1 -1
  31. package/dist/esm/server/lib/patch-fetch.js +1 -1
  32. package/dist/esm/server/lib/start-server.js +1 -3
  33. package/dist/esm/server/lib/start-server.js.map +1 -1
  34. package/dist/esm/server/web/spec-extension/adapters/request-cookies.js +1 -1
  35. package/dist/esm/server/web/spec-extension/adapters/request-cookies.js.map +1 -1
  36. package/dist/esm/shared/lib/base64-arraybuffer.js.map +1 -0
  37. package/dist/esm/shared/lib/bloom-filter.js +74 -0
  38. package/dist/esm/shared/lib/bloom-filter.js.map +1 -0
  39. package/dist/esm/shared/lib/router/router.js +6 -6
  40. package/dist/esm/shared/lib/router/router.js.map +1 -1
  41. package/dist/lib/create-client-router-filter.js +1 -2
  42. package/dist/lib/create-client-router-filter.js.map +1 -1
  43. package/dist/lib/server-external-packages.json +1 -0
  44. package/dist/server/dev/hot-reloader.js +1 -1
  45. package/dist/server/lib/incremental-cache/index.js +1 -1
  46. package/dist/server/lib/patch-fetch.js +1 -1
  47. package/dist/server/lib/start-server.js +1 -3
  48. package/dist/server/lib/start-server.js.map +1 -1
  49. package/dist/server/web/spec-extension/adapters/request-cookies.d.ts +1 -1
  50. package/dist/server/web/spec-extension/adapters/request-cookies.js +1 -1
  51. package/dist/server/web/spec-extension/adapters/request-cookies.js.map +1 -1
  52. package/dist/shared/lib/base64-arraybuffer.js.map +1 -0
  53. package/dist/shared/lib/bloom-filter.d.ts +20 -0
  54. package/dist/shared/lib/bloom-filter.js +84 -0
  55. package/dist/shared/lib/bloom-filter.js.map +1 -0
  56. package/dist/shared/lib/router/router.js +6 -6
  57. package/dist/shared/lib/router/router.js.map +1 -1
  58. package/dist/telemetry/anonymous-meta.js +1 -1
  59. package/dist/telemetry/events/session-stopped.js +2 -2
  60. package/dist/telemetry/events/version.js +2 -2
  61. package/package.json +16 -16
  62. package/dist/esm/shared/lib/bloom-filter/base-filter.js +0 -88
  63. package/dist/esm/shared/lib/bloom-filter/base-filter.js.map +0 -1
  64. package/dist/esm/shared/lib/bloom-filter/base64-arraybuffer.js.map +0 -1
  65. package/dist/esm/shared/lib/bloom-filter/bit-set.js +0 -129
  66. package/dist/esm/shared/lib/bloom-filter/bit-set.js.map +0 -1
  67. package/dist/esm/shared/lib/bloom-filter/formulas.js +0 -46
  68. package/dist/esm/shared/lib/bloom-filter/formulas.js.map +0 -1
  69. package/dist/esm/shared/lib/bloom-filter/hashing.js +0 -181
  70. package/dist/esm/shared/lib/bloom-filter/hashing.js.map +0 -1
  71. package/dist/esm/shared/lib/bloom-filter/index.js +0 -158
  72. package/dist/esm/shared/lib/bloom-filter/index.js.map +0 -1
  73. package/dist/esm/shared/lib/bloom-filter/utils.js +0 -68
  74. package/dist/esm/shared/lib/bloom-filter/utils.js.map +0 -1
  75. package/dist/shared/lib/bloom-filter/base-filter.d.ts +0 -50
  76. package/dist/shared/lib/bloom-filter/base-filter.js +0 -94
  77. package/dist/shared/lib/bloom-filter/base-filter.js.map +0 -1
  78. package/dist/shared/lib/bloom-filter/base64-arraybuffer.js.map +0 -1
  79. package/dist/shared/lib/bloom-filter/bit-set.d.ts +0 -72
  80. package/dist/shared/lib/bloom-filter/bit-set.js +0 -134
  81. package/dist/shared/lib/bloom-filter/bit-set.js.map +0 -1
  82. package/dist/shared/lib/bloom-filter/formulas.d.ts +0 -21
  83. package/dist/shared/lib/bloom-filter/formulas.js +0 -62
  84. package/dist/shared/lib/bloom-filter/formulas.js.map +0 -1
  85. package/dist/shared/lib/bloom-filter/hashing.d.ts +0 -117
  86. package/dist/shared/lib/bloom-filter/hashing.js +0 -191
  87. package/dist/shared/lib/bloom-filter/hashing.js.map +0 -1
  88. package/dist/shared/lib/bloom-filter/index.d.ts +0 -101
  89. package/dist/shared/lib/bloom-filter/index.js +0 -161
  90. package/dist/shared/lib/bloom-filter/index.js.map +0 -1
  91. package/dist/shared/lib/bloom-filter/utils.d.ts +0 -56
  92. package/dist/shared/lib/bloom-filter/utils.js +0 -78
  93. package/dist/shared/lib/bloom-filter/utils.js.map +0 -1
  94. /package/dist/esm/shared/lib/{bloom-filter/base64-arraybuffer.js → base64-arraybuffer.js} +0 -0
  95. /package/dist/shared/lib/{bloom-filter/base64-arraybuffer.d.ts → base64-arraybuffer.d.ts} +0 -0
  96. /package/dist/shared/lib/{bloom-filter/base64-arraybuffer.js → base64-arraybuffer.js} +0 -0
@@ -1,191 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return Hashing;
9
- }
10
- });
11
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _fnv1a = /*#__PURE__*/ _interop_require_default._(require("../fnv1a"));
13
- const _utils = require("./utils");
14
- class Hashing {
15
- /**
16
- * Apply enhanced Double Hashing to produce a n-hash
17
- * @see {@link http://peterd.org/pcd-diss.pdf} s6.5.4
18
- * @param n - The indice of the hash function we want to produce
19
- * @param hashA - The result of the first hash function applied to a value.
20
- * @param hashB - The result of the second hash function applied to a value.
21
- * @param size - The size of the datastructures associated to the hash context (ex: the size of a Bloom Filter)
22
- * @return The result of hash_n applied to a value.
23
- * @memberof Hashing
24
- * @author Thomas Minier
25
- * @author Arnaud Grall
26
- */ doubleHashing(n, hashA, hashB, size) {
27
- return Math.abs((hashA + n * hashB + Math.floor((n ** 3 - n) / 6)) % size);
28
- }
29
- /**
30
- * Generate a set of distinct indexes on interval [0, size) using the double hashing technique
31
- * For generating efficiently distinct indexes we re-hash after detecting a cycle by changing slightly the seed.
32
- * It has the effect of generating faster distinct indexes without loosing entirely the utility of the double hashing.
33
- * For small number of indexes it will work perfectly. For a number close to the size, and size very large
34
- * Advise: do not generate `size` indexes for a large interval. In practice, size should be equal
35
- * to the number of hash functions used and is often low.
36
- *
37
- * @param element - The element to hash
38
- * @param size - the range on which we can generate an index [0, size) = size
39
- * @param number - The number of indexes desired
40
- * @param seed - The seed used
41
- * @return Array<number>
42
- * @author Arnaud Grall
43
- * @author Simon Woolf (SimonWoolf)
44
- */ getDistinctIndexes(element, size, number, seed) {
45
- if (seed === undefined) {
46
- seed = (0, _utils.getDefaultSeed)();
47
- }
48
- let n = 0;
49
- const indexes = new Set();
50
- let hashes = this.hashTwice(element, seed);
51
- // let cycle = 0
52
- while(indexes.size < number){
53
- const ind = hashes.first % size;
54
- if (!indexes.has(ind)) {
55
- indexes.add(ind);
56
- }
57
- hashes.first = (hashes.first + hashes.second) % size;
58
- hashes.second = (hashes.second + n) % size;
59
- n++;
60
- if (n > size) {
61
- // Enhanced double hashing stops cycles of length less than `size` in the case where
62
- // size is coprime with the second hash. But you still get cycles of length `size`.
63
- // So if we reach there and haven't finished, append a prime to the input and
64
- // rehash.
65
- seed++;
66
- hashes = this.hashTwice(element, seed);
67
- }
68
- }
69
- return [
70
- ...indexes.values()
71
- ];
72
- }
73
- /**
74
- * Generate N indexes on range [0, size)
75
- * It uses the double hashing technique to generate the indexes.
76
- * It hash twice the value only once before generating the indexes.
77
- * Warning: you can have a lot of modulo collisions.
78
- * @param element - The element to hash
79
- * @param size - The range on which we can generate the index, exclusive
80
- * @param hashCount - The number of indexes we want
81
- * @return An array of indexes on range [0, size)
82
- */ getIndexes(element, size, hashCount, seed) {
83
- if (seed === undefined) {
84
- seed = (0, _utils.getDefaultSeed)();
85
- }
86
- const arr = [];
87
- const hashes = this.hashTwice(element, seed);
88
- for(let i = 0; i < hashCount; i++){
89
- arr.push(this.doubleHashing(i, hashes.first, hashes.second, size));
90
- }
91
- return arr;
92
- }
93
- /**
94
- * @internal
95
- * Hash an element of type {@link HashableInput} into {@link Number}
96
- * Can be overrided as long as you return a value of type {@link Number}
97
- * Don't forget to use the seed when hashing, otherwise if some kind of randomness is in the process
98
- * you may have inconsistent behaviors between 2 runs.
99
- * @param element
100
- * @param seed
101
- * @returns A 64bits floating point {@link Number}
102
- */ serialize(element, seed) {
103
- if (!seed) {
104
- seed = (0, _utils.getDefaultSeed)();
105
- }
106
- return Number((0, _fnv1a.default)(element, {
107
- seed
108
- }));
109
- }
110
- /**
111
- * (64-bits only) Hash a value into two values (in hex or integer format)
112
- * @param value - The value to hash
113
- * @param asInt - (optional) If True, the values will be returned as an integer. Otherwise, as hexadecimal values.
114
- * @param seed the seed used for hashing
115
- * @return The results of the hash functions applied to the value (in hex or integer)
116
- * @author Arnaud Grall & Thomas Minier
117
- */ hashTwice(value, seed) {
118
- if (seed === undefined) {
119
- seed = (0, _utils.getDefaultSeed)();
120
- }
121
- return {
122
- first: this.serialize(value, seed + 1),
123
- second: this.serialize(value, seed + 2)
124
- };
125
- }
126
- /**
127
- * Hash twice an element into their HEX string representations
128
- * @param value
129
- * @param seed
130
- * @returns TwoHashesTemplated<string>
131
- */ hashTwiceAsString(value, seed) {
132
- const { first , second } = this.hashTwice(value, seed);
133
- return {
134
- first: (0, _utils.numberToHex)(first),
135
- second: (0, _utils.numberToHex)(second)
136
- };
137
- }
138
- /**
139
- * (64-bits only) Same as hashTwice but return Numbers and String equivalent
140
- * @param val the value to hash
141
- * @param seed the seed to change when hashing
142
- * @return TwoHashesIntAndString
143
- * @author Arnaud Grall
144
- */ hashTwiceIntAndString(val, seed) {
145
- if (seed === undefined) {
146
- seed = (0, _utils.getDefaultSeed)();
147
- }
148
- const one = this.hashIntAndString(val, seed + 1);
149
- const two = this.hashIntAndString(val, seed + 2);
150
- return {
151
- int: {
152
- first: one.int,
153
- second: two.int
154
- },
155
- string: {
156
- first: one.string,
157
- second: two.string
158
- }
159
- };
160
- }
161
- /**
162
- * Hash an item as an unsigned int
163
- * @param elem - Element to hash
164
- * @param seed - The hash seed. If its is UINT32 make sure to set the length to 32
165
- * @param length - The length of hashes (defaults to 32 bits)
166
- * @return The hash value as an unsigned int
167
- * @author Arnaud Grall
168
- */ hashAsInt(elem, seed) {
169
- if (seed === undefined) {
170
- seed = (0, _utils.getDefaultSeed)();
171
- }
172
- return this.serialize(elem, seed);
173
- }
174
- /**
175
- * Hash an item and return its number and HEX string representation
176
- * @param elem - Element to hash
177
- * @param seed - The hash seed. If its is UINT32 make sure to set the length to 32
178
- * @param base - The base in which the string will be returned, default: 16
179
- * @param length - The length of hashes (defaults to 32 bits)
180
- * @return The item hased as an int and a string
181
- * @author Arnaud Grall
182
- */ hashIntAndString(elem, seed) {
183
- const hash = this.hashAsInt(elem, seed);
184
- return {
185
- int: hash,
186
- string: (0, _utils.numberToHex)(hash)
187
- };
188
- }
189
- }
190
-
191
- //# sourceMappingURL=hashing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/hashing.ts"],"names":["Hashing","doubleHashing","n","hashA","hashB","size","Math","abs","floor","getDistinctIndexes","element","number","seed","undefined","getDefaultSeed","indexes","Set","hashes","hashTwice","ind","first","has","add","second","values","getIndexes","hashCount","arr","i","push","serialize","Number","fnv1a","value","hashTwiceAsString","numberToHex","hashTwiceIntAndString","val","one","hashIntAndString","two","int","string","hashAsInt","elem","hash"],"mappings":";;;;;;;eAmCqBA;;;;gEAnCH;uBAC0B;AAkC7B,MAAMA;IACnB;;;;;;;;;;;GAWC,GACD,AAAOC,cACLC,CAAS,EACTC,KAAa,EACbC,KAAa,EACbC,IAAY,EACJ;QACR,OAAOC,KAAKC,GAAG,CAAC,AAACJ,CAAAA,QAAQD,IAAIE,QAAQE,KAAKE,KAAK,CAAC,AAACN,CAAAA,KAAK,IAAIA,CAAAA,IAAK,EAAC,IAAKG;IACvE;IAEA;;;;;;;;;;;;;;;GAeC,GACD,AAAOI,mBACLC,OAAsB,EACtBL,IAAY,EACZM,MAAc,EACdC,IAAa,EACE;QACf,IAAIA,SAASC,WAAW;YACtBD,OAAOE,IAAAA,qBAAc;QACvB,CAAC;QACD,IAAIZ,IAAI;QACR,MAAMa,UAAuB,IAAIC;QACjC,IAAIC,SAAS,IAAI,CAACC,SAAS,CAACR,SAASE;QACrC,gBAAgB;QAChB,MAAOG,QAAQV,IAAI,GAAGM,OAAQ;YAC5B,MAAMQ,MAAMF,OAAOG,KAAK,GAAGf;YAC3B,IAAI,CAACU,QAAQM,GAAG,CAACF,MAAM;gBACrBJ,QAAQO,GAAG,CAACH;YACd,CAAC;YACDF,OAAOG,KAAK,GAAG,AAACH,CAAAA,OAAOG,KAAK,GAAGH,OAAOM,MAAM,AAAD,IAAKlB;YAChD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AK,EAAEG,OAAM,EAAE,GAAG,IAAI,CAACL,SAAS,CAACe,OAAOrB;QAChD,OAAO;YACLQ,OAAOe,IAAAA,kBAAW,EAACf;YACnBG,QAAQY,IAAAA,kBAAW,EAACZ;QACtB;IACF;IAEA;;;;;;GAMC,GACD,AAAOa,sBACLC,GAAkB,EAClBzB,IAAa,EACU;QACvB,IAAIA,SAASC,WAAW;YACtBD,OAAOE,IAAAA,qBAAc;QACvB,CAAC;QACD,MAAMwB,MAAM,IAAI,CAACC,gBAAgB,CAACF,KAAKzB,OAAO;QAC9C,MAAM4B,MAAM,IAAI,CAACD,gBAAgB,CAACF,KAAKzB,OAAO;QAC9C,OAAO;YACL6B,KAAK;gBACHrB,OAAOkB,IAAIG,GAAG;gBACdlB,QAAQiB,IAAIC,GAAG;YACjB;YACAC,QAAQ;gBACNtB,OAAOkB,IAAII,MAAM;gBACjBnB,QAAQiB,IAAIE,MAAM;YACpB;QACF;IACF;IAEA;;;;;;;GAOC,GACD,AAAOC,UAAUC,IAAmB,EAAEhC,IAAa,EAAU;QAC3D,IAAIA,SAASC,WAAW;YACtBD,OAAOE,IAAAA,qBAAc;QACvB,CAAC;QACD,OAAO,IAAI,CAACgB,SAAS,CAACc,MAAMhC;IAC9B;IAEA;;;;;;;;GAQC,GACD,AAAO2B,iBAAiBK,IAAmB,EAAEhC,IAAa,EAAE;QAC1D,MAAMiC,OAAO,IAAI,CAACF,SAAS,CAACC,MAAMhC;QAClC,OAAO;YAAE6B,KAAKI;YAAMH,QAAQP,IAAAA,kBAAW,EAACU;QAAM;IAChD;AACF"}
@@ -1,101 +0,0 @@
1
- import BaseFilter from './base-filter';
2
- import BitSet from './bit-set';
3
- import { HashableInput } from './hashing';
4
- /**
5
- * A Bloom filter is a space-efficient probabilistic data structure, conceived by Burton Howard Bloom in 1970,
6
- * that is used to test whether an element is a member of a set. False positive matches are possible, but false negatives are not.
7
- *
8
- * Reference: Bloom, B. H. (1970). Space/time trade-offs in hash coding with allowable errors. Communications of the ACM, 13(7), 422-426.
9
- * @see {@link http://crystal.uta.edu/~mcguigan/cse6350/papers/Bloom.pdf} for more details about classic Bloom Filters.
10
- * @author Thomas Minier
11
- * @author Arnaud Grall
12
- */
13
- export declare class BloomFilter extends BaseFilter {
14
- _size: number;
15
- _nbHashes: number;
16
- _filter: BitSet;
17
- /**
18
- * Constructor
19
- * @param size - The number of cells
20
- * @param nbHashes - The number of hash functions used
21
- */
22
- constructor(size: number, nbHashes: number);
23
- /**
24
- * Create an optimal bloom filter providing the maximum of elements stored and the error rate desired
25
- * @param nbItems - The maximum number of item to store
26
- * @param errorRate - The error rate desired for a maximum of items inserted
27
- * @return A new {@link BloomFilter}
28
- */
29
- static create(nbItems: number, errorRate: number): BloomFilter;
30
- /**
31
- * Build a new Bloom Filter from an existing iterable with a fixed error rate
32
- * @param items - The iterable used to populate the filter
33
- * @param errorRate - The error rate, i.e. 'false positive' rate, targeted by the filter
34
- * @param seed - The random number seed (optional)
35
- * @return A new Bloom Filter filled with the iterable's elements
36
- * @example
37
- * ```js
38
- * // create a filter with a false positive rate of 0.1
39
- * const filter = BloomFilter.from(['alice', 'bob', 'carl'], 0.1);
40
- * ```
41
- */
42
- static from(items: Iterable<HashableInput>, errorRate: number, seed?: number): BloomFilter;
43
- /**
44
- * Get the optimal size of the filter
45
- * @return The size of the filter
46
- */
47
- get size(): number;
48
- /**
49
- * Get the number of bits currently set in the filter
50
- * @return The filter length
51
- */
52
- get length(): number;
53
- /**
54
- * Add an element to the filter
55
- * @param element - The element to add
56
- * @example
57
- * ```js
58
- * const filter = new BloomFilter(15, 0.1);
59
- * filter.add('foo');
60
- * ```
61
- */
62
- add(element: HashableInput): void;
63
- /**
64
- * Test an element for membership
65
- * @param element - The element to look for in the filter
66
- * @return False if the element is definitively not in the filter, True is the element might be in the filter
67
- * @example
68
- * ```js
69
- * const filter = new BloomFilter(15, 0.1);
70
- * filter.add('foo');
71
- * console.log(filter.has('foo')); // output: true
72
- * console.log(filter.has('bar')); // output: false
73
- * ```
74
- */
75
- has(element: HashableInput): boolean;
76
- /**
77
- * Get the current false positive rate (or error rate) of the filter
78
- * @return The current false positive rate of the filter
79
- * @example
80
- * ```js
81
- * const filter = new BloomFilter(15, 0.1);
82
- * console.log(filter.rate()); // output: something around 0.1
83
- * ```
84
- */
85
- rate(): number;
86
- /**
87
- * Check if another Bloom Filter is equal to this one
88
- * @param other - The filter to compare to this one
89
- * @return True if they are equal, false otherwise
90
- */
91
- equals(other: BloomFilter): boolean;
92
- export(): {
93
- bitset: {
94
- size: number;
95
- content: string;
96
- };
97
- hashes: number;
98
- size: number;
99
- };
100
- import(data: ReturnType<typeof this.export>): void;
101
- }
@@ -1,161 +0,0 @@
1
- // original source: https://github.com/Callidon/bloom-filters
2
- /* file : bloom-filter.ts
3
- MIT License
4
-
5
- Copyright (c) 2017 Thomas Minier & Arnaud Grall
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
24
- */ "use strict";
25
- Object.defineProperty(exports, "__esModule", {
26
- value: true
27
- });
28
- Object.defineProperty(exports, "BloomFilter", {
29
- enumerable: true,
30
- get: function() {
31
- return BloomFilter;
32
- }
33
- });
34
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
35
- const _basefilter = /*#__PURE__*/ _interop_require_default._(require("./base-filter"));
36
- const _bitset = /*#__PURE__*/ _interop_require_default._(require("./bit-set"));
37
- const _formulas = require("./formulas");
38
- class BloomFilter extends _basefilter.default {
39
- /**
40
- * Create an optimal bloom filter providing the maximum of elements stored and the error rate desired
41
- * @param nbItems - The maximum number of item to store
42
- * @param errorRate - The error rate desired for a maximum of items inserted
43
- * @return A new {@link BloomFilter}
44
- */ static create(nbItems, errorRate) {
45
- const size = (0, _formulas.optimalFilterSize)(nbItems, errorRate);
46
- const hashes = (0, _formulas.optimalHashes)(size, nbItems);
47
- return new this(size, hashes);
48
- }
49
- /**
50
- * Build a new Bloom Filter from an existing iterable with a fixed error rate
51
- * @param items - The iterable used to populate the filter
52
- * @param errorRate - The error rate, i.e. 'false positive' rate, targeted by the filter
53
- * @param seed - The random number seed (optional)
54
- * @return A new Bloom Filter filled with the iterable's elements
55
- * @example
56
- * ```js
57
- * // create a filter with a false positive rate of 0.1
58
- * const filter = BloomFilter.from(['alice', 'bob', 'carl'], 0.1);
59
- * ```
60
- */ static from(items, errorRate, seed) {
61
- const array = Array.from(items);
62
- const filter = BloomFilter.create(array.length, errorRate);
63
- if (typeof seed === "number") {
64
- filter.seed = seed;
65
- }
66
- array.forEach((element)=>filter.add(element));
67
- return filter;
68
- }
69
- /**
70
- * Get the optimal size of the filter
71
- * @return The size of the filter
72
- */ get size() {
73
- return this._size;
74
- }
75
- /**
76
- * Get the number of bits currently set in the filter
77
- * @return The filter length
78
- */ get length() {
79
- return this._filter.bitCount();
80
- }
81
- /**
82
- * Add an element to the filter
83
- * @param element - The element to add
84
- * @example
85
- * ```js
86
- * const filter = new BloomFilter(15, 0.1);
87
- * filter.add('foo');
88
- * ```
89
- */ add(element) {
90
- const indexes = this._hashing.getIndexes(element, this._size, this._nbHashes, this.seed);
91
- for(let i = 0; i < indexes.length; i++){
92
- this._filter.add(indexes[i]);
93
- }
94
- }
95
- /**
96
- * Test an element for membership
97
- * @param element - The element to look for in the filter
98
- * @return False if the element is definitively not in the filter, True is the element might be in the filter
99
- * @example
100
- * ```js
101
- * const filter = new BloomFilter(15, 0.1);
102
- * filter.add('foo');
103
- * console.log(filter.has('foo')); // output: true
104
- * console.log(filter.has('bar')); // output: false
105
- * ```
106
- */ has(element) {
107
- const indexes = this._hashing.getIndexes(element, this._size, this._nbHashes, this.seed);
108
- for(let i = 0; i < indexes.length; i++){
109
- if (!this._filter.has(indexes[i])) {
110
- return false;
111
- }
112
- }
113
- return true;
114
- }
115
- /**
116
- * Get the current false positive rate (or error rate) of the filter
117
- * @return The current false positive rate of the filter
118
- * @example
119
- * ```js
120
- * const filter = new BloomFilter(15, 0.1);
121
- * console.log(filter.rate()); // output: something around 0.1
122
- * ```
123
- */ rate() {
124
- return Math.pow(1 - Math.exp(-this.length / this._size), this._nbHashes);
125
- }
126
- /**
127
- * Check if another Bloom Filter is equal to this one
128
- * @param other - The filter to compare to this one
129
- * @return True if they are equal, false otherwise
130
- */ equals(other) {
131
- if (this._size !== other._size || this._nbHashes !== other._nbHashes) {
132
- return false;
133
- }
134
- return this._filter.equals(other._filter);
135
- }
136
- export() {
137
- return {
138
- bitset: this._filter.export(),
139
- hashes: this._nbHashes,
140
- size: this._size
141
- };
142
- }
143
- import(data) {
144
- this._filter = _bitset.default.import(data.bitset);
145
- }
146
- /**
147
- * Constructor
148
- * @param size - The number of cells
149
- * @param nbHashes - The number of hash functions used
150
- */ constructor(size, nbHashes){
151
- super();
152
- if (nbHashes < 1) {
153
- throw new Error("A BloomFilter cannot uses less than one hash function, while you tried to use " + nbHashes + ".");
154
- }
155
- this._size = size;
156
- this._nbHashes = nbHashes;
157
- this._filter = new _bitset.default(size);
158
- }
159
- }
160
-
161
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/index.ts"],"names":["BloomFilter","BaseFilter","create","nbItems","errorRate","size","optimalFilterSize","hashes","optimalHashes","from","items","seed","array","Array","filter","length","forEach","element","add","_size","_filter","bitCount","indexes","_hashing","getIndexes","_nbHashes","i","has","rate","Math","pow","exp","equals","other","export","bitset","import","data","BitSet","constructor","nbHashes","Error"],"mappings":"AAAA,6DAA6D;AAC7D;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;+BAgBaA;;;eAAAA;;;;qEAdU;iEACJ;0BAC8B;AAY1C,MAAMA,oBAAoBC,mBAAU;IAsBzC;;;;;GAKC,GACD,OAAcC,OAAOC,OAAe,EAAEC,SAAiB,EAAe;QACpE,MAAMC,OAAOC,IAAAA,2BAAiB,EAACH,SAASC;QACxC,MAAMG,SAASC,IAAAA,uBAAa,EAACH,MAAMF;QACnC,OAAO,IAAI,IAAI,CAACE,MAAME;IACxB;IAEA;;;;;;;;;;;GAWC,GACD,OAAcE,KACZC,KAA8B,EAC9BN,SAAiB,EACjBO,IAAa,EACA;QACb,MAAMC,QAAQC,MAAMJ,IAAI,CAACC;QACzB,MAAMI,SAASd,YAAYE,MAAM,CAACU,MAAMG,MAAM,EAAEX;QAChD,IAAI,OAAOO,SAAS,UAAU;YAC5BG,OAAOH,IAAI,GAAGA;QAChB,CAAC;QACDC,MAAMI,OAAO,CAAC,CAACC,UAAYH,OAAOI,GAAG,CAACD;QACtC,OAAOH;IACT;IAEA;;;GAGC,GACD,IAAIT,OAAe;QACjB,OAAO,IAAI,CAACc,KAAK;IACnB;IAEA;;;GAGC,GACD,IAAWJ,SAAiB;QAC1B,OAAO,IAAI,CAACK,OAAO,CAACC,QAAQ;IAC9B;IAEA;;;;;;;;GAQC,GACD,AAAOH,IAAID,OAAsB,EAAQ;QACvC,MAAMK,UAAU,IAAI,CAACC,QAAQ,CAACC,UAAU,CACtCP,SACA,IAAI,CAACE,KAAK,EACV,IAAI,CAAC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;IA1JA;;;;GAIC,GACDI,YAAYlC,IAAY,EAAEmC,QAAgB,CAAE;QAC1C,KAAK;QACL,IAAIA,WAAW,GAAG;YAChB,MAAM,IAAIC,MACR,AAAC,mFAAgFD,WAAS,KAC3F;QACH,CAAC;QACD,IAAI,CAACrB,KAAK,GAAGd;QACb,IAAI,CAACoB,SAAS,GAAGe;QACjB,IAAI,CAACpB,OAAO,GAAG,IAAIkB,eAAM,CAACjC;IAC5B;AA4IF"}
@@ -1,56 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * Utilitaries functions
4
- * @namespace Utils
5
- * @private
6
- */
7
- /**
8
- * @typedef {TwoHashes} Two hashes of the same value, as computed by {@link hashTwice}.
9
- * @property {number} first - The result of the first hashing function applied to a value
10
- * @property {number} second - The result of the second hashing function applied to a value
11
- * @memberof Utils
12
- */
13
- export interface TwoHashes {
14
- first: number;
15
- second: number;
16
- }
17
- /**
18
- * Templated TwoHashes type
19
- */
20
- export interface TwoHashesTemplated<T> {
21
- first: T;
22
- second: T;
23
- }
24
- /**
25
- * TwoHashes type in number and int format
26
- */
27
- export interface TwoHashesIntAndString {
28
- int: TwoHashesTemplated<number>;
29
- string: TwoHashesTemplated<string>;
30
- }
31
- /**
32
- * Data type of an hashable value, must be string, ArrayBuffer or Buffer.
33
- */
34
- export declare type HashableInput = string | ArrayBuffer | Buffer;
35
- /**
36
- * Return a number to its Hex format by padding zeroes if length mod 4 != 0
37
- * @param elem the element to transform in HEX
38
- * @returns the HEX number padded of zeroes
39
- */
40
- export declare function numberToHex(elem: number): string;
41
- /**
42
- * Generate a random int between two bounds (included)
43
- * @param min - The lower bound
44
- * @param max - The upper bound
45
- * @param random - Function used to generate random floats
46
- * @return A random int bewteen lower and upper bound (included)
47
- * @memberof Utils
48
- * @author Thomas Minier
49
- */
50
- export declare function randomInt(min: number, max: number, random?: () => number): number;
51
- /**
52
- * Return the default seed used in the package
53
- * @return A seed as a floating point number
54
- * @author Arnaud Grall
55
- */
56
- export declare function getDefaultSeed(): number;
@@ -1,78 +0,0 @@
1
- /* file : utils.ts
2
- MIT License
3
-
4
- Copyright (c) 2017-2020 Thomas Minier & Arnaud Grall
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
23
- */ /**
24
- * Utilitaries functions
25
- * @namespace Utils
26
- * @private
27
- */ /* JSDOC typedef */ /**
28
- * @typedef {TwoHashes} Two hashes of the same value, as computed by {@link hashTwice}.
29
- * @property {number} first - The result of the first hashing function applied to a value
30
- * @property {number} second - The result of the second hashing function applied to a value
31
- * @memberof Utils
32
- */ "use strict";
33
- Object.defineProperty(exports, "__esModule", {
34
- value: true
35
- });
36
- 0 && (module.exports = {
37
- numberToHex: null,
38
- randomInt: null,
39
- getDefaultSeed: null
40
- });
41
- function _export(target, all) {
42
- for(var name in all)Object.defineProperty(target, name, {
43
- enumerable: true,
44
- get: all[name]
45
- });
46
- }
47
- _export(exports, {
48
- numberToHex: function() {
49
- return numberToHex;
50
- },
51
- randomInt: function() {
52
- return randomInt;
53
- },
54
- getDefaultSeed: function() {
55
- return getDefaultSeed;
56
- }
57
- });
58
- function numberToHex(elem) {
59
- let e = Number(elem).toString(16);
60
- if (e.length % 4 !== 0) {
61
- e = "0".repeat(4 - e.length % 4) + e;
62
- }
63
- return e;
64
- }
65
- function randomInt(min, max, random) {
66
- if (random === undefined) {
67
- random = Math.random;
68
- }
69
- min = Math.ceil(min);
70
- max = Math.floor(max);
71
- const rn = random();
72
- return Math.floor(rn * (max - min + 1)) + min;
73
- }
74
- function getDefaultSeed() {
75
- return 0x1234567890;
76
- }
77
-
78
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/utils.ts"],"names":["numberToHex","randomInt","getDefaultSeed","elem","e","Number","toString","length","repeat","min","max","random","undefined","Math","ceil","floor","rn"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBA,GAEA;;;;CAIC,GAED,iBAAiB,GACjB;;;;;CAKC;;;;;;;;;;;;;;;;IAgCeA,WAAW;eAAXA;;IAiBAC,SAAS;eAATA;;IAmBAC,cAAc;eAAdA;;;AApCT,SAASF,YAAYG,IAAY,EAAU;IAChD,IAAIC,IAAIC,OAAOF,MAAMG,QAAQ,CAAC;IAC9B,IAAIF,EAAEG,MAAM,GAAG,MAAM,GAAG;QACtBH,IAAI,IAAII,MAAM,CAAC,IAAKJ,EAAEG,MAAM,GAAG,KAAMH;IACvC,CAAC;IACD,OAAOA;AACT;AAWO,SAASH,UACdQ,GAAW,EACXC,GAAW,EACXC,MAAqB,EACb;IACR,IAAIA,WAAWC,WAAW;QACxBD,SAASE,KAAKF,MAAM;IACtB,CAAC;IACDF,MAAMI,KAAKC,IAAI,CAACL;IAChBC,MAAMG,KAAKE,KAAK,CAACL;IACjB,MAAMM,KAAKL;IACX,OAAOE,KAAKE,KAAK,CAACC,KAAMN,CAAAA,MAAMD,MAAM,CAAA,KAAMA;AAC5C;AAOO,SAASP,iBAAyB;IACvC,OAAO;AACT"}