serializable-bptree 9.0.2 → 9.0.4-alpha.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.
@@ -2159,13 +2159,7 @@ function insertOp(ops, ctx, key, value, comparator) {
2159
2159
  }
2160
2160
  function deleteEntry(ops, ctx, node, key, comparator) {
2161
2161
  if (!node.leaf) {
2162
- let keyIndex = -1;
2163
- for (let i = 0, len = node.keys.length; i < len; i++) {
2164
- if (node.keys[i] === key) {
2165
- keyIndex = i;
2166
- break;
2167
- }
2168
- }
2162
+ let keyIndex = node.keys.indexOf(key);
2169
2163
  if (keyIndex !== -1) {
2170
2164
  node = cloneNode(node);
2171
2165
  node.keys.splice(keyIndex, 1);
@@ -2204,17 +2198,15 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2204
2198
  let nextNode = null;
2205
2199
  let prevValue = null;
2206
2200
  let postValue = null;
2207
- for (let i = 0, len = parentNode.keys.length; i < len; i++) {
2208
- const nKey = parentNode.keys[i];
2209
- if (nKey === node.id) {
2210
- if (i > 0) {
2211
- prevNode = ops.getNode(parentNode.keys[i - 1]);
2212
- prevValue = parentNode.values[i - 1];
2213
- }
2214
- if (i < parentNode.keys.length - 1) {
2215
- nextNode = ops.getNode(parentNode.keys[i + 1]);
2216
- postValue = parentNode.values[i];
2217
- }
2201
+ let keyIndex = parentNode.keys.indexOf(node.id);
2202
+ if (keyIndex !== -1) {
2203
+ if (keyIndex > 0) {
2204
+ prevNode = ops.getNode(parentNode.keys[keyIndex - 1]);
2205
+ prevValue = parentNode.values[keyIndex - 1];
2206
+ }
2207
+ if (keyIndex < parentNode.keys.length - 1) {
2208
+ nextNode = ops.getNode(parentNode.keys[keyIndex + 1]);
2209
+ postValue = parentNode.values[keyIndex];
2218
2210
  }
2219
2211
  }
2220
2212
  let siblingNode;
@@ -2247,7 +2239,7 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2247
2239
  siblingNode = node;
2248
2240
  node = pTemp;
2249
2241
  }
2250
- siblingNode.keys.push(...node.keys);
2242
+ siblingNode.keys = siblingNode.keys.concat(node.keys);
2251
2243
  if (!node.leaf) {
2252
2244
  siblingNode.values.push(guess);
2253
2245
  } else {
@@ -2258,7 +2250,7 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2258
2250
  ops.updateNode(n);
2259
2251
  }
2260
2252
  }
2261
- siblingNode.values.push(...node.values);
2253
+ siblingNode.values = siblingNode.values.concat(node.values);
2262
2254
  if (!siblingNode.leaf) {
2263
2255
  const keys = siblingNode.keys;
2264
2256
  for (let i = 0, len = keys.length; i < len; i++) {
@@ -2306,8 +2298,8 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2306
2298
  if (!node.leaf) {
2307
2299
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
2308
2300
  pointerK0 = siblingNode.values.splice(0, 1)[0];
2309
- node.keys = [...node.keys, pointerP0];
2310
- node.values = [...node.values, guess];
2301
+ node.keys = node.keys.concat(pointerP0);
2302
+ node.values = node.values.concat(guess);
2311
2303
  parentNode = cloneNode(ops.getNode(node.parent));
2312
2304
  const pointerIndex = parentNode.keys.indexOf(siblingNode.id);
2313
2305
  if (pointerIndex > 0) {
@@ -2317,8 +2309,8 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2317
2309
  } else {
2318
2310
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
2319
2311
  pointerK0 = siblingNode.values.splice(0, 1)[0];
2320
- node.keys = [...node.keys, pointerP0];
2321
- node.values = [...node.values, pointerK0];
2312
+ node.keys = node.keys.concat(pointerP0);
2313
+ node.values = node.values.concat(pointerK0);
2322
2314
  parentNode = cloneNode(ops.getNode(node.parent));
2323
2315
  const pointerIndex = parentNode.keys.indexOf(siblingNode.id);
2324
2316
  if (pointerIndex > 0) {
@@ -3236,6 +3228,9 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
3236
3228
  this._verifierMapCached = createVerifierMap(this.comparator, this._cachedRegexp, ensureValues);
3237
3229
  this._searchConfigsCached = createSearchConfigs(this.comparator, ensureValues);
3238
3230
  }
3231
+ getRootNode() {
3232
+ return this.getNode(this.rootId);
3233
+ }
3239
3234
  // ─── Legacy protected methods (delegating to ops) ────────────────
3240
3235
  getNode(id) {
3241
3236
  return this._ops.getNode(id);
@@ -4198,13 +4193,7 @@ async function insertOpAsync(ops, ctx, key, value, comparator) {
4198
4193
  }
4199
4194
  async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4200
4195
  if (!node.leaf) {
4201
- let keyIndex = -1;
4202
- for (let i = 0, len = node.keys.length; i < len; i++) {
4203
- if (node.keys[i] === key) {
4204
- keyIndex = i;
4205
- break;
4206
- }
4207
- }
4196
+ let keyIndex = node.keys.indexOf(key);
4208
4197
  if (keyIndex !== -1) {
4209
4198
  node = cloneNode(node);
4210
4199
  node.keys.splice(keyIndex, 1);
@@ -4233,16 +4222,15 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4233
4222
  let nextNode = null;
4234
4223
  let prevValue = null;
4235
4224
  let postValue = null;
4236
- for (let i = 0, len = parentNode.keys.length; i < len; i++) {
4237
- if (parentNode.keys[i] === node.id) {
4238
- if (i > 0) {
4239
- prevNode = await ops.getNode(parentNode.keys[i - 1]);
4240
- prevValue = parentNode.values[i - 1];
4241
- }
4242
- if (i < parentNode.keys.length - 1) {
4243
- nextNode = await ops.getNode(parentNode.keys[i + 1]);
4244
- postValue = parentNode.values[i];
4245
- }
4225
+ let keyIndex = parentNode.keys.indexOf(node.id);
4226
+ if (keyIndex !== -1) {
4227
+ if (keyIndex > 0) {
4228
+ prevNode = await ops.getNode(parentNode.keys[keyIndex - 1]);
4229
+ prevValue = parentNode.values[keyIndex - 1];
4230
+ }
4231
+ if (keyIndex < parentNode.keys.length - 1) {
4232
+ nextNode = await ops.getNode(parentNode.keys[keyIndex + 1]);
4233
+ postValue = parentNode.values[keyIndex];
4246
4234
  }
4247
4235
  }
4248
4236
  let siblingNode;
@@ -4269,11 +4257,11 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4269
4257
  siblingNode = cloneNode(siblingNode);
4270
4258
  if (node.values.length + siblingNode.values.length < ctx.order) {
4271
4259
  if (!isPredecessor) {
4272
- const t = siblingNode;
4260
+ const pTemp = siblingNode;
4273
4261
  siblingNode = node;
4274
- node = t;
4262
+ node = pTemp;
4275
4263
  }
4276
- siblingNode.keys.push(...node.keys);
4264
+ siblingNode.keys = siblingNode.keys.concat(node.keys);
4277
4265
  if (!node.leaf) {
4278
4266
  siblingNode.values.push(guess);
4279
4267
  } else {
@@ -4284,7 +4272,7 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4284
4272
  await ops.updateNode(n);
4285
4273
  }
4286
4274
  }
4287
- siblingNode.values.push(...node.values);
4275
+ siblingNode.values = siblingNode.values.concat(node.values);
4288
4276
  if (!siblingNode.leaf) {
4289
4277
  for (let i = 0, len = siblingNode.keys.length; i < len; i++) {
4290
4278
  const n = cloneNode(await ops.getNode(siblingNode.keys[i]));
@@ -4328,8 +4316,8 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4328
4316
  if (!node.leaf) {
4329
4317
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
4330
4318
  pointerK0 = siblingNode.values.splice(0, 1)[0];
4331
- node.keys = [...node.keys, pointerP0];
4332
- node.values = [...node.values, guess];
4319
+ node.keys = node.keys.concat(pointerP0);
4320
+ node.values = node.values.concat(guess);
4333
4321
  parentNode = cloneNode(await ops.getNode(node.parent));
4334
4322
  const pi = parentNode.keys.indexOf(siblingNode.id);
4335
4323
  if (pi > 0) {
@@ -4339,8 +4327,8 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4339
4327
  } else {
4340
4328
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
4341
4329
  pointerK0 = siblingNode.values.splice(0, 1)[0];
4342
- node.keys = [...node.keys, pointerP0];
4343
- node.values = [...node.values, pointerK0];
4330
+ node.keys = node.keys.concat(pointerP0);
4331
+ node.values = node.values.concat(pointerK0);
4344
4332
  parentNode = cloneNode(await ops.getNode(node.parent));
4345
4333
  const pi = parentNode.keys.indexOf(siblingNode.id);
4346
4334
  if (pi > 0) {
@@ -4674,6 +4662,9 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
4674
4662
  this.lock.writeUnlock(lockId);
4675
4663
  });
4676
4664
  }
4665
+ async getRootNode() {
4666
+ return this.getNode(this.rootId);
4667
+ }
4677
4668
  // ─── Legacy protected methods (delegating to ops) ────────────────
4678
4669
  async getNode(id) {
4679
4670
  return this._ops.getNode(id);
@@ -5107,21 +5098,18 @@ var BPTreePureSync = class {
5107
5098
  );
5108
5099
  flush();
5109
5100
  }
5110
- /**
5111
- * Returns the ID of the root node.
5112
- */
5101
+ getRootNode() {
5102
+ const ctx = this._readCtx();
5103
+ return this.strategy.read(ctx.rootId);
5104
+ }
5113
5105
  getRootId() {
5114
- return this._readCtx().rootId;
5106
+ const ctx = this._readCtx();
5107
+ return ctx.rootId;
5115
5108
  }
5116
- /**
5117
- * Returns the order of the B+Tree.
5118
- */
5119
5109
  getOrder() {
5120
- return this._readCtx().order;
5110
+ const ctx = this._readCtx();
5111
+ return ctx.order;
5121
5112
  }
5122
- /**
5123
- * Verified if the value satisfies the condition.
5124
- */
5125
5113
  verify(nodeValue, condition) {
5126
5114
  for (const key in condition) {
5127
5115
  const verifyFn = this._verifierMap[key];
@@ -5134,18 +5122,18 @@ var BPTreePureSync = class {
5134
5122
  }
5135
5123
  // ─── Query ───────────────────────────────────────────────────────
5136
5124
  get(key) {
5137
- const { rootId } = this._readCtx();
5138
- return getOp(this._createReadOps(), rootId, key);
5125
+ const ctx = this._readCtx();
5126
+ return getOp(this._createReadOps(), ctx.rootId, key);
5139
5127
  }
5140
5128
  exists(key, value) {
5141
- const { rootId } = this._readCtx();
5142
- return existsOp(this._createReadOps(), rootId, key, value, this.comparator);
5129
+ const ctx = this._readCtx();
5130
+ return existsOp(this._createReadOps(), ctx.rootId, key, value, this.comparator);
5143
5131
  }
5144
5132
  *keysStream(condition, options) {
5145
- const { rootId } = this._readCtx();
5133
+ const ctx = this._readCtx();
5146
5134
  yield* keysStreamOp(
5147
5135
  this._createReadOps(),
5148
- rootId,
5136
+ ctx.rootId,
5149
5137
  condition,
5150
5138
  this.comparator,
5151
5139
  this._verifierMap,
@@ -5155,10 +5143,10 @@ var BPTreePureSync = class {
5155
5143
  );
5156
5144
  }
5157
5145
  *whereStream(condition, options) {
5158
- const { rootId } = this._readCtx();
5146
+ const ctx = this._readCtx();
5159
5147
  yield* whereStreamOp(
5160
5148
  this._createReadOps(),
5161
- rootId,
5149
+ ctx.rootId,
5162
5150
  condition,
5163
5151
  this.comparator,
5164
5152
  this._verifierMap,
@@ -5366,11 +5354,17 @@ var BPTreePureAsync = class {
5366
5354
  await flush();
5367
5355
  });
5368
5356
  }
5357
+ async getRootNode() {
5358
+ const ctx = await this._readCtx();
5359
+ return await this.strategy.read(ctx.rootId);
5360
+ }
5369
5361
  async getRootId() {
5370
- return (await this._readCtx()).rootId;
5362
+ const ctx = await this._readCtx();
5363
+ return ctx.rootId;
5371
5364
  }
5372
5365
  async getOrder() {
5373
- return (await this._readCtx()).order;
5366
+ const ctx = await this._readCtx();
5367
+ return ctx.order;
5374
5368
  }
5375
5369
  verify(nodeValue, condition) {
5376
5370
  for (const key in condition) {
@@ -5382,21 +5376,21 @@ var BPTreePureAsync = class {
5382
5376
  }
5383
5377
  // ─── Query ───────────────────────────────────────────────────────
5384
5378
  async get(key) {
5385
- const { rootId } = await this._readCtx();
5386
- return getOpAsync(this._createReadOps(), rootId, key);
5379
+ const ctx = await this._readCtx();
5380
+ return getOpAsync(this._createReadOps(), ctx.rootId, key);
5387
5381
  }
5388
5382
  async exists(key, value) {
5389
- const { rootId } = await this._readCtx();
5390
- return existsOpAsync(this._createReadOps(), rootId, key, value, this.comparator);
5383
+ const ctx = await this._readCtx();
5384
+ return existsOpAsync(this._createReadOps(), ctx.rootId, key, value, this.comparator);
5391
5385
  }
5392
5386
  async *keysStream(condition, options) {
5393
5387
  let lockId;
5394
5388
  try {
5395
5389
  lockId = await this.lock.readLock([0, 0.1], async (id) => id);
5396
- const { rootId } = await this._readCtx();
5390
+ const ctx = await this._readCtx();
5397
5391
  yield* keysStreamOpAsync(
5398
5392
  this._createReadOps(),
5399
- rootId,
5393
+ ctx.rootId,
5400
5394
  condition,
5401
5395
  this.comparator,
5402
5396
  this._verifierMap,
@@ -5412,10 +5406,10 @@ var BPTreePureAsync = class {
5412
5406
  let lockId;
5413
5407
  try {
5414
5408
  lockId = await this.lock.readLock([0, 0.1], async (id) => id);
5415
- const { rootId } = await this._readCtx();
5409
+ const ctx = await this._readCtx();
5416
5410
  yield* whereStreamOpAsync(
5417
5411
  this._createReadOps(),
5418
- rootId,
5412
+ ctx.rootId,
5419
5413
  condition,
5420
5414
  this.comparator,
5421
5415
  this._verifierMap,
@@ -2121,13 +2121,7 @@ function insertOp(ops, ctx, key, value, comparator) {
2121
2121
  }
2122
2122
  function deleteEntry(ops, ctx, node, key, comparator) {
2123
2123
  if (!node.leaf) {
2124
- let keyIndex = -1;
2125
- for (let i = 0, len = node.keys.length; i < len; i++) {
2126
- if (node.keys[i] === key) {
2127
- keyIndex = i;
2128
- break;
2129
- }
2130
- }
2124
+ let keyIndex = node.keys.indexOf(key);
2131
2125
  if (keyIndex !== -1) {
2132
2126
  node = cloneNode(node);
2133
2127
  node.keys.splice(keyIndex, 1);
@@ -2166,17 +2160,15 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2166
2160
  let nextNode = null;
2167
2161
  let prevValue = null;
2168
2162
  let postValue = null;
2169
- for (let i = 0, len = parentNode.keys.length; i < len; i++) {
2170
- const nKey = parentNode.keys[i];
2171
- if (nKey === node.id) {
2172
- if (i > 0) {
2173
- prevNode = ops.getNode(parentNode.keys[i - 1]);
2174
- prevValue = parentNode.values[i - 1];
2175
- }
2176
- if (i < parentNode.keys.length - 1) {
2177
- nextNode = ops.getNode(parentNode.keys[i + 1]);
2178
- postValue = parentNode.values[i];
2179
- }
2163
+ let keyIndex = parentNode.keys.indexOf(node.id);
2164
+ if (keyIndex !== -1) {
2165
+ if (keyIndex > 0) {
2166
+ prevNode = ops.getNode(parentNode.keys[keyIndex - 1]);
2167
+ prevValue = parentNode.values[keyIndex - 1];
2168
+ }
2169
+ if (keyIndex < parentNode.keys.length - 1) {
2170
+ nextNode = ops.getNode(parentNode.keys[keyIndex + 1]);
2171
+ postValue = parentNode.values[keyIndex];
2180
2172
  }
2181
2173
  }
2182
2174
  let siblingNode;
@@ -2209,7 +2201,7 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2209
2201
  siblingNode = node;
2210
2202
  node = pTemp;
2211
2203
  }
2212
- siblingNode.keys.push(...node.keys);
2204
+ siblingNode.keys = siblingNode.keys.concat(node.keys);
2213
2205
  if (!node.leaf) {
2214
2206
  siblingNode.values.push(guess);
2215
2207
  } else {
@@ -2220,7 +2212,7 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2220
2212
  ops.updateNode(n);
2221
2213
  }
2222
2214
  }
2223
- siblingNode.values.push(...node.values);
2215
+ siblingNode.values = siblingNode.values.concat(node.values);
2224
2216
  if (!siblingNode.leaf) {
2225
2217
  const keys = siblingNode.keys;
2226
2218
  for (let i = 0, len = keys.length; i < len; i++) {
@@ -2268,8 +2260,8 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2268
2260
  if (!node.leaf) {
2269
2261
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
2270
2262
  pointerK0 = siblingNode.values.splice(0, 1)[0];
2271
- node.keys = [...node.keys, pointerP0];
2272
- node.values = [...node.values, guess];
2263
+ node.keys = node.keys.concat(pointerP0);
2264
+ node.values = node.values.concat(guess);
2273
2265
  parentNode = cloneNode(ops.getNode(node.parent));
2274
2266
  const pointerIndex = parentNode.keys.indexOf(siblingNode.id);
2275
2267
  if (pointerIndex > 0) {
@@ -2279,8 +2271,8 @@ function deleteEntry(ops, ctx, node, key, comparator) {
2279
2271
  } else {
2280
2272
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
2281
2273
  pointerK0 = siblingNode.values.splice(0, 1)[0];
2282
- node.keys = [...node.keys, pointerP0];
2283
- node.values = [...node.values, pointerK0];
2274
+ node.keys = node.keys.concat(pointerP0);
2275
+ node.values = node.values.concat(pointerK0);
2284
2276
  parentNode = cloneNode(ops.getNode(node.parent));
2285
2277
  const pointerIndex = parentNode.keys.indexOf(siblingNode.id);
2286
2278
  if (pointerIndex > 0) {
@@ -3198,6 +3190,9 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
3198
3190
  this._verifierMapCached = createVerifierMap(this.comparator, this._cachedRegexp, ensureValues);
3199
3191
  this._searchConfigsCached = createSearchConfigs(this.comparator, ensureValues);
3200
3192
  }
3193
+ getRootNode() {
3194
+ return this.getNode(this.rootId);
3195
+ }
3201
3196
  // ─── Legacy protected methods (delegating to ops) ────────────────
3202
3197
  getNode(id) {
3203
3198
  return this._ops.getNode(id);
@@ -4160,13 +4155,7 @@ async function insertOpAsync(ops, ctx, key, value, comparator) {
4160
4155
  }
4161
4156
  async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4162
4157
  if (!node.leaf) {
4163
- let keyIndex = -1;
4164
- for (let i = 0, len = node.keys.length; i < len; i++) {
4165
- if (node.keys[i] === key) {
4166
- keyIndex = i;
4167
- break;
4168
- }
4169
- }
4158
+ let keyIndex = node.keys.indexOf(key);
4170
4159
  if (keyIndex !== -1) {
4171
4160
  node = cloneNode(node);
4172
4161
  node.keys.splice(keyIndex, 1);
@@ -4195,16 +4184,15 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4195
4184
  let nextNode = null;
4196
4185
  let prevValue = null;
4197
4186
  let postValue = null;
4198
- for (let i = 0, len = parentNode.keys.length; i < len; i++) {
4199
- if (parentNode.keys[i] === node.id) {
4200
- if (i > 0) {
4201
- prevNode = await ops.getNode(parentNode.keys[i - 1]);
4202
- prevValue = parentNode.values[i - 1];
4203
- }
4204
- if (i < parentNode.keys.length - 1) {
4205
- nextNode = await ops.getNode(parentNode.keys[i + 1]);
4206
- postValue = parentNode.values[i];
4207
- }
4187
+ let keyIndex = parentNode.keys.indexOf(node.id);
4188
+ if (keyIndex !== -1) {
4189
+ if (keyIndex > 0) {
4190
+ prevNode = await ops.getNode(parentNode.keys[keyIndex - 1]);
4191
+ prevValue = parentNode.values[keyIndex - 1];
4192
+ }
4193
+ if (keyIndex < parentNode.keys.length - 1) {
4194
+ nextNode = await ops.getNode(parentNode.keys[keyIndex + 1]);
4195
+ postValue = parentNode.values[keyIndex];
4208
4196
  }
4209
4197
  }
4210
4198
  let siblingNode;
@@ -4231,11 +4219,11 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4231
4219
  siblingNode = cloneNode(siblingNode);
4232
4220
  if (node.values.length + siblingNode.values.length < ctx.order) {
4233
4221
  if (!isPredecessor) {
4234
- const t = siblingNode;
4222
+ const pTemp = siblingNode;
4235
4223
  siblingNode = node;
4236
- node = t;
4224
+ node = pTemp;
4237
4225
  }
4238
- siblingNode.keys.push(...node.keys);
4226
+ siblingNode.keys = siblingNode.keys.concat(node.keys);
4239
4227
  if (!node.leaf) {
4240
4228
  siblingNode.values.push(guess);
4241
4229
  } else {
@@ -4246,7 +4234,7 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4246
4234
  await ops.updateNode(n);
4247
4235
  }
4248
4236
  }
4249
- siblingNode.values.push(...node.values);
4237
+ siblingNode.values = siblingNode.values.concat(node.values);
4250
4238
  if (!siblingNode.leaf) {
4251
4239
  for (let i = 0, len = siblingNode.keys.length; i < len; i++) {
4252
4240
  const n = cloneNode(await ops.getNode(siblingNode.keys[i]));
@@ -4290,8 +4278,8 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4290
4278
  if (!node.leaf) {
4291
4279
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
4292
4280
  pointerK0 = siblingNode.values.splice(0, 1)[0];
4293
- node.keys = [...node.keys, pointerP0];
4294
- node.values = [...node.values, guess];
4281
+ node.keys = node.keys.concat(pointerP0);
4282
+ node.values = node.values.concat(guess);
4295
4283
  parentNode = cloneNode(await ops.getNode(node.parent));
4296
4284
  const pi = parentNode.keys.indexOf(siblingNode.id);
4297
4285
  if (pi > 0) {
@@ -4301,8 +4289,8 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
4301
4289
  } else {
4302
4290
  pointerP0 = siblingNode.keys.splice(0, 1)[0];
4303
4291
  pointerK0 = siblingNode.values.splice(0, 1)[0];
4304
- node.keys = [...node.keys, pointerP0];
4305
- node.values = [...node.values, pointerK0];
4292
+ node.keys = node.keys.concat(pointerP0);
4293
+ node.values = node.values.concat(pointerK0);
4306
4294
  parentNode = cloneNode(await ops.getNode(node.parent));
4307
4295
  const pi = parentNode.keys.indexOf(siblingNode.id);
4308
4296
  if (pi > 0) {
@@ -4636,6 +4624,9 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
4636
4624
  this.lock.writeUnlock(lockId);
4637
4625
  });
4638
4626
  }
4627
+ async getRootNode() {
4628
+ return this.getNode(this.rootId);
4629
+ }
4639
4630
  // ─── Legacy protected methods (delegating to ops) ────────────────
4640
4631
  async getNode(id) {
4641
4632
  return this._ops.getNode(id);
@@ -5069,21 +5060,18 @@ var BPTreePureSync = class {
5069
5060
  );
5070
5061
  flush();
5071
5062
  }
5072
- /**
5073
- * Returns the ID of the root node.
5074
- */
5063
+ getRootNode() {
5064
+ const ctx = this._readCtx();
5065
+ return this.strategy.read(ctx.rootId);
5066
+ }
5075
5067
  getRootId() {
5076
- return this._readCtx().rootId;
5068
+ const ctx = this._readCtx();
5069
+ return ctx.rootId;
5077
5070
  }
5078
- /**
5079
- * Returns the order of the B+Tree.
5080
- */
5081
5071
  getOrder() {
5082
- return this._readCtx().order;
5072
+ const ctx = this._readCtx();
5073
+ return ctx.order;
5083
5074
  }
5084
- /**
5085
- * Verified if the value satisfies the condition.
5086
- */
5087
5075
  verify(nodeValue, condition) {
5088
5076
  for (const key in condition) {
5089
5077
  const verifyFn = this._verifierMap[key];
@@ -5096,18 +5084,18 @@ var BPTreePureSync = class {
5096
5084
  }
5097
5085
  // ─── Query ───────────────────────────────────────────────────────
5098
5086
  get(key) {
5099
- const { rootId } = this._readCtx();
5100
- return getOp(this._createReadOps(), rootId, key);
5087
+ const ctx = this._readCtx();
5088
+ return getOp(this._createReadOps(), ctx.rootId, key);
5101
5089
  }
5102
5090
  exists(key, value) {
5103
- const { rootId } = this._readCtx();
5104
- return existsOp(this._createReadOps(), rootId, key, value, this.comparator);
5091
+ const ctx = this._readCtx();
5092
+ return existsOp(this._createReadOps(), ctx.rootId, key, value, this.comparator);
5105
5093
  }
5106
5094
  *keysStream(condition, options) {
5107
- const { rootId } = this._readCtx();
5095
+ const ctx = this._readCtx();
5108
5096
  yield* keysStreamOp(
5109
5097
  this._createReadOps(),
5110
- rootId,
5098
+ ctx.rootId,
5111
5099
  condition,
5112
5100
  this.comparator,
5113
5101
  this._verifierMap,
@@ -5117,10 +5105,10 @@ var BPTreePureSync = class {
5117
5105
  );
5118
5106
  }
5119
5107
  *whereStream(condition, options) {
5120
- const { rootId } = this._readCtx();
5108
+ const ctx = this._readCtx();
5121
5109
  yield* whereStreamOp(
5122
5110
  this._createReadOps(),
5123
- rootId,
5111
+ ctx.rootId,
5124
5112
  condition,
5125
5113
  this.comparator,
5126
5114
  this._verifierMap,
@@ -5328,11 +5316,17 @@ var BPTreePureAsync = class {
5328
5316
  await flush();
5329
5317
  });
5330
5318
  }
5319
+ async getRootNode() {
5320
+ const ctx = await this._readCtx();
5321
+ return await this.strategy.read(ctx.rootId);
5322
+ }
5331
5323
  async getRootId() {
5332
- return (await this._readCtx()).rootId;
5324
+ const ctx = await this._readCtx();
5325
+ return ctx.rootId;
5333
5326
  }
5334
5327
  async getOrder() {
5335
- return (await this._readCtx()).order;
5328
+ const ctx = await this._readCtx();
5329
+ return ctx.order;
5336
5330
  }
5337
5331
  verify(nodeValue, condition) {
5338
5332
  for (const key in condition) {
@@ -5344,21 +5338,21 @@ var BPTreePureAsync = class {
5344
5338
  }
5345
5339
  // ─── Query ───────────────────────────────────────────────────────
5346
5340
  async get(key) {
5347
- const { rootId } = await this._readCtx();
5348
- return getOpAsync(this._createReadOps(), rootId, key);
5341
+ const ctx = await this._readCtx();
5342
+ return getOpAsync(this._createReadOps(), ctx.rootId, key);
5349
5343
  }
5350
5344
  async exists(key, value) {
5351
- const { rootId } = await this._readCtx();
5352
- return existsOpAsync(this._createReadOps(), rootId, key, value, this.comparator);
5345
+ const ctx = await this._readCtx();
5346
+ return existsOpAsync(this._createReadOps(), ctx.rootId, key, value, this.comparator);
5353
5347
  }
5354
5348
  async *keysStream(condition, options) {
5355
5349
  let lockId;
5356
5350
  try {
5357
5351
  lockId = await this.lock.readLock([0, 0.1], async (id) => id);
5358
- const { rootId } = await this._readCtx();
5352
+ const ctx = await this._readCtx();
5359
5353
  yield* keysStreamOpAsync(
5360
5354
  this._createReadOps(),
5361
- rootId,
5355
+ ctx.rootId,
5362
5356
  condition,
5363
5357
  this.comparator,
5364
5358
  this._verifierMap,
@@ -5374,10 +5368,10 @@ var BPTreePureAsync = class {
5374
5368
  let lockId;
5375
5369
  try {
5376
5370
  lockId = await this.lock.readLock([0, 0.1], async (id) => id);
5377
- const { rootId } = await this._readCtx();
5371
+ const ctx = await this._readCtx();
5378
5372
  yield* whereStreamOpAsync(
5379
5373
  this._createReadOps(),
5380
- rootId,
5374
+ ctx.rootId,
5381
5375
  condition,
5382
5376
  this.comparator,
5383
5377
  this._verifierMap,
@@ -1,8 +1,8 @@
1
- import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, SerializableData } from './types';
1
+ import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, BPTreeUnknownNode, SerializableData } from './types';
2
+ import { Ryoiki } from 'ryoiki';
2
3
  import { SerializeStrategyAsync } from './SerializeStrategyAsync';
3
4
  import { ValueComparator } from './base/ValueComparator';
4
5
  import { BPTreeTransaction } from './base/BPTreeTransaction';
5
- import { Ryoiki } from 'ryoiki';
6
6
  export declare class BPTreePureAsync<K, V> {
7
7
  protected readonly strategy: SerializeStrategyAsync<K, V>;
8
8
  protected readonly comparator: ValueComparator<V>;
@@ -19,6 +19,7 @@ export declare class BPTreePureAsync<K, V> {
19
19
  private _createCtx;
20
20
  protected writeLock<T>(fn: () => Promise<T>): Promise<T>;
21
21
  init(): Promise<void>;
22
+ getRootNode(): Promise<BPTreeUnknownNode<K, V>>;
22
23
  getRootId(): Promise<string>;
23
24
  getOrder(): Promise<number>;
24
25
  verify(nodeValue: V, condition: BPTreeCondition<V>): boolean;
@@ -1,4 +1,4 @@
1
- import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, SerializableData } from './types';
1
+ import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, BPTreeUnknownNode, SerializableData } from './types';
2
2
  import { SerializeStrategySync } from './SerializeStrategySync';
3
3
  import { ValueComparator } from './base/ValueComparator';
4
4
  import { BPTreeTransaction } from './base/BPTreeTransaction';
@@ -16,17 +16,9 @@ export declare class BPTreePureSync<K, V> {
16
16
  private _readCtx;
17
17
  private _createCtx;
18
18
  init(): void;
19
- /**
20
- * Returns the ID of the root node.
21
- */
19
+ getRootNode(): BPTreeUnknownNode<K, V>;
22
20
  getRootId(): string;
23
- /**
24
- * Returns the order of the B+Tree.
25
- */
26
21
  getOrder(): number;
27
- /**
28
- * Verified if the value satisfies the condition.
29
- */
30
22
  verify(nodeValue: V, condition: BPTreeCondition<V>): boolean;
31
23
  get(key: K): V | undefined;
32
24
  exists(key: K, value: V): boolean;
@@ -57,6 +57,11 @@ export declare abstract class BPTreeTransaction<K, V> {
57
57
  * @returns An array of keys that are in conflict. Empty array if no conflicts.
58
58
  */
59
59
  static CheckConflicts<K, V>(transactions: BPTreeTransaction<K, V>[]): string[];
60
+ /**
61
+ * Returns the root node of the B+Tree.
62
+ * @returns The root node.
63
+ */
64
+ abstract getRootNode(): Deferred<BPTreeUnknownNode<K, V>>;
60
65
  /**
61
66
  * Returns the ID of the root node.
62
67
  * @returns The root node ID.
@@ -20,6 +20,7 @@ export declare class BPTreeAsyncTransaction<K, V> extends BPTreeTransaction<K, V
20
20
  constructor(rootTx: BPTreeAsyncTransaction<K, V> | null, mvccRoot: AsyncBPTreeMVCC<K, V>, mvcc: AsyncBPTreeMVCC<K, V>, strategy: SerializeStrategyAsync<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
21
21
  private _initAlgoContext;
22
22
  protected writeLock<T>(id: number, fn: () => Promise<T>): Promise<T>;
23
+ getRootNode(): Promise<BPTreeUnknownNode<K, V>>;
23
24
  protected getNode(id: string): Promise<BPTreeUnknownNode<K, V>>;
24
25
  protected _createNode(leaf: boolean, keys: string[] | K[][], values: V[], parent?: string | null, next?: string | null, prev?: string | null): Promise<BPTreeUnknownNode<K, V>>;
25
26
  protected _updateNode(node: BPTreeUnknownNode<K, V>): Promise<void>;
@@ -17,6 +17,7 @@ export declare class BPTreeSyncTransaction<K, V> extends BPTreeTransaction<K, V>
17
17
  private _searchConfigsCached;
18
18
  constructor(rootTx: BPTreeSyncTransaction<K, V>, mvccRoot: SyncBPTreeMVCC<K, V>, mvcc: SyncBPTreeMVCC<K, V>, strategy: SerializeStrategySync<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
19
19
  private _initAlgoContext;
20
+ getRootNode(): BPTreeUnknownNode<K, V>;
20
21
  protected getNode(id: string): BPTreeUnknownNode<K, V>;
21
22
  protected _createNode(leaf: boolean, keys: string[] | K[][], values: V[], parent?: string | null, next?: string | null, prev?: string | null): BPTreeUnknownNode<K, V>;
22
23
  protected _updateNode(node: BPTreeUnknownNode<K, V>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "9.0.2",
3
+ "version": "9.0.4-alpha.0",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "main": "./dist/cjs/index.cjs",