serializable-bptree 4.0.0 → 4.0.2

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.
@@ -61,368 +61,36 @@ var StringComparator = class extends ValueComparator {
61
61
  }
62
62
  };
63
63
 
64
- // node_modules/cachebranch/dist/esm/index.mjs
65
- var CacheBranch = class {
66
- data;
67
- branches;
68
- constructor(data) {
69
- this.data = data;
70
- this.branches = /* @__PURE__ */ new Map();
64
+ // src/utils/InvertedWeakMap.ts
65
+ var InvertedWeakMap = class {
66
+ _map;
67
+ _registry;
68
+ constructor() {
69
+ this._map = /* @__PURE__ */ new Map();
70
+ this._registry = new FinalizationRegistry((key) => this._map.delete(key));
71
71
  }
72
- /**
73
- * The method splits the provided key value into tokens and returns them as an array.
74
- * For instance, if you pass `'user/name/middle'` as the parameter, it will return `['user', 'name', 'middle']` as the split values.
75
- * @param key The key value to split.
76
- */
77
- tokens(key) {
78
- return key.split("/");
79
- }
80
- to(key, getNextBranch) {
81
- const tokens = this.tokens(key);
82
- let current = this;
83
- for (let i = 0, len = tokens.length; i < len; i++) {
84
- const last = i === len - 1;
85
- const key2 = tokens[i];
86
- const next = getNextBranch(current, key2, i, last);
87
- if (next === null) {
88
- return void 0;
89
- }
90
- current = next;
91
- }
92
- return current;
93
- }
94
- };
95
- var VOID = -1;
96
- var PRIMITIVE = 0;
97
- var ARRAY = 1;
98
- var OBJECT = 2;
99
- var DATE = 3;
100
- var REGEXP = 4;
101
- var MAP = 5;
102
- var SET = 6;
103
- var ERROR = 7;
104
- var BIGINT = 8;
105
- var env = typeof self === "object" ? self : globalThis;
106
- var deserializer = ($, _) => {
107
- const as = (out, index) => {
108
- $.set(index, out);
109
- return out;
110
- };
111
- const unpair = (index) => {
112
- if ($.has(index))
113
- return $.get(index);
114
- const [type, value] = _[index];
115
- switch (type) {
116
- case PRIMITIVE:
117
- case VOID:
118
- return as(value, index);
119
- case ARRAY: {
120
- const arr = as([], index);
121
- for (const index2 of value)
122
- arr.push(unpair(index2));
123
- return arr;
124
- }
125
- case OBJECT: {
126
- const object = as({}, index);
127
- for (const [key, index2] of value)
128
- object[unpair(key)] = unpair(index2);
129
- return object;
130
- }
131
- case DATE:
132
- return as(new Date(value), index);
133
- case REGEXP: {
134
- const { source, flags } = value;
135
- return as(new RegExp(source, flags), index);
136
- }
137
- case MAP: {
138
- const map = as(/* @__PURE__ */ new Map(), index);
139
- for (const [key, index2] of value)
140
- map.set(unpair(key), unpair(index2));
141
- return map;
142
- }
143
- case SET: {
144
- const set = as(/* @__PURE__ */ new Set(), index);
145
- for (const index2 of value)
146
- set.add(unpair(index2));
147
- return set;
148
- }
149
- case ERROR: {
150
- const { name, message } = value;
151
- return as(new env[name](message), index);
152
- }
153
- case BIGINT:
154
- return as(BigInt(value), index);
155
- case "BigInt":
156
- return as(Object(BigInt(value)), index);
157
- }
158
- return as(new env[type](value), index);
159
- };
160
- return unpair;
161
- };
162
- var deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
163
- var EMPTY = "";
164
- var { toString } = {};
165
- var { keys } = Object;
166
- var typeOf = (value) => {
167
- const type = typeof value;
168
- if (type !== "object" || !value)
169
- return [PRIMITIVE, type];
170
- const asString = toString.call(value).slice(8, -1);
171
- switch (asString) {
172
- case "Array":
173
- return [ARRAY, EMPTY];
174
- case "Object":
175
- return [OBJECT, EMPTY];
176
- case "Date":
177
- return [DATE, EMPTY];
178
- case "RegExp":
179
- return [REGEXP, EMPTY];
180
- case "Map":
181
- return [MAP, EMPTY];
182
- case "Set":
183
- return [SET, EMPTY];
184
- }
185
- if (asString.includes("Array"))
186
- return [ARRAY, asString];
187
- if (asString.includes("Error"))
188
- return [ERROR, asString];
189
- return [OBJECT, asString];
190
- };
191
- var shouldSkip = ([TYPE, type]) => TYPE === PRIMITIVE && (type === "function" || type === "symbol");
192
- var serializer = (strict, json, $, _) => {
193
- const as = (out, value) => {
194
- const index = _.push(out) - 1;
195
- $.set(value, index);
196
- return index;
197
- };
198
- const pair = (value) => {
199
- if ($.has(value))
200
- return $.get(value);
201
- let [TYPE, type] = typeOf(value);
202
- switch (TYPE) {
203
- case PRIMITIVE: {
204
- let entry = value;
205
- switch (type) {
206
- case "bigint":
207
- TYPE = BIGINT;
208
- entry = value.toString();
209
- break;
210
- case "function":
211
- case "symbol":
212
- if (strict)
213
- throw new TypeError("unable to serialize " + type);
214
- entry = null;
215
- break;
216
- case "undefined":
217
- return as([VOID], value);
218
- }
219
- return as([TYPE, entry], value);
220
- }
221
- case ARRAY: {
222
- if (type)
223
- return as([type, [...value]], value);
224
- const arr = [];
225
- const index = as([TYPE, arr], value);
226
- for (const entry of value)
227
- arr.push(pair(entry));
228
- return index;
229
- }
230
- case OBJECT: {
231
- if (type) {
232
- switch (type) {
233
- case "BigInt":
234
- return as([type, value.toString()], value);
235
- case "Boolean":
236
- case "Number":
237
- case "String":
238
- return as([type, value.valueOf()], value);
239
- }
240
- }
241
- if (json && "toJSON" in value)
242
- return pair(value.toJSON());
243
- const entries = [];
244
- const index = as([TYPE, entries], value);
245
- for (const key of keys(value)) {
246
- if (strict || !shouldSkip(typeOf(value[key])))
247
- entries.push([pair(key), pair(value[key])]);
248
- }
249
- return index;
250
- }
251
- case DATE:
252
- return as([TYPE, value.toISOString()], value);
253
- case REGEXP: {
254
- const { source, flags } = value;
255
- return as([TYPE, { source, flags }], value);
256
- }
257
- case MAP: {
258
- const entries = [];
259
- const index = as([TYPE, entries], value);
260
- for (const [key, entry] of value) {
261
- if (strict || !(shouldSkip(typeOf(key)) || shouldSkip(typeOf(entry))))
262
- entries.push([pair(key), pair(entry)]);
263
- }
264
- return index;
265
- }
266
- case SET: {
267
- const entries = [];
268
- const index = as([TYPE, entries], value);
269
- for (const entry of value) {
270
- if (strict || !shouldSkip(typeOf(entry)))
271
- entries.push(pair(entry));
272
- }
273
- return index;
274
- }
275
- }
276
- const { message } = value;
277
- return as([TYPE, { name: type, message }], value);
278
- };
279
- return pair;
280
- };
281
- var serialize = (value, { json, lossy } = {}) => {
282
- const _ = [];
283
- return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
284
- };
285
- var esm_default = typeof structuredClone === "function" ? (
286
- /* c8 ignore start */
287
- (any, options) => options && ("json" in options || "lossy" in options) ? deserialize(serialize(any, options)) : structuredClone(any)
288
- ) : (any, options) => deserialize(serialize(any, options));
289
- var CacheData = class _CacheData {
290
- static IsDirty(data) {
291
- return data.dirty;
292
- }
293
- static SetDirty(data, value) {
294
- data.dirty = value;
295
- return data;
296
- }
297
- static StructuredClone = globalThis.structuredClone ?? esm_default;
298
- _raw;
299
- generator;
300
- dirty;
301
- constructor(generator) {
302
- this._raw = void 0;
303
- this.dirty = false;
304
- this.generator = generator;
72
+ clear() {
73
+ return this._map.clear();
305
74
  }
306
- /**
307
- * This is cached data.
308
- * It was generated at the time of caching, so there is a risk of modification if it's an object due to shallow copying.
309
- * Therefore, if it's not a primitive type, please avoid using this value directly and use the `clone` method to use a copied version of the data.
310
- */
311
- get raw() {
312
- if (!this.dirty) {
313
- throw new Error(`The data is not initialized and cannot be accessed. Please use the 'ensure' or 'set' method to create the data first.`);
314
- }
315
- return this._raw;
75
+ delete(key) {
76
+ return this._map.delete(key);
316
77
  }
317
- /**
318
- * The method returns a copied value of the cached data.
319
- * You can pass a function as a parameter to copy the value. This parameter function should return the copied value.
320
- *
321
- * If no parameter is passed, it defaults to using Javascript's or \@ungap/structured-clone's `structuredClone` function to copy the value.
322
- * If you prefer shallow copying instead of deep copying,
323
- * you can use the default options `array-shallow-copy`, `object-shallow-copy` and `deep-copy`,
324
- * which are replaced with functions to shallow copy arrays and objects, respectively. This is a syntactic sugar.
325
- * @param strategy The function that returns the copied value.
326
- * If you want to perform a shallow copy, simply pass the strings `array-shallow-copy` or `object-shallow-copy` for easy use.
327
- * The default is `structuredClone`.
328
- */
329
- clone(strategy = "deep-copy") {
330
- if (strategy && typeof strategy !== "string") {
331
- return strategy(this.raw);
332
- }
333
- switch (strategy) {
334
- case "array-shallow-copy":
335
- return [].concat(this.raw);
336
- case "object-shallow-copy":
337
- return Object.assign({}, this.raw);
338
- case "deep-copy":
339
- default:
340
- return _CacheData.StructuredClone(this.raw);
341
- }
78
+ get(key) {
79
+ return this._map.get(key)?.deref();
342
80
  }
343
- };
344
- var CacheDataSync = class extends CacheData {
345
- static EmptyDataGenerator = () => void 0;
346
- static Update(branch, data, generator) {
347
- data._raw = generator(branch);
348
- data.generator = generator;
349
- data.dirty = true;
350
- return data;
351
- }
352
- static Cache(branch, data) {
353
- data._raw = data.generator(branch);
354
- return data;
81
+ has(key) {
82
+ return this._map.has(key) && this.get(key) !== void 0;
355
83
  }
356
- };
357
- var CacheBranchSync = class _CacheBranchSync extends CacheBranch {
358
- root;
359
- constructor(generator = CacheDataSync.EmptyDataGenerator, root) {
360
- super(new CacheDataSync(generator));
361
- this.root = root ?? this;
362
- }
363
- ensureBranch(key, generator) {
364
- return this.to(key, (b, k) => {
365
- const branch = b;
366
- if (!branch.branches.has(k)) {
367
- branch.branches.set(k, new _CacheBranchSync(generator, this.root));
368
- }
369
- return branch.branches.get(k);
370
- });
371
- }
372
- getBranch(key) {
373
- return this.to(key, (b, k) => {
374
- const branch = b;
375
- if (!branch.branches.has(k)) {
376
- return null;
377
- }
378
- return branch.branches.get(k);
379
- });
380
- }
381
- cache(key, recursive) {
382
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
383
- if (!branch) {
384
- return this;
385
- }
386
- if (recursive === "bottom-up") {
387
- for (const key2 of branch.branches.keys()) {
388
- branch.cache(key2, recursive);
389
- }
390
- }
391
- CacheDataSync.Cache(this.root, branch.data);
392
- if (recursive === "top-down") {
393
- for (const key2 of branch.branches.keys()) {
394
- branch.cache(key2, recursive);
395
- }
396
- }
84
+ set(key, value) {
85
+ this._map.set(key, new WeakRef(value));
86
+ this._registry.register(value, key);
397
87
  return this;
398
88
  }
399
- ensure(key, generator) {
400
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
401
- if (!CacheDataSync.IsDirty(branch.data)) {
402
- CacheDataSync.Update(this.root, branch.data, generator);
403
- }
404
- return branch.data;
405
- }
406
- get(key) {
407
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
408
- if (!CacheDataSync.IsDirty(branch.data)) {
409
- return void 0;
410
- }
411
- return branch.data;
412
- }
413
- set(key, generator) {
414
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
415
- CacheDataSync.Update(this.root, branch.data, generator);
416
- return this;
89
+ get size() {
90
+ return this._map.size;
417
91
  }
418
- delete(key) {
419
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
420
- if (branch) {
421
- branch.branches.clear();
422
- CacheDataSync.Update(this.root, branch.data, CacheDataSync.EmptyDataGenerator);
423
- CacheDataSync.SetDirty(branch.data, false);
424
- }
425
- return this;
92
+ keys() {
93
+ return this._map.keys();
426
94
  }
427
95
  };
428
96
 
@@ -447,10 +115,12 @@ var BPTree = class {
447
115
  like: (nv, v) => {
448
116
  const nodeValue = this.comparator.match(nv);
449
117
  const value = this.comparator.match(v);
450
- const regexp = this._cachedRegexp.ensure(value, () => {
118
+ if (!this._cachedRegexp.has(value)) {
451
119
  const pattern = value.replace(/%/g, ".*").replace(/_/g, ".");
452
- return new RegExp(`^${pattern}$`, "i");
453
- }).raw;
120
+ const regexp2 = new RegExp(`^${pattern}$`, "i");
121
+ this._cachedRegexp.set(value, regexp2);
122
+ }
123
+ const regexp = this._cachedRegexp.get(value);
454
124
  return regexp.test(nodeValue);
455
125
  }
456
126
  };
@@ -482,11 +152,11 @@ var BPTree = class {
482
152
  like: true
483
153
  };
484
154
  constructor(strategy, comparator) {
485
- this._cachedRegexp = new CacheBranchSync();
155
+ this._cachedRegexp = new InvertedWeakMap();
486
156
  this._nodeCreateBuffer = /* @__PURE__ */ new Map();
487
157
  this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
488
158
  this._nodeDeleteBuffer = /* @__PURE__ */ new Map();
489
- this.nodes = /* @__PURE__ */ new Map();
159
+ this.nodes = new InvertedWeakMap();
490
160
  this.strategy = strategy;
491
161
  this.comparator = comparator;
492
162
  }
@@ -495,8 +165,8 @@ var BPTree = class {
495
165
  for (let i = 0, len = node.values.length; i < len; i++) {
496
166
  const nValue = node.values[i];
497
167
  if (this.comparator.isSame(value, nValue)) {
498
- const keys2 = node.keys[i];
499
- keys2.push(key);
168
+ const keys = node.keys[i];
169
+ keys.push(key);
500
170
  this.bufferForNodeUpdate(node);
501
171
  break;
502
172
  } else if (this.comparator.isLower(value, nValue)) {
@@ -550,12 +220,12 @@ var BPTreeSync = class extends BPTree {
550
220
  let i = node.values.length;
551
221
  while (i--) {
552
222
  const nValue = node.values[i];
553
- const keys2 = node.keys[i];
223
+ const keys = node.keys[i];
554
224
  if (comparator(nValue, value)) {
555
225
  found = true;
556
- let j = keys2.length;
226
+ let j = keys.length;
557
227
  while (j--) {
558
- pairs.push({ key: keys2[j], value: nValue });
228
+ pairs.push({ key: keys[j], value: nValue });
559
229
  }
560
230
  } else if (found && !fullScan) {
561
231
  done = true;
@@ -578,10 +248,10 @@ var BPTreeSync = class extends BPTree {
578
248
  while (!done) {
579
249
  for (let i = 0, len = node.values.length; i < len; i++) {
580
250
  const nValue = node.values[i];
581
- const keys2 = node.keys[i];
251
+ const keys = node.keys[i];
582
252
  if (comparator(nValue, value)) {
583
253
  found = true;
584
- for (const key of keys2) {
254
+ for (const key of keys) {
585
255
  pairs.push({ key, value: nValue });
586
256
  }
587
257
  } else if (found && !fullScan) {
@@ -614,11 +284,11 @@ var BPTreeSync = class extends BPTree {
614
284
  }
615
285
  return id;
616
286
  }
617
- _createNode(isLeaf, keys2, values, leaf = false, parent = null, next = null, prev = null) {
287
+ _createNode(isLeaf, keys, values, leaf = false, parent = null, next = null, prev = null) {
618
288
  const id = this._createNodeId(isLeaf);
619
289
  const node = {
620
290
  id,
621
- keys: keys2,
291
+ keys,
622
292
  values,
623
293
  leaf,
624
294
  parent,
@@ -648,9 +318,9 @@ var BPTreeSync = class extends BPTree {
648
318
  }
649
319
  }
650
320
  if (this.root === node && node.keys.length === 1) {
651
- const keys2 = node.keys;
321
+ const keys = node.keys;
652
322
  this.bufferForNodeDelete(this.root);
653
- this.root = this.getNode(keys2[0]);
323
+ this.root = this.getNode(keys[0]);
654
324
  this.root.parent = null;
655
325
  this.strategy.head.root = this.root.id;
656
326
  this.bufferForNodeUpdate(this.root);
@@ -724,8 +394,8 @@ var BPTreeSync = class extends BPTree {
724
394
  }
725
395
  pointer.values.push(...node.values);
726
396
  if (!pointer.leaf) {
727
- const keys2 = pointer.keys;
728
- for (const key2 of keys2) {
397
+ const keys = pointer.keys;
398
+ for (const key2 of keys) {
729
399
  const node2 = this.getNode(key2);
730
400
  node2.parent = pointer.id;
731
401
  this.bufferForNodeUpdate(node2);
@@ -925,8 +595,8 @@ var BPTreeSync = class extends BPTree {
925
595
  leftestNode() {
926
596
  let node = this.root;
927
597
  while (!node.leaf) {
928
- const keys2 = node.keys;
929
- node = this.getNode(keys2[0]);
598
+ const keys = node.keys;
599
+ node = this.getNode(keys[0]);
930
600
  }
931
601
  return node;
932
602
  }
@@ -1037,17 +707,17 @@ var BPTreeSync = class extends BPTree {
1037
707
  while (i--) {
1038
708
  const nValue = node.values[i];
1039
709
  if (this.comparator.isSame(value, nValue)) {
1040
- const keys2 = node.keys[i];
1041
- if (keys2.includes(key)) {
1042
- if (keys2.length > 1) {
1043
- keys2.splice(keys2.indexOf(key), 1);
710
+ const keys = node.keys[i];
711
+ if (keys.includes(key)) {
712
+ if (keys.length > 1) {
713
+ keys.splice(keys.indexOf(key), 1);
1044
714
  this.bufferForNodeUpdate(node);
1045
715
  } else if (node === this.root) {
1046
716
  node.values.splice(i, 1);
1047
717
  node.keys.splice(i, 1);
1048
718
  this.bufferForNodeUpdate(node);
1049
719
  } else {
1050
- keys2.splice(keys2.indexOf(key), 1);
720
+ keys.splice(keys.indexOf(key), 1);
1051
721
  node.keys.splice(i, 1);
1052
722
  node.values.splice(node.values.indexOf(value), 1);
1053
723
  this._deleteEntry(node, key, value);
@@ -1066,8 +736,8 @@ var BPTreeSync = class extends BPTree {
1066
736
  for (let i = 0, len = node.values.length; i < len; i++) {
1067
737
  const nValue = node.values[i];
1068
738
  if (this.comparator.isSame(value, nValue)) {
1069
- const keys2 = node.keys[i];
1070
- return keys2.includes(key);
739
+ const keys = node.keys[i];
740
+ return keys.includes(key);
1071
741
  }
1072
742
  }
1073
743
  return false;
@@ -1077,13 +747,13 @@ var BPTreeSync = class extends BPTree {
1077
747
  this.commitHeadBuffer();
1078
748
  }
1079
749
  forceUpdate() {
1080
- const keys2 = [...this.nodes.keys()];
750
+ const keys = [...this.nodes.keys()];
1081
751
  this.nodes.clear();
1082
752
  this.init();
1083
- for (const key of keys2) {
753
+ for (const key of keys) {
1084
754
  this.getNode(key);
1085
755
  }
1086
- return keys2.length;
756
+ return keys.length;
1087
757
  }
1088
758
  };
1089
759
 
@@ -1101,12 +771,12 @@ var BPTreeAsync = class extends BPTree {
1101
771
  let i = node.values.length;
1102
772
  while (i--) {
1103
773
  const nValue = node.values[i];
1104
- const keys2 = node.keys[i];
774
+ const keys = node.keys[i];
1105
775
  if (comparator(nValue, value)) {
1106
776
  found = true;
1107
- let j = keys2.length;
777
+ let j = keys.length;
1108
778
  while (j--) {
1109
- pairs.push({ key: keys2[j], value: nValue });
779
+ pairs.push({ key: keys[j], value: nValue });
1110
780
  }
1111
781
  } else if (found && !fullScan) {
1112
782
  done = true;
@@ -1129,10 +799,10 @@ var BPTreeAsync = class extends BPTree {
1129
799
  while (!done) {
1130
800
  for (let i = 0, len = node.values.length; i < len; i++) {
1131
801
  const nValue = node.values[i];
1132
- const keys2 = node.keys[i];
802
+ const keys = node.keys[i];
1133
803
  if (comparator(nValue, value)) {
1134
804
  found = true;
1135
- for (const key of keys2) {
805
+ for (const key of keys) {
1136
806
  pairs.push({ key, value: nValue });
1137
807
  }
1138
808
  } else if (found && !fullScan) {
@@ -1165,11 +835,11 @@ var BPTreeAsync = class extends BPTree {
1165
835
  }
1166
836
  return id;
1167
837
  }
1168
- async _createNode(isLeaf, keys2, values, leaf = false, parent = null, next = null, prev = null) {
838
+ async _createNode(isLeaf, keys, values, leaf = false, parent = null, next = null, prev = null) {
1169
839
  const id = await this._createNodeId(isLeaf);
1170
840
  const node = {
1171
841
  id,
1172
- keys: keys2,
842
+ keys,
1173
843
  values,
1174
844
  leaf,
1175
845
  parent,
@@ -1199,9 +869,9 @@ var BPTreeAsync = class extends BPTree {
1199
869
  }
1200
870
  }
1201
871
  if (this.root === node && node.keys.length === 1) {
1202
- const keys2 = node.keys;
872
+ const keys = node.keys;
1203
873
  this.bufferForNodeDelete(this.root);
1204
- this.root = await this.getNode(keys2[0]);
874
+ this.root = await this.getNode(keys[0]);
1205
875
  this.root.parent = null;
1206
876
  this.strategy.head.root = this.root.id;
1207
877
  this.bufferForNodeUpdate(this.root);
@@ -1275,8 +945,8 @@ var BPTreeAsync = class extends BPTree {
1275
945
  }
1276
946
  pointer.values.push(...node.values);
1277
947
  if (!pointer.leaf) {
1278
- const keys2 = pointer.keys;
1279
- for (const key2 of keys2) {
948
+ const keys = pointer.keys;
949
+ for (const key2 of keys) {
1280
950
  const node2 = await this.getNode(key2);
1281
951
  node2.parent = pointer.id;
1282
952
  this.bufferForNodeUpdate(node2);
@@ -1476,8 +1146,8 @@ var BPTreeAsync = class extends BPTree {
1476
1146
  async leftestNode() {
1477
1147
  let node = this.root;
1478
1148
  while (!node.leaf) {
1479
- const keys2 = node.keys;
1480
- node = await this.getNode(keys2[0]);
1149
+ const keys = node.keys;
1150
+ node = await this.getNode(keys[0]);
1481
1151
  }
1482
1152
  return node;
1483
1153
  }
@@ -1588,17 +1258,17 @@ var BPTreeAsync = class extends BPTree {
1588
1258
  while (i--) {
1589
1259
  const nValue = node.values[i];
1590
1260
  if (this.comparator.isSame(value, nValue)) {
1591
- const keys2 = node.keys[i];
1592
- if (keys2.includes(key)) {
1593
- if (keys2.length > 1) {
1594
- keys2.splice(keys2.indexOf(key), 1);
1261
+ const keys = node.keys[i];
1262
+ if (keys.includes(key)) {
1263
+ if (keys.length > 1) {
1264
+ keys.splice(keys.indexOf(key), 1);
1595
1265
  this.bufferForNodeUpdate(node);
1596
1266
  } else if (node === this.root) {
1597
1267
  node.values.splice(i, 1);
1598
1268
  node.keys.splice(i, 1);
1599
1269
  this.bufferForNodeUpdate(node);
1600
1270
  } else {
1601
- keys2.splice(keys2.indexOf(key), 1);
1271
+ keys.splice(keys.indexOf(key), 1);
1602
1272
  node.keys.splice(i, 1);
1603
1273
  node.values.splice(node.values.indexOf(value), 1);
1604
1274
  await this._deleteEntry(node, key, value);
@@ -1617,8 +1287,8 @@ var BPTreeAsync = class extends BPTree {
1617
1287
  for (let i = 0, len = node.values.length; i < len; i++) {
1618
1288
  const nValue = node.values[i];
1619
1289
  if (this.comparator.isSame(value, nValue)) {
1620
- const keys2 = node.keys[i];
1621
- return keys2.includes(key);
1290
+ const keys = node.keys[i];
1291
+ return keys.includes(key);
1622
1292
  }
1623
1293
  }
1624
1294
  return false;
@@ -1628,13 +1298,13 @@ var BPTreeAsync = class extends BPTree {
1628
1298
  await this.commitHeadBuffer();
1629
1299
  }
1630
1300
  async forceUpdate() {
1631
- const keys2 = [...this.nodes.keys()];
1301
+ const keys = [...this.nodes.keys()];
1632
1302
  this.nodes.clear();
1633
1303
  await this.init();
1634
- for (const key of keys2) {
1304
+ for (const key of keys) {
1635
1305
  await this.getNode(key);
1636
1306
  }
1637
- return keys2.length;
1307
+ return keys.length;
1638
1308
  }
1639
1309
  };
1640
1310