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,88 +0,0 @@
1
- /* file : base-filter.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
- */ import Hashing from "./hashing";
24
- import { getDefaultSeed } from "./utils";
25
- function randomInt32() {
26
- if (typeof window === "undefined" && process.env.NEXT_RUNTIME === "nodejs") {
27
- return require("crypto").randomBytes(4).readUInt32BE(0);
28
- }
29
- return crypto.getRandomValues(new Uint32Array(1))[0];
30
- }
31
- function seedrandom() {
32
- return {
33
- int32: randomInt32,
34
- quick: randomInt32
35
- };
36
- }
37
- class BaseFilter {
38
- /**
39
- * Get the seed used in this structure
40
- */ get seed() {
41
- return this._seed;
42
- }
43
- /**
44
- * Set the seed for this structure
45
- * @param seed the new seed that will be used in this structure
46
- */ set seed(seed) {
47
- this._seed = seed;
48
- this._rng = seedrandom();
49
- }
50
- /**
51
- * Get a function used to draw random number
52
- * @return A factory function used to draw random integer
53
- */ get random() {
54
- return this._rng;
55
- }
56
- /**
57
- * Return a next random seeded int32 integer
58
- * @returns
59
- */ nextInt32() {
60
- return this._rng.int32();
61
- }
62
- /**
63
- * Save the current structure as a JSON
64
- */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- saveAsJSON() {
66
- throw new Error("not-implemented");
67
- }
68
- /**
69
- * Load an Object from a provided JSON object
70
- * @param json the JSON object to load
71
- * @return Return the Object loaded from the provided JSON object
72
- */ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
73
- static fromJSON(json) {
74
- throw new Error("not-implemented");
75
- }
76
- constructor(){
77
- this._seed = getDefaultSeed();
78
- this._rng = seedrandom();
79
- this._hashing = new Hashing();
80
- }
81
- }
82
- /**
83
- * A base class for implementing probailistic filters
84
- * @author Thomas Minier
85
- * @author Arnaud Grall
86
- */ export { BaseFilter as default };
87
-
88
- //# sourceMappingURL=base-filter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/base-filter.ts"],"names":["Hashing","getDefaultSeed","randomInt32","window","process","env","NEXT_RUNTIME","require","randomBytes","readUInt32BE","crypto","getRandomValues","Uint32Array","seedrandom","int32","quick","BaseFilter","seed","_seed","_rng","random","nextInt32","saveAsJSON","Error","fromJSON","json","constructor","_hashing"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBA,GAEA,OAAOA,aAAa,YAAW;AAC/B,SAASC,cAAc,QAAQ,UAAS;AAYxC,SAASC,cAAc;IACrB,IAAI,OAAOC,WAAW,eAAeC,QAAQC,GAAG,CAACC,YAAY,KAAK,UAAU;QAC1E,OAAO,AAACC,QAAQ,UACbC,WAAW,CAAC,GACZC,YAAY,CAAC;IAClB,CAAC;IACD,OAAOC,OAAOC,eAAe,CAAC,IAAIC,YAAY,GAAG,CAAC,EAAE;AACtD;AAEA,SAASC,aAAa;IACpB,OAAO;QACLC,OAAOZ;QACPa,OAAOb;IACT;AACF;AAOe,MAAec;IAW5B;;GAEC,GACD,IAAWC,OAAe;QACxB,OAAO,IAAI,CAACC,KAAK;IACnB;IAEA;;;GAGC,GACD,IAAWD,KAAKA,IAAY,EAAE;QAC5B,IAAI,CAACC,KAAK,GAAGD;QACb,IAAI,CAACE,IAAI,GAAGN;IACd;IAEA;;;GAGC,GACD,IAAWO,SAAe;QACxB,OAAO,IAAI,CAACD,IAAI;IAClB;IAEA;;;GAGC,GACD,AAAOE,YAAoB;QACzB,OAAO,IAAI,CAACF,IAAI,CAACL,KAAK;IACxB;IAEA;;GAEC,GACD,8DAA8D;IACvDQ,aAAkB;QACvB,MAAM,IAAIC,MAAM,mBAAkB;IACpC;IAEA;;;;GAIC,GACD,iGAAiG;IACjG,OAAcC,SAASC,IAAU,EAAO;QACtC,MAAM,IAAIF,MAAO,mBAAiB;IACpC;IAtDAG,aAAc;QACZ,IAAI,CAACR,KAAK,GAAGjB;QACb,IAAI,CAACkB,IAAI,GAAGN;QACZ,IAAI,CAACc,QAAQ,GAAG,IAAI3B;IACtB;AAmDF;AAjEA;;;;CAIC,GACD,SAA8BgB,wBA4D7B"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/base64-arraybuffer.ts"],"names":["chars","lookup","Uint8Array","i","length","charCodeAt","encode","arraybuffer","bytes","len","base64","substring","decode","bufferLength","p","encoded1","encoded2","encoded3","encoded4","ArrayBuffer"],"mappings":"AAAA,2FAA2F;AAE3F,MAAMA,QAAQ;AAEd,wCAAwC;AACxC,MAAMC,SAAS,OAAOC,eAAe,cAAc,EAAE,GAAG,IAAIA,WAAW,IAAI;AAC3E,IAAK,IAAIC,IAAI,GAAGA,IAAIH,MAAMI,MAAM,EAAED,IAAK;IACrCF,MAAM,CAACD,MAAMK,UAAU,CAACF,GAAG,GAAGA;AAChC;AAEA,OAAO,MAAMG,SAAS,CAACC,cAAqC;IAC1D,IAAIC,QAAQ,IAAIN,WAAWK,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AAI,GAAG;QAC3Cc,WAAWhB,MAAM,CAACS,OAAOL,UAAU,CAACF,IAAI,GAAG;QAC3Ce,WAAWjB,MAAM,CAACS,OAAOL,UAAU,CAACF,IAAI,GAAG;QAE3CK,KAAK,CAACM,IAAI,GAAG,AAACC,YAAY,IAAMC,YAAY;QAC5CR,KAAK,CAACM,IAAI,GAAG,AAAEE,CAAAA,WAAW,EAAC,KAAM,IAAMC,YAAY;QACnDT,KAAK,CAACM,IAAI,GAAG,AAAEG,CAAAA,WAAW,CAAA,KAAM,IAAMC,WAAW;IACnD;IAEA,OAAOX;AACT,EAAC"}
@@ -1,129 +0,0 @@
1
- import { encode, decode } from "./base64-arraybuffer";
2
- const bitsPerWord = 8;
3
- class BitSet {
4
- /**
5
- * Returns the value of the bit at the given index
6
- * @param index position of the bit, zero-indexed
7
- */ has(index) {
8
- const wordIndex = Math.floor(index / bitsPerWord);
9
- const mask = 1 << index % bitsPerWord;
10
- return (this.array[wordIndex] & mask) !== 0;
11
- }
12
- /**
13
- * Set the bit to true
14
- * @param index position of the bit, zero-indexed
15
- */ add(index) {
16
- const wordIndex = Math.floor(index / bitsPerWord);
17
- const mask = 1 << index % bitsPerWord;
18
- this.array[wordIndex] = this.array[wordIndex] | mask;
19
- }
20
- /**
21
- * Returns the maximum true bit.
22
- */ max() {
23
- for(let i = this.array.length - 1; i >= 0; i--){
24
- const bits = this.array[i];
25
- if (bits) {
26
- return BitSet.highBit(bits) + i * bitsPerWord;
27
- }
28
- }
29
- return 0;
30
- }
31
- /**
32
- * Returns the number of true bits.
33
- */ bitCount() {
34
- let result = 0;
35
- for(let i = 0; i < this.array.length; i++){
36
- result += BitSet.countBits(this.array[i]) // Assumes we never have bits set beyond the end
37
- ;
38
- }
39
- return result;
40
- }
41
- /**
42
- * Returns true if the size and contents are identical.
43
- * @param other another BitSet
44
- */ equals(other) {
45
- if (other.size !== this.size) {
46
- return false;
47
- }
48
- for(let i = 0; i < this.array.length; i++){
49
- if (this.array[i] !== other.array[i]) {
50
- return false;
51
- }
52
- }
53
- return true;
54
- }
55
- /**
56
- * Returns a JSON-encodable object readable by {@link import}.
57
- */ export() {
58
- return {
59
- size: this.size,
60
- content: encode(this.array)
61
- };
62
- }
63
- /**
64
- * Returns an object written by {@link export}.
65
- * @param data an object written by {@link export}
66
- */ static import(data) {
67
- if (typeof data.size !== "number") {
68
- throw Error("BitSet missing size");
69
- }
70
- if (typeof data.content !== "string") {
71
- throw Error("BitSet: missing content");
72
- }
73
- const result = new BitSet(data.size);
74
- const buffer = decode(data.content);
75
- result.array = new Uint8Array(buffer);
76
- return result;
77
- }
78
- /**
79
- * Returns the index of the maximum bit in the number, or -1 for 0
80
- * @bits an unsigned 8-bit number
81
- * ```js
82
- * @example
83
- * BitSet.highBit(0) // returns -1
84
- * BitSet.highBit(5) // returns 2
85
- * ```
86
- */ static highBit(bits) {
87
- let result = bitsPerWord - 1;
88
- let mask = 1 << result;
89
- while(result >= 0 && (mask & bits) !== mask){
90
- mask >>>= 1;
91
- result--;
92
- }
93
- return result;
94
- }
95
- /**
96
- * Returns the number of true bits in the number
97
- * @bits an unsigned 8-bit number
98
- * @example
99
- * ```js
100
- * BitSet.countBits(0) // returns 0
101
- * BitSet.countBits(3) // returns 2
102
- * ```
103
- */ static countBits(bits) {
104
- let result = bits & 1;
105
- while(bits !== 0){
106
- bits = bits >>> 1;
107
- result += bits & 1;
108
- }
109
- return result;
110
- }
111
- /**
112
- * Constructor. All bits are initially set to false.
113
- * @param size the number of bits that can be stored. (This is NOT required to be a multiple of 8.)
114
- */ constructor(size){
115
- const diff = bitsPerWord - size % bitsPerWord;
116
- this.size = size + ([
117
- 0,
118
- 8
119
- ].includes(diff) ? 0 : diff);
120
- this.array = new Uint8Array(Math.ceil(this.size / bitsPerWord));
121
- }
122
- }
123
- /**
124
- * A memory-efficient Boolean array. Contains just the minimal operations needed for our Bloom filter implementation.
125
- *
126
- * @author David Leppik
127
- */ export { BitSet as default };
128
-
129
- //# sourceMappingURL=bit-set.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/bit-set.ts"],"names":["encode","decode","bitsPerWord","BitSet","has","index","wordIndex","Math","floor","mask","array","add","max","i","length","bits","highBit","bitCount","result","countBits","equals","other","size","export","content","import","data","Error","buffer","Uint8Array","constructor","diff","includes","ceil"],"mappings":"AAAA,SAASA,MAAM,EAAEC,MAAM,QAAQ,uBAAsB;AAErD,MAAMC,cAAc;AAOL,MAAMC;IAgBnB;;;GAGC,GACD,AAAOC,IAAIC,KAAa,EAAW;QACjC,MAAMC,YAAYC,KAAKC,KAAK,CAACH,QAAQH;QACrC,MAAMO,OAAO,KAAKJ,QAAQH;QAC1B,OAAO,AAAC,CAAA,IAAI,CAACQ,KAAK,CAACJ,UAAU,GAAGG,IAAG,MAAO;IAC5C;IAEA;;;GAGC,GACD,AAAOE,IAAIN,KAAa,EAAE;QACxB,MAAMC,YAAYC,KAAKC,KAAK,CAACH,QAAQH;QACrC,MAAMO,OAAO,KAAKJ,QAAQH;QAC1B,IAAI,CAACQ,KAAK,CAACJ,UAAU,GAAG,IAAI,CAACI,KAAK,CAACJ,UAAU,GAAGG;IAClD;IAEA;;GAEC,GACD,AAAOG,MAAc;QACnB,IAAK,IAAIC,IAAI,IAAI,CAACH,KAAK,CAACI,MAAM,GAAG,GAAGD,KAAK,GAAGA,IAAK;YAC/C,MAAME,OAAO,IAAI,CAACL,KAAK,CAACG,EAAE;YAC1B,IAAIE,MAAM;gBACR,OAAOZ,OAAOa,OAAO,CAACD,QAAQF,IAAIX;YACpC,CAAC;QACH;QACA,OAAO;IACT;IAEA;;GAEC,GACD,AAAOe,WAAmB;QACxB,IAAIC,SAAS;QACb,IAAK,IAAIL,IAAI,GAAGA,IAAI,IAAI,CAACH,KAAK,CAACI,MAAM,EAAED,IAAK;YAC1CK,UAAUf,OAAOgB,SAAS,CAAC,IAAI,CAACT,KAAK,CAACG,EAAE,EAAE,gDAAgD;;QAC5F;QACA,OAAOK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A;;;GAGC,GACDY,YAAYR,IAAY,CAAE;QACxB,MAAMS,OAAO7B,cAAeoB,OAAOpB;QACnC,IAAI,CAACoB,IAAI,GAAGA,OAAQ,CAAA;YAAC;YAAG;SAAE,CAACU,QAAQ,CAACD,QAAQ,IAAIA,IAAI,AAAD;QACnD,IAAI,CAACrB,KAAK,GAAG,IAAImB,WAAWtB,KAAK0B,IAAI,CAAC,IAAI,CAACX,IAAI,GAAGpB;IACpD;AA6HF;AAhJA;;;;CAIC,GACD,SAAqBC,oBA2IpB"}
@@ -1,46 +0,0 @@
1
- /* file : formulas.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
- * Various formulas used with Bloom Filters
25
- * @namespace Formulas
26
- * @private
27
- */ /**
28
- * Compute the optimal size of a Bloom Filter
29
- * @param length - The length of the set used to fill the filter
30
- * @param errorRate - The targeted false positive rate
31
- * @return The optimal size of a Bloom Filter
32
- * @memberof Formulas
33
- */ export function optimalFilterSize(length, errorRate) {
34
- return Math.ceil(-(length * Math.log(errorRate) / Math.pow(Math.log(2), 2)));
35
- }
36
- /**
37
- * Compute the optimal number of hash functions to be used by a Bloom Filter
38
- * @param size - The size of the filter
39
- * @param length - The length of the set used to fill the filter
40
- * @return The optimal number of hash functions to be used by a Bloom Filter
41
- * @memberof Formulas
42
- */ export function optimalHashes(size, length) {
43
- return Math.ceil(size / length * Math.log(2));
44
- }
45
-
46
- //# sourceMappingURL=formulas.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/formulas.ts"],"names":["optimalFilterSize","length","errorRate","Math","ceil","log","pow","optimalHashes","size"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBA,GAEA;;;;CAIC,GAED;;;;;;CAMC,GACD,OAAO,SAASA,kBAAkBC,MAAc,EAAEC,SAAiB,EAAU;IAC3E,OAAOC,KAAKC,IAAI,CAAC,CAAE,CAAA,AAACH,SAASE,KAAKE,GAAG,CAACH,aAAcC,KAAKG,GAAG,CAACH,KAAKE,GAAG,CAAC,IAAI,EAAC;AAC7E,CAAC;AAED;;;;;;CAMC,GACD,OAAO,SAASE,cAAcC,IAAY,EAAEP,MAAc,EAAU;IAClE,OAAOE,KAAKC,IAAI,CAAC,AAACI,OAAOP,SAAUE,KAAKE,GAAG,CAAC;AAC9C,CAAC"}
@@ -1,181 +0,0 @@
1
- import fnv1a from "../fnv1a";
2
- import { getDefaultSeed, numberToHex } from "./utils";
3
- class Hashing {
4
- /**
5
- * Apply enhanced Double Hashing to produce a n-hash
6
- * @see {@link http://peterd.org/pcd-diss.pdf} s6.5.4
7
- * @param n - The indice of the hash function we want to produce
8
- * @param hashA - The result of the first hash function applied to a value.
9
- * @param hashB - The result of the second hash function applied to a value.
10
- * @param size - The size of the datastructures associated to the hash context (ex: the size of a Bloom Filter)
11
- * @return The result of hash_n applied to a value.
12
- * @memberof Hashing
13
- * @author Thomas Minier
14
- * @author Arnaud Grall
15
- */ doubleHashing(n, hashA, hashB, size) {
16
- return Math.abs((hashA + n * hashB + Math.floor((n ** 3 - n) / 6)) % size);
17
- }
18
- /**
19
- * Generate a set of distinct indexes on interval [0, size) using the double hashing technique
20
- * For generating efficiently distinct indexes we re-hash after detecting a cycle by changing slightly the seed.
21
- * It has the effect of generating faster distinct indexes without loosing entirely the utility of the double hashing.
22
- * For small number of indexes it will work perfectly. For a number close to the size, and size very large
23
- * Advise: do not generate `size` indexes for a large interval. In practice, size should be equal
24
- * to the number of hash functions used and is often low.
25
- *
26
- * @param element - The element to hash
27
- * @param size - the range on which we can generate an index [0, size) = size
28
- * @param number - The number of indexes desired
29
- * @param seed - The seed used
30
- * @return Array<number>
31
- * @author Arnaud Grall
32
- * @author Simon Woolf (SimonWoolf)
33
- */ getDistinctIndexes(element, size, number, seed) {
34
- if (seed === undefined) {
35
- seed = getDefaultSeed();
36
- }
37
- let n = 0;
38
- const indexes = new Set();
39
- let hashes = this.hashTwice(element, seed);
40
- // let cycle = 0
41
- while(indexes.size < number){
42
- const ind = hashes.first % size;
43
- if (!indexes.has(ind)) {
44
- indexes.add(ind);
45
- }
46
- hashes.first = (hashes.first + hashes.second) % size;
47
- hashes.second = (hashes.second + n) % size;
48
- n++;
49
- if (n > size) {
50
- // Enhanced double hashing stops cycles of length less than `size` in the case where
51
- // size is coprime with the second hash. But you still get cycles of length `size`.
52
- // So if we reach there and haven't finished, append a prime to the input and
53
- // rehash.
54
- seed++;
55
- hashes = this.hashTwice(element, seed);
56
- }
57
- }
58
- return [
59
- ...indexes.values()
60
- ];
61
- }
62
- /**
63
- * Generate N indexes on range [0, size)
64
- * It uses the double hashing technique to generate the indexes.
65
- * It hash twice the value only once before generating the indexes.
66
- * Warning: you can have a lot of modulo collisions.
67
- * @param element - The element to hash
68
- * @param size - The range on which we can generate the index, exclusive
69
- * @param hashCount - The number of indexes we want
70
- * @return An array of indexes on range [0, size)
71
- */ getIndexes(element, size, hashCount, seed) {
72
- if (seed === undefined) {
73
- seed = getDefaultSeed();
74
- }
75
- const arr = [];
76
- const hashes = this.hashTwice(element, seed);
77
- for(let i = 0; i < hashCount; i++){
78
- arr.push(this.doubleHashing(i, hashes.first, hashes.second, size));
79
- }
80
- return arr;
81
- }
82
- /**
83
- * @internal
84
- * Hash an element of type {@link HashableInput} into {@link Number}
85
- * Can be overrided as long as you return a value of type {@link Number}
86
- * Don't forget to use the seed when hashing, otherwise if some kind of randomness is in the process
87
- * you may have inconsistent behaviors between 2 runs.
88
- * @param element
89
- * @param seed
90
- * @returns A 64bits floating point {@link Number}
91
- */ serialize(element, seed) {
92
- if (!seed) {
93
- seed = getDefaultSeed();
94
- }
95
- return Number(fnv1a(element, {
96
- seed
97
- }));
98
- }
99
- /**
100
- * (64-bits only) Hash a value into two values (in hex or integer format)
101
- * @param value - The value to hash
102
- * @param asInt - (optional) If True, the values will be returned as an integer. Otherwise, as hexadecimal values.
103
- * @param seed the seed used for hashing
104
- * @return The results of the hash functions applied to the value (in hex or integer)
105
- * @author Arnaud Grall & Thomas Minier
106
- */ hashTwice(value, seed) {
107
- if (seed === undefined) {
108
- seed = getDefaultSeed();
109
- }
110
- return {
111
- first: this.serialize(value, seed + 1),
112
- second: this.serialize(value, seed + 2)
113
- };
114
- }
115
- /**
116
- * Hash twice an element into their HEX string representations
117
- * @param value
118
- * @param seed
119
- * @returns TwoHashesTemplated<string>
120
- */ hashTwiceAsString(value, seed) {
121
- const { first , second } = this.hashTwice(value, seed);
122
- return {
123
- first: numberToHex(first),
124
- second: numberToHex(second)
125
- };
126
- }
127
- /**
128
- * (64-bits only) Same as hashTwice but return Numbers and String equivalent
129
- * @param val the value to hash
130
- * @param seed the seed to change when hashing
131
- * @return TwoHashesIntAndString
132
- * @author Arnaud Grall
133
- */ hashTwiceIntAndString(val, seed) {
134
- if (seed === undefined) {
135
- seed = getDefaultSeed();
136
- }
137
- const one = this.hashIntAndString(val, seed + 1);
138
- const two = this.hashIntAndString(val, seed + 2);
139
- return {
140
- int: {
141
- first: one.int,
142
- second: two.int
143
- },
144
- string: {
145
- first: one.string,
146
- second: two.string
147
- }
148
- };
149
- }
150
- /**
151
- * Hash an item as an unsigned int
152
- * @param elem - Element to hash
153
- * @param seed - The hash seed. If its is UINT32 make sure to set the length to 32
154
- * @param length - The length of hashes (defaults to 32 bits)
155
- * @return The hash value as an unsigned int
156
- * @author Arnaud Grall
157
- */ hashAsInt(elem, seed) {
158
- if (seed === undefined) {
159
- seed = getDefaultSeed();
160
- }
161
- return this.serialize(elem, seed);
162
- }
163
- /**
164
- * Hash an item and return its number and HEX string representation
165
- * @param elem - Element to hash
166
- * @param seed - The hash seed. If its is UINT32 make sure to set the length to 32
167
- * @param base - The base in which the string will be returned, default: 16
168
- * @param length - The length of hashes (defaults to 32 bits)
169
- * @return The item hased as an int and a string
170
- * @author Arnaud Grall
171
- */ hashIntAndString(elem, seed) {
172
- const hash = this.hashAsInt(elem, seed);
173
- return {
174
- int: hash,
175
- string: numberToHex(hash)
176
- };
177
- }
178
- }
179
- export { Hashing as default };
180
-
181
- //# sourceMappingURL=hashing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/hashing.ts"],"names":["fnv1a","getDefaultSeed","numberToHex","Hashing","doubleHashing","n","hashA","hashB","size","Math","abs","floor","getDistinctIndexes","element","number","seed","undefined","indexes","Set","hashes","hashTwice","ind","first","has","add","second","values","getIndexes","hashCount","arr","i","push","serialize","Number","value","hashTwiceAsString","hashTwiceIntAndString","val","one","hashIntAndString","two","int","string","hashAsInt","elem","hash"],"mappings":"AAAA,OAAOA,WAAW,WAAU;AAC5B,SAASC,cAAc,EAAEC,WAAW,QAAQ,UAAS;AAkCtC,MAAMC;IACnB;;;;;;;;;;;GAWC,GACD,AAAOC,cACLC,CAAS,EACTC,KAAa,EACbC,KAAa,EACbC,IAAY,EACJ;QACR,OAAOC,KAAKC,GAAG,CAAC,AAACJ,CA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AAO,IAAI,CAAC+B,SAAS,CAACY,MAAM7B;IAC9B;IAEA;;;;;;;;GAQC,GACD,AAAOwB,iBAAiBK,IAAmB,EAAE7B,IAAa,EAAE;QAC1D,MAAM8B,OAAO,IAAI,CAACF,SAAS,CAACC,MAAM7B;QAClC,OAAO;YAAE0B,KAAKI;YAAMH,QAAQxC,YAAY2C;QAAM;IAChD;AACF;AA/MA,SAAqB1C,qBA+MpB"}
@@ -1,158 +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
- */ import BaseFilter from "./base-filter";
25
- import BitSet from "./bit-set";
26
- import { optimalFilterSize, optimalHashes } from "./formulas";
27
- /**
28
- * A Bloom filter is a space-efficient probabilistic data structure, conceived by Burton Howard Bloom in 1970,
29
- * that is used to test whether an element is a member of a set. False positive matches are possible, but false negatives are not.
30
- *
31
- * Reference: Bloom, B. H. (1970). Space/time trade-offs in hash coding with allowable errors. Communications of the ACM, 13(7), 422-426.
32
- * @see {@link http://crystal.uta.edu/~mcguigan/cse6350/papers/Bloom.pdf} for more details about classic Bloom Filters.
33
- * @author Thomas Minier
34
- * @author Arnaud Grall
35
- */ export class BloomFilter extends BaseFilter {
36
- /**
37
- * Create an optimal bloom filter providing the maximum of elements stored and the error rate desired
38
- * @param nbItems - The maximum number of item to store
39
- * @param errorRate - The error rate desired for a maximum of items inserted
40
- * @return A new {@link BloomFilter}
41
- */ static create(nbItems, errorRate) {
42
- const size = optimalFilterSize(nbItems, errorRate);
43
- const hashes = optimalHashes(size, nbItems);
44
- return new this(size, hashes);
45
- }
46
- /**
47
- * Build a new Bloom Filter from an existing iterable with a fixed error rate
48
- * @param items - The iterable used to populate the filter
49
- * @param errorRate - The error rate, i.e. 'false positive' rate, targeted by the filter
50
- * @param seed - The random number seed (optional)
51
- * @return A new Bloom Filter filled with the iterable's elements
52
- * @example
53
- * ```js
54
- * // create a filter with a false positive rate of 0.1
55
- * const filter = BloomFilter.from(['alice', 'bob', 'carl'], 0.1);
56
- * ```
57
- */ static from(items, errorRate, seed) {
58
- const array = Array.from(items);
59
- const filter = BloomFilter.create(array.length, errorRate);
60
- if (typeof seed === "number") {
61
- filter.seed = seed;
62
- }
63
- array.forEach((element)=>filter.add(element));
64
- return filter;
65
- }
66
- /**
67
- * Get the optimal size of the filter
68
- * @return The size of the filter
69
- */ get size() {
70
- return this._size;
71
- }
72
- /**
73
- * Get the number of bits currently set in the filter
74
- * @return The filter length
75
- */ get length() {
76
- return this._filter.bitCount();
77
- }
78
- /**
79
- * Add an element to the filter
80
- * @param element - The element to add
81
- * @example
82
- * ```js
83
- * const filter = new BloomFilter(15, 0.1);
84
- * filter.add('foo');
85
- * ```
86
- */ add(element) {
87
- const indexes = this._hashing.getIndexes(element, this._size, this._nbHashes, this.seed);
88
- for(let i = 0; i < indexes.length; i++){
89
- this._filter.add(indexes[i]);
90
- }
91
- }
92
- /**
93
- * Test an element for membership
94
- * @param element - The element to look for in the filter
95
- * @return False if the element is definitively not in the filter, True is the element might be in the filter
96
- * @example
97
- * ```js
98
- * const filter = new BloomFilter(15, 0.1);
99
- * filter.add('foo');
100
- * console.log(filter.has('foo')); // output: true
101
- * console.log(filter.has('bar')); // output: false
102
- * ```
103
- */ has(element) {
104
- const indexes = this._hashing.getIndexes(element, this._size, this._nbHashes, this.seed);
105
- for(let i = 0; i < indexes.length; i++){
106
- if (!this._filter.has(indexes[i])) {
107
- return false;
108
- }
109
- }
110
- return true;
111
- }
112
- /**
113
- * Get the current false positive rate (or error rate) of the filter
114
- * @return The current false positive rate of the filter
115
- * @example
116
- * ```js
117
- * const filter = new BloomFilter(15, 0.1);
118
- * console.log(filter.rate()); // output: something around 0.1
119
- * ```
120
- */ rate() {
121
- return Math.pow(1 - Math.exp(-this.length / this._size), this._nbHashes);
122
- }
123
- /**
124
- * Check if another Bloom Filter is equal to this one
125
- * @param other - The filter to compare to this one
126
- * @return True if they are equal, false otherwise
127
- */ equals(other) {
128
- if (this._size !== other._size || this._nbHashes !== other._nbHashes) {
129
- return false;
130
- }
131
- return this._filter.equals(other._filter);
132
- }
133
- export() {
134
- return {
135
- bitset: this._filter.export(),
136
- hashes: this._nbHashes,
137
- size: this._size
138
- };
139
- }
140
- import(data) {
141
- this._filter = BitSet.import(data.bitset);
142
- }
143
- /**
144
- * Constructor
145
- * @param size - The number of cells
146
- * @param nbHashes - The number of hash functions used
147
- */ constructor(size, nbHashes){
148
- super();
149
- if (nbHashes < 1) {
150
- throw new Error("A BloomFilter cannot uses less than one hash function, while you tried to use " + nbHashes + ".");
151
- }
152
- this._size = size;
153
- this._nbHashes = nbHashes;
154
- this._filter = new BitSet(size);
155
- }
156
- }
157
-
158
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/shared/lib/bloom-filter/index.ts"],"names":["BaseFilter","BitSet","optimalFilterSize","optimalHashes","BloomFilter","create","nbItems","errorRate","size","hashes","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","constructor","nbHashes","Error"],"mappings":"AAAA,6DAA6D;AAC7D;;;;;;;;;;;;;;;;;;;;;;AAsBA,GAEA,OAAOA,gBAAgB,gBAAe;AACtC,OAAOC,YAAY,YAAW;AAC9B,SAASC,iBAAiB,EAAEC,aAAa,QAAQ,aAAY;AAG7D;;;;;;;;CAQC,GACD,OAAO,MAAMC,oBAAoBJ;IAsB/B;;;;;GAKC,GACD,OAAcK,OAAOC,OAAe,EAAEC,SAAiB,EAAe;QACpE,MAAMC,OAAON,kBAAkBI,SAASC;QACxC,MAAME,SAASN,cAAcK,MAAMF;QACnC,OAAO,IAAI,IAAI,CAACE,MAAMC;IACxB;IAEA;;;;;;;;;;;GAWC,GACD,OAAcC,KACZC,KAA8B,EAC9BJ,SAAiB,EACjBK,IAAa,EACA;QACb,MAAMC,QAAQC,MAAMJ,IAAI,CAACC;QACzB,MAAMI,SAASX,YAAYC,MAAM,CAACQ,MAAMG,MAAM,EAAET;QAChD,IAAI,OAAOK,SAAS,UAAU;YAC5BG,OAAOH,IAAI,GAAGA;QAChB,CAAC;QACDC,MAAMI,OAAO,CAAC,CAACC,UAAYH,OAAOI,GAAG,CAACD;QACtC,OAAOH;IACT;IAEA;;;GAGC,GACD,IAAIP,OAAe;QACjB,OAAO,IAAI,CAACY,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,CAACM,SAAS,EACd,IAAI,CAACd,IAAI;QAEX,IAA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