@sepiariver/unique-set 2.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PERF.md +30 -140
- package/README.md +48 -60
- package/dist/index.d.mts +12 -38
- package/dist/index.d.ts +15 -0
- package/dist/index.js +183 -375
- package/dist/index.mjs +132 -154
- package/index.ts +147 -177
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -1,389 +1,197 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// index.ts
|
|
31
|
+
var unique_set_exports = {};
|
|
32
|
+
__export(unique_set_exports, {
|
|
33
|
+
MapSet: () => MapSet,
|
|
34
|
+
UniqueSet: () => MapSet,
|
|
35
|
+
structuralHash: () => structuralHash
|
|
5
36
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
21
|
-
|
|
22
|
-
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
|
|
23
|
-
|
|
24
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
25
|
-
|
|
26
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
-
|
|
28
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
29
|
-
|
|
30
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
31
|
-
|
|
32
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
33
|
-
|
|
34
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
35
|
-
|
|
36
|
-
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
37
|
-
|
|
38
|
-
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
39
|
-
|
|
40
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
41
|
-
|
|
42
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
43
|
-
|
|
44
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
45
|
-
|
|
46
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
47
|
-
|
|
48
|
-
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
49
|
-
|
|
50
|
-
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
51
|
-
|
|
52
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
53
|
-
|
|
54
|
-
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
55
|
-
|
|
56
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
57
|
-
|
|
58
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
59
|
-
|
|
60
|
-
var UniqueSet = /*#__PURE__*/function (_Set) {
|
|
61
|
-
_inherits(UniqueSet, _Set);
|
|
62
|
-
|
|
63
|
-
var _super = _createSuper(UniqueSet);
|
|
64
|
-
|
|
65
|
-
function UniqueSet() {
|
|
66
|
-
var _this;
|
|
67
|
-
|
|
68
|
-
var iterable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
69
|
-
|
|
70
|
-
_classCallCheck(this, UniqueSet);
|
|
71
|
-
|
|
72
|
-
if (!Array.isArray(iterable) && !iterable[Symbol.iterator]) {
|
|
73
|
-
throw new TypeError("UniqueSet requires an iterable");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_this = _super.call(this);
|
|
77
|
-
|
|
78
|
-
var _iterator = _createForOfIteratorHelper(iterable),
|
|
79
|
-
_step;
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
83
|
-
var item = _step.value;
|
|
84
|
-
|
|
85
|
-
_this.add(item);
|
|
86
|
-
}
|
|
87
|
-
} catch (err) {
|
|
88
|
-
_iterator.e(err);
|
|
89
|
-
} finally {
|
|
90
|
-
_iterator.f();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return _this;
|
|
37
|
+
module.exports = __toCommonJS(unique_set_exports);
|
|
38
|
+
var import_es6 = __toESM(require("fast-deep-equal/es6/index.js"));
|
|
39
|
+
var _f64 = new Float64Array(1);
|
|
40
|
+
var _u8 = new Uint8Array(_f64.buffer);
|
|
41
|
+
var structuralHash = (value) => {
|
|
42
|
+
return _shash(value, 2166136261) >>> 0;
|
|
43
|
+
};
|
|
44
|
+
var _mix = (hash, byte) => {
|
|
45
|
+
return Math.imul(hash ^ byte, 16777619);
|
|
46
|
+
};
|
|
47
|
+
var _mixStr = (hash, str) => {
|
|
48
|
+
for (let i = 0; i < str.length; i++) {
|
|
49
|
+
hash = Math.imul(hash ^ str.charCodeAt(i), 16777619);
|
|
94
50
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
51
|
+
return hash;
|
|
52
|
+
};
|
|
53
|
+
var _shash = (value, hash) => {
|
|
54
|
+
if (value === null) return _mix(hash, 0);
|
|
55
|
+
if (value === void 0) return _mix(hash, 1);
|
|
56
|
+
switch (typeof value) {
|
|
57
|
+
case "boolean":
|
|
58
|
+
return _mix(hash, value ? 3 : 2);
|
|
59
|
+
case "number":
|
|
60
|
+
hash = _mix(hash, 5);
|
|
61
|
+
if (isNaN(value)) return _mix(hash, 4);
|
|
62
|
+
if (value === 0) return _mix(hash, 48);
|
|
63
|
+
_f64[0] = value;
|
|
64
|
+
for (let i = 0; i < 8; i++) hash = _mix(hash, _u8[i]);
|
|
65
|
+
return hash;
|
|
66
|
+
case "string":
|
|
67
|
+
hash = _mix(hash, 6);
|
|
68
|
+
return _mixStr(hash, value);
|
|
69
|
+
case "bigint":
|
|
70
|
+
hash = _mix(hash, 7);
|
|
71
|
+
return _mixStr(hash, value.toString());
|
|
72
|
+
case "function":
|
|
73
|
+
case "symbol":
|
|
74
|
+
hash = _mix(hash, 8);
|
|
75
|
+
return _mixStr(hash, String(value));
|
|
76
|
+
default:
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
hash = _mix(hash, 16);
|
|
81
|
+
for (let i = 0; i < value.length; i++) hash = _shash(value[i], hash);
|
|
82
|
+
return hash;
|
|
83
|
+
}
|
|
84
|
+
if (value instanceof Map) {
|
|
85
|
+
hash = _mix(hash, 17);
|
|
86
|
+
const entries = Array.from(value.entries()).sort(
|
|
87
|
+
([a], [b]) => String(a).localeCompare(String(b))
|
|
88
|
+
);
|
|
89
|
+
for (const [k, v] of entries) {
|
|
90
|
+
hash = _shash(k, hash);
|
|
91
|
+
hash = _shash(v, hash);
|
|
92
|
+
}
|
|
93
|
+
return hash;
|
|
94
|
+
}
|
|
95
|
+
if (value instanceof Set) {
|
|
96
|
+
hash = _mix(hash, 18);
|
|
97
|
+
for (const v of value) hash = _shash(v, hash);
|
|
98
|
+
return hash;
|
|
99
|
+
}
|
|
100
|
+
if (value instanceof Date) {
|
|
101
|
+
hash = _mix(hash, 20);
|
|
102
|
+
_f64[0] = value.getTime();
|
|
103
|
+
for (let i = 0; i < 8; i++) hash = _mix(hash, _u8[i]);
|
|
104
|
+
return hash;
|
|
105
|
+
}
|
|
106
|
+
if (value instanceof RegExp) {
|
|
107
|
+
hash = _mix(hash, 21);
|
|
108
|
+
return _mixStr(hash, value.toString());
|
|
109
|
+
}
|
|
110
|
+
hash = _mix(hash, 19);
|
|
111
|
+
const keys = Object.keys(value).sort();
|
|
112
|
+
for (const key of keys) {
|
|
113
|
+
hash = _mixStr(hash, key);
|
|
114
|
+
hash = _shash(value[key], hash);
|
|
115
|
+
}
|
|
116
|
+
return hash;
|
|
117
|
+
};
|
|
118
|
+
var MapSet = class {
|
|
119
|
+
#map;
|
|
120
|
+
#size;
|
|
121
|
+
constructor(iterable = []) {
|
|
147
122
|
if (!Array.isArray(iterable) && !iterable[Symbol.iterator]) {
|
|
148
|
-
throw new TypeError("
|
|
123
|
+
throw new TypeError("MapSet requires an iterable");
|
|
149
124
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
options = {};
|
|
125
|
+
this.#map = /* @__PURE__ */ new Map();
|
|
126
|
+
this.#size = 0;
|
|
127
|
+
for (const item of iterable) {
|
|
128
|
+
this.add(item);
|
|
155
129
|
}
|
|
156
|
-
|
|
157
|
-
var _options = options,
|
|
158
|
-
_options$size = _options.size,
|
|
159
|
-
size = _options$size === void 0 ? 6553577 : _options$size,
|
|
160
|
-
_options$hashCount = _options.hashCount,
|
|
161
|
-
hashCount = _options$hashCount === void 0 ? 7 : _options$hashCount;
|
|
162
|
-
|
|
163
|
-
if (typeof size !== "number" || size <= 0) {
|
|
164
|
-
6553577, _readOnlyError("size"); // Targeting < 1 collision per 100,000 elements, ~819 KB memory, needs 7 hashes
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
_this2.aSize = _this2._findNextPrime(size);
|
|
168
|
-
|
|
169
|
-
if (typeof hashCount !== "number" || hashCount <= 0) {
|
|
170
|
-
7, _readOnlyError("hashCount");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
_this2.hashCount = hashCount;
|
|
174
|
-
_this2.bitArray = new Uint8Array(Math.ceil(size / 8));
|
|
175
|
-
|
|
176
|
-
var _iterator3 = _createForOfIteratorHelper(iterable),
|
|
177
|
-
_step3;
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
181
|
-
var item = _step3.value;
|
|
182
|
-
|
|
183
|
-
_this2.add(item);
|
|
184
|
-
}
|
|
185
|
-
} catch (err) {
|
|
186
|
-
_iterator3.e(err);
|
|
187
|
-
} finally {
|
|
188
|
-
_iterator3.f();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return _this2;
|
|
192
130
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return num;
|
|
205
|
-
}
|
|
206
|
-
}, {
|
|
207
|
-
key: "_isPrime",
|
|
208
|
-
value: function _isPrime(num) {
|
|
209
|
-
if (num < 2) return false;
|
|
210
|
-
if (num === 2 || num === 3) return true;
|
|
211
|
-
if (num % 2 === 0 || num % 3 === 0) return false;
|
|
212
|
-
var sqrt = Math.floor(Math.sqrt(num));
|
|
213
|
-
|
|
214
|
-
for (var i = 5; i <= sqrt; i += 6) {
|
|
215
|
-
if (num % i === 0 || num % (i + 2) === 0) return false;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
}, {
|
|
221
|
-
key: "_serialize",
|
|
222
|
-
value: function _serialize(item) {
|
|
223
|
-
if (typeof item === "number" && isNaN(item)) {
|
|
224
|
-
return "NaN";
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (item && _typeof(item) === "object") {
|
|
228
|
-
var serialize = this._serialize.bind(this);
|
|
229
|
-
|
|
230
|
-
if (Array.isArray(item)) {
|
|
231
|
-
return "[".concat(item.map(serialize).join(","), "]");
|
|
232
|
-
} else {
|
|
233
|
-
return "{".concat(Object.entries(item).sort(function (_ref, _ref2) {
|
|
234
|
-
var _ref3 = _slicedToArray(_ref, 1),
|
|
235
|
-
a = _ref3[0];
|
|
236
|
-
|
|
237
|
-
var _ref4 = _slicedToArray(_ref2, 1),
|
|
238
|
-
b = _ref4[0];
|
|
239
|
-
|
|
240
|
-
return a.localeCompare(b);
|
|
241
|
-
}).map(function (_ref5) {
|
|
242
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
243
|
-
k = _ref6[0],
|
|
244
|
-
v = _ref6[1];
|
|
245
|
-
|
|
246
|
-
return "".concat(k, ":").concat(serialize(v));
|
|
247
|
-
}).join(","), "}");
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return String(item);
|
|
252
|
-
}
|
|
253
|
-
}, {
|
|
254
|
-
key: "_hashes",
|
|
255
|
-
value: function _hashes(item) {
|
|
256
|
-
var hashes = [];
|
|
257
|
-
|
|
258
|
-
var str = this._serialize(item);
|
|
259
|
-
|
|
260
|
-
var hash = this._fnv1a(str); // Base hash
|
|
261
|
-
// Bloom into hashCount hash values
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
for (var i = 0; i < this.hashCount; i++) {
|
|
265
|
-
hash %= this.aSize; // Ensure within bounds
|
|
266
|
-
// Track
|
|
267
|
-
|
|
268
|
-
hashes.push(hash); // Modify
|
|
269
|
-
|
|
270
|
-
hash = (hash ^ hash >>> 13) * 0xc2b2ae35;
|
|
271
|
-
hash >>>= 0; // Ensure unsigned 32-bit integer
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return hashes;
|
|
275
|
-
}
|
|
276
|
-
}, {
|
|
277
|
-
key: "_fnv1a",
|
|
278
|
-
value: function _fnv1a(str) {
|
|
279
|
-
if (typeof str !== "string") {
|
|
280
|
-
str = String(str);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
var hash = 2166136261; // FNV offset basis for 32-bit
|
|
284
|
-
|
|
285
|
-
for (var i = 0; i < str.length; i++) {
|
|
286
|
-
hash ^= str.charCodeAt(i);
|
|
287
|
-
hash = hash * 16777619 >>> 0; // Multiply by the FNV prime and ensure 32-bit unsigned
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return hash >>> 0;
|
|
291
|
-
}
|
|
292
|
-
}, {
|
|
293
|
-
key: "_setBits",
|
|
294
|
-
value: function _setBits(hashes) {
|
|
295
|
-
var _iterator4 = _createForOfIteratorHelper(hashes),
|
|
296
|
-
_step4;
|
|
297
|
-
|
|
298
|
-
try {
|
|
299
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
300
|
-
var hash = _step4.value;
|
|
301
|
-
var index = Math.floor(hash / 8);
|
|
302
|
-
var bit = hash % 8;
|
|
303
|
-
this.bitArray[index] |= 1 << bit;
|
|
304
|
-
}
|
|
305
|
-
} catch (err) {
|
|
306
|
-
_iterator4.e(err);
|
|
307
|
-
} finally {
|
|
308
|
-
_iterator4.f();
|
|
131
|
+
add(value) {
|
|
132
|
+
const hash = structuralHash(value);
|
|
133
|
+
const bucket = this.#map.get(hash);
|
|
134
|
+
if (!bucket) {
|
|
135
|
+
this.#map.set(hash, [value]);
|
|
136
|
+
this.#size++;
|
|
137
|
+
} else {
|
|
138
|
+
for (const item of bucket) {
|
|
139
|
+
if ((0, import_es6.default)(value, item)) return this;
|
|
309
140
|
}
|
|
141
|
+
bucket.push(value);
|
|
142
|
+
this.#size++;
|
|
310
143
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
has(value) {
|
|
147
|
+
const hash = structuralHash(value);
|
|
148
|
+
const bucket = this.#map.get(hash);
|
|
149
|
+
if (!bucket) return false;
|
|
150
|
+
for (const item of bucket) {
|
|
151
|
+
if ((0, import_es6.default)(value, item)) return true;
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
delete(value) {
|
|
156
|
+
const hash = structuralHash(value);
|
|
157
|
+
const bucket = this.#map.get(hash);
|
|
158
|
+
if (!bucket) return false;
|
|
159
|
+
for (let i = 0; i < bucket.length; i++) {
|
|
160
|
+
if ((0, import_es6.default)(value, bucket[i])) {
|
|
161
|
+
bucket.splice(i, 1);
|
|
162
|
+
if (bucket.length === 0) this.#map.delete(hash);
|
|
163
|
+
this.#size--;
|
|
164
|
+
return true;
|
|
331
165
|
}
|
|
332
|
-
|
|
333
|
-
return true;
|
|
334
166
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
try {
|
|
349
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
350
|
-
var i = _step6.value;
|
|
351
|
-
|
|
352
|
-
if ((0, _fastDeepEqual["default"])(o, i)) {
|
|
353
|
-
return true;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
} catch (err) {
|
|
357
|
-
_iterator6.e(err);
|
|
358
|
-
} finally {
|
|
359
|
-
_iterator6.f();
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
get size() {
|
|
170
|
+
return this.#size;
|
|
171
|
+
}
|
|
172
|
+
clear() {
|
|
173
|
+
this.#map.clear();
|
|
174
|
+
this.#size = 0;
|
|
175
|
+
}
|
|
176
|
+
forEach(callback, thisArg) {
|
|
177
|
+
for (const bucket of this.#map.values()) {
|
|
178
|
+
for (const value of bucket) {
|
|
179
|
+
callback.call(thisArg, value, value, this);
|
|
360
180
|
}
|
|
361
|
-
|
|
362
|
-
return false;
|
|
363
181
|
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
var hashes = this._hashes(o);
|
|
369
|
-
|
|
370
|
-
this._setBits(hashes);
|
|
371
|
-
|
|
372
|
-
_get(_getPrototypeOf(BloomSet.prototype), "add", this).call(this, o);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return this;
|
|
182
|
+
}
|
|
183
|
+
*values() {
|
|
184
|
+
for (const bucket of this.#map.values()) {
|
|
185
|
+
yield* bucket;
|
|
376
186
|
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
};
|
|
389
|
-
}
|
|
187
|
+
}
|
|
188
|
+
*[Symbol.iterator]() {
|
|
189
|
+
yield* this.values();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
MapSet,
|
|
195
|
+
UniqueSet,
|
|
196
|
+
structuralHash
|
|
197
|
+
});
|