serializable-bptree 9.0.1 → 9.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.
- package/dist/cjs/index.cjs +88 -40
- package/dist/esm/index.mjs +88 -40
- package/dist/types/BPTreePureAsync.d.ts +5 -5
- package/dist/types/BPTreePureSync.d.ts +3 -3
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -4990,8 +4990,6 @@ var BPTreePureSync = class {
|
|
|
4990
4990
|
comparator;
|
|
4991
4991
|
option;
|
|
4992
4992
|
_cachedRegexp = /* @__PURE__ */ new Map();
|
|
4993
|
-
_ctx;
|
|
4994
|
-
_ops;
|
|
4995
4993
|
_verifierMap;
|
|
4996
4994
|
_searchConfigs;
|
|
4997
4995
|
constructor(strategy, comparator, option) {
|
|
@@ -5005,7 +5003,7 @@ var BPTreePureSync = class {
|
|
|
5005
5003
|
_ensureValues(v) {
|
|
5006
5004
|
return Array.isArray(v) ? v : [v];
|
|
5007
5005
|
}
|
|
5008
|
-
|
|
5006
|
+
_createReadOps() {
|
|
5009
5007
|
const strategy = this.strategy;
|
|
5010
5008
|
return {
|
|
5011
5009
|
getNode(id) {
|
|
@@ -5072,16 +5070,35 @@ var BPTreePureSync = class {
|
|
|
5072
5070
|
}
|
|
5073
5071
|
return { ops, flush };
|
|
5074
5072
|
}
|
|
5073
|
+
_readCtx() {
|
|
5074
|
+
const head = this.strategy.readHead();
|
|
5075
|
+
if (head === null) {
|
|
5076
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5077
|
+
}
|
|
5078
|
+
return { rootId: head.root, order: head.order };
|
|
5079
|
+
}
|
|
5080
|
+
_createCtx() {
|
|
5081
|
+
const strategy = this.strategy;
|
|
5082
|
+
const head = strategy.readHead();
|
|
5083
|
+
if (head === null) {
|
|
5084
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5085
|
+
}
|
|
5086
|
+
return {
|
|
5087
|
+
rootId: head.root,
|
|
5088
|
+
order: head.order,
|
|
5089
|
+
headData: () => strategy.head.data
|
|
5090
|
+
};
|
|
5091
|
+
}
|
|
5075
5092
|
init() {
|
|
5076
5093
|
const { ops, flush } = this._createBufferedOps();
|
|
5077
|
-
|
|
5094
|
+
const ctx = {
|
|
5078
5095
|
rootId: "",
|
|
5079
5096
|
order: this.strategy.order,
|
|
5080
5097
|
headData: () => this.strategy.head.data
|
|
5081
5098
|
};
|
|
5082
5099
|
initOp(
|
|
5083
5100
|
ops,
|
|
5084
|
-
|
|
5101
|
+
ctx,
|
|
5085
5102
|
this.strategy.order,
|
|
5086
5103
|
this.strategy.head,
|
|
5087
5104
|
(head) => {
|
|
@@ -5089,19 +5106,18 @@ var BPTreePureSync = class {
|
|
|
5089
5106
|
}
|
|
5090
5107
|
);
|
|
5091
5108
|
flush();
|
|
5092
|
-
this._ops = this._createOps();
|
|
5093
5109
|
}
|
|
5094
5110
|
/**
|
|
5095
5111
|
* Returns the ID of the root node.
|
|
5096
5112
|
*/
|
|
5097
5113
|
getRootId() {
|
|
5098
|
-
return this.
|
|
5114
|
+
return this._readCtx().rootId;
|
|
5099
5115
|
}
|
|
5100
5116
|
/**
|
|
5101
5117
|
* Returns the order of the B+Tree.
|
|
5102
5118
|
*/
|
|
5103
5119
|
getOrder() {
|
|
5104
|
-
return this.
|
|
5120
|
+
return this._readCtx().order;
|
|
5105
5121
|
}
|
|
5106
5122
|
/**
|
|
5107
5123
|
* Verified if the value satisfies the condition.
|
|
@@ -5118,15 +5134,18 @@ var BPTreePureSync = class {
|
|
|
5118
5134
|
}
|
|
5119
5135
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5120
5136
|
get(key) {
|
|
5121
|
-
|
|
5137
|
+
const { rootId } = this._readCtx();
|
|
5138
|
+
return getOp(this._createReadOps(), rootId, key);
|
|
5122
5139
|
}
|
|
5123
5140
|
exists(key, value) {
|
|
5124
|
-
|
|
5141
|
+
const { rootId } = this._readCtx();
|
|
5142
|
+
return existsOp(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5125
5143
|
}
|
|
5126
5144
|
*keysStream(condition, options) {
|
|
5145
|
+
const { rootId } = this._readCtx();
|
|
5127
5146
|
yield* keysStreamOp(
|
|
5128
|
-
this.
|
|
5129
|
-
|
|
5147
|
+
this._createReadOps(),
|
|
5148
|
+
rootId,
|
|
5130
5149
|
condition,
|
|
5131
5150
|
this.comparator,
|
|
5132
5151
|
this._verifierMap,
|
|
@@ -5136,9 +5155,10 @@ var BPTreePureSync = class {
|
|
|
5136
5155
|
);
|
|
5137
5156
|
}
|
|
5138
5157
|
*whereStream(condition, options) {
|
|
5158
|
+
const { rootId } = this._readCtx();
|
|
5139
5159
|
yield* whereStreamOp(
|
|
5140
|
-
this.
|
|
5141
|
-
|
|
5160
|
+
this._createReadOps(),
|
|
5161
|
+
rootId,
|
|
5142
5162
|
condition,
|
|
5143
5163
|
this.comparator,
|
|
5144
5164
|
this._verifierMap,
|
|
@@ -5164,27 +5184,31 @@ var BPTreePureSync = class {
|
|
|
5164
5184
|
// ─── Mutation ────────────────────────────────────────────────────
|
|
5165
5185
|
insert(key, value) {
|
|
5166
5186
|
const { ops, flush } = this._createBufferedOps();
|
|
5167
|
-
|
|
5187
|
+
const ctx = this._createCtx();
|
|
5188
|
+
insertOp(ops, ctx, key, value, this.comparator);
|
|
5168
5189
|
flush();
|
|
5169
5190
|
}
|
|
5170
5191
|
delete(key, value) {
|
|
5171
5192
|
const { ops, flush } = this._createBufferedOps();
|
|
5172
|
-
|
|
5193
|
+
const ctx = this._createCtx();
|
|
5194
|
+
deleteOp(ops, ctx, key, this.comparator, value);
|
|
5173
5195
|
flush();
|
|
5174
5196
|
}
|
|
5175
5197
|
batchInsert(entries) {
|
|
5176
5198
|
const { ops, flush } = this._createBufferedOps();
|
|
5177
|
-
|
|
5199
|
+
const ctx = this._createCtx();
|
|
5200
|
+
batchInsertOp(ops, ctx, entries, this.comparator);
|
|
5178
5201
|
flush();
|
|
5179
5202
|
}
|
|
5180
5203
|
bulkLoad(entries) {
|
|
5181
5204
|
const { ops, flush } = this._createBufferedOps();
|
|
5182
|
-
|
|
5205
|
+
const ctx = this._createCtx();
|
|
5206
|
+
bulkLoadOp(ops, ctx, entries, this.comparator);
|
|
5183
5207
|
flush();
|
|
5184
5208
|
}
|
|
5185
5209
|
// ─── Head Data ───────────────────────────────────────────────────
|
|
5186
5210
|
getHeadData() {
|
|
5187
|
-
const head = this.
|
|
5211
|
+
const head = this.strategy.readHead();
|
|
5188
5212
|
if (head === null) {
|
|
5189
5213
|
throw new Error("Head not found");
|
|
5190
5214
|
}
|
|
@@ -5214,8 +5238,6 @@ var BPTreePureAsync = class {
|
|
|
5214
5238
|
option;
|
|
5215
5239
|
lock = new Ryoiki2();
|
|
5216
5240
|
_cachedRegexp = /* @__PURE__ */ new Map();
|
|
5217
|
-
_ctx;
|
|
5218
|
-
_ops;
|
|
5219
5241
|
_verifierMap;
|
|
5220
5242
|
_searchConfigs;
|
|
5221
5243
|
constructor(strategy, comparator, option) {
|
|
@@ -5229,7 +5251,7 @@ var BPTreePureAsync = class {
|
|
|
5229
5251
|
_ensureValues(v) {
|
|
5230
5252
|
return Array.isArray(v) ? v : [v];
|
|
5231
5253
|
}
|
|
5232
|
-
|
|
5254
|
+
_createReadOps() {
|
|
5233
5255
|
const strategy = this.strategy;
|
|
5234
5256
|
return {
|
|
5235
5257
|
async getNode(id) {
|
|
@@ -5296,6 +5318,25 @@ var BPTreePureAsync = class {
|
|
|
5296
5318
|
}
|
|
5297
5319
|
return { ops, flush };
|
|
5298
5320
|
}
|
|
5321
|
+
async _readCtx() {
|
|
5322
|
+
const head = await this.strategy.readHead();
|
|
5323
|
+
if (head === null) {
|
|
5324
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5325
|
+
}
|
|
5326
|
+
return { rootId: head.root, order: head.order };
|
|
5327
|
+
}
|
|
5328
|
+
async _createCtx() {
|
|
5329
|
+
const strategy = this.strategy;
|
|
5330
|
+
const head = await strategy.readHead();
|
|
5331
|
+
if (head === null) {
|
|
5332
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5333
|
+
}
|
|
5334
|
+
return {
|
|
5335
|
+
rootId: head.root,
|
|
5336
|
+
order: head.order,
|
|
5337
|
+
headData: () => strategy.head.data
|
|
5338
|
+
};
|
|
5339
|
+
}
|
|
5299
5340
|
async writeLock(fn) {
|
|
5300
5341
|
let lockId;
|
|
5301
5342
|
return this.lock.writeLock(async (_lockId) => {
|
|
@@ -5308,14 +5349,14 @@ var BPTreePureAsync = class {
|
|
|
5308
5349
|
async init() {
|
|
5309
5350
|
return this.writeLock(async () => {
|
|
5310
5351
|
const { ops, flush } = this._createBufferedOps();
|
|
5311
|
-
|
|
5352
|
+
const ctx = {
|
|
5312
5353
|
rootId: "",
|
|
5313
5354
|
order: this.strategy.order,
|
|
5314
5355
|
headData: () => this.strategy.head.data
|
|
5315
5356
|
};
|
|
5316
5357
|
await initOpAsync(
|
|
5317
5358
|
ops,
|
|
5318
|
-
|
|
5359
|
+
ctx,
|
|
5319
5360
|
this.strategy.order,
|
|
5320
5361
|
this.strategy.head,
|
|
5321
5362
|
(head) => {
|
|
@@ -5323,14 +5364,13 @@ var BPTreePureAsync = class {
|
|
|
5323
5364
|
}
|
|
5324
5365
|
);
|
|
5325
5366
|
await flush();
|
|
5326
|
-
this._ops = this._createOps();
|
|
5327
5367
|
});
|
|
5328
5368
|
}
|
|
5329
|
-
getRootId() {
|
|
5330
|
-
return this.
|
|
5369
|
+
async getRootId() {
|
|
5370
|
+
return (await this._readCtx()).rootId;
|
|
5331
5371
|
}
|
|
5332
|
-
getOrder() {
|
|
5333
|
-
return this.
|
|
5372
|
+
async getOrder() {
|
|
5373
|
+
return (await this._readCtx()).order;
|
|
5334
5374
|
}
|
|
5335
5375
|
verify(nodeValue, condition) {
|
|
5336
5376
|
for (const key in condition) {
|
|
@@ -5342,18 +5382,21 @@ var BPTreePureAsync = class {
|
|
|
5342
5382
|
}
|
|
5343
5383
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5344
5384
|
async get(key) {
|
|
5345
|
-
|
|
5385
|
+
const { rootId } = await this._readCtx();
|
|
5386
|
+
return getOpAsync(this._createReadOps(), rootId, key);
|
|
5346
5387
|
}
|
|
5347
5388
|
async exists(key, value) {
|
|
5348
|
-
|
|
5389
|
+
const { rootId } = await this._readCtx();
|
|
5390
|
+
return existsOpAsync(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5349
5391
|
}
|
|
5350
5392
|
async *keysStream(condition, options) {
|
|
5351
5393
|
let lockId;
|
|
5352
5394
|
try {
|
|
5353
5395
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5396
|
+
const { rootId } = await this._readCtx();
|
|
5354
5397
|
yield* keysStreamOpAsync(
|
|
5355
|
-
this.
|
|
5356
|
-
|
|
5398
|
+
this._createReadOps(),
|
|
5399
|
+
rootId,
|
|
5357
5400
|
condition,
|
|
5358
5401
|
this.comparator,
|
|
5359
5402
|
this._verifierMap,
|
|
@@ -5369,9 +5412,10 @@ var BPTreePureAsync = class {
|
|
|
5369
5412
|
let lockId;
|
|
5370
5413
|
try {
|
|
5371
5414
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5415
|
+
const { rootId } = await this._readCtx();
|
|
5372
5416
|
yield* whereStreamOpAsync(
|
|
5373
|
-
this.
|
|
5374
|
-
|
|
5417
|
+
this._createReadOps(),
|
|
5418
|
+
rootId,
|
|
5375
5419
|
condition,
|
|
5376
5420
|
this.comparator,
|
|
5377
5421
|
this._verifierMap,
|
|
@@ -5401,34 +5445,38 @@ var BPTreePureAsync = class {
|
|
|
5401
5445
|
async insert(key, value) {
|
|
5402
5446
|
return this.writeLock(async () => {
|
|
5403
5447
|
const { ops, flush } = this._createBufferedOps();
|
|
5404
|
-
|
|
5448
|
+
const ctx = await this._createCtx();
|
|
5449
|
+
await insertOpAsync(ops, ctx, key, value, this.comparator);
|
|
5405
5450
|
await flush();
|
|
5406
5451
|
});
|
|
5407
5452
|
}
|
|
5408
5453
|
async delete(key, value) {
|
|
5409
5454
|
return this.writeLock(async () => {
|
|
5410
5455
|
const { ops, flush } = this._createBufferedOps();
|
|
5411
|
-
|
|
5456
|
+
const ctx = await this._createCtx();
|
|
5457
|
+
await deleteOpAsync(ops, ctx, key, this.comparator, value);
|
|
5412
5458
|
await flush();
|
|
5413
5459
|
});
|
|
5414
5460
|
}
|
|
5415
5461
|
async batchInsert(entries) {
|
|
5416
5462
|
return this.writeLock(async () => {
|
|
5417
5463
|
const { ops, flush } = this._createBufferedOps();
|
|
5418
|
-
|
|
5464
|
+
const ctx = await this._createCtx();
|
|
5465
|
+
await batchInsertOpAsync(ops, ctx, entries, this.comparator);
|
|
5419
5466
|
await flush();
|
|
5420
5467
|
});
|
|
5421
5468
|
}
|
|
5422
5469
|
async bulkLoad(entries) {
|
|
5423
5470
|
return this.writeLock(async () => {
|
|
5424
5471
|
const { ops, flush } = this._createBufferedOps();
|
|
5425
|
-
|
|
5472
|
+
const ctx = await this._createCtx();
|
|
5473
|
+
await bulkLoadOpAsync(ops, ctx, entries, this.comparator);
|
|
5426
5474
|
await flush();
|
|
5427
5475
|
});
|
|
5428
5476
|
}
|
|
5429
5477
|
// ─── Head Data ───────────────────────────────────────────────────
|
|
5430
5478
|
async getHeadData() {
|
|
5431
|
-
const head = await this.
|
|
5479
|
+
const head = await this.strategy.readHead();
|
|
5432
5480
|
if (head === null) throw new Error("Head not found");
|
|
5433
5481
|
return head.data;
|
|
5434
5482
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -4952,8 +4952,6 @@ var BPTreePureSync = class {
|
|
|
4952
4952
|
comparator;
|
|
4953
4953
|
option;
|
|
4954
4954
|
_cachedRegexp = /* @__PURE__ */ new Map();
|
|
4955
|
-
_ctx;
|
|
4956
|
-
_ops;
|
|
4957
4955
|
_verifierMap;
|
|
4958
4956
|
_searchConfigs;
|
|
4959
4957
|
constructor(strategy, comparator, option) {
|
|
@@ -4967,7 +4965,7 @@ var BPTreePureSync = class {
|
|
|
4967
4965
|
_ensureValues(v) {
|
|
4968
4966
|
return Array.isArray(v) ? v : [v];
|
|
4969
4967
|
}
|
|
4970
|
-
|
|
4968
|
+
_createReadOps() {
|
|
4971
4969
|
const strategy = this.strategy;
|
|
4972
4970
|
return {
|
|
4973
4971
|
getNode(id) {
|
|
@@ -5034,16 +5032,35 @@ var BPTreePureSync = class {
|
|
|
5034
5032
|
}
|
|
5035
5033
|
return { ops, flush };
|
|
5036
5034
|
}
|
|
5035
|
+
_readCtx() {
|
|
5036
|
+
const head = this.strategy.readHead();
|
|
5037
|
+
if (head === null) {
|
|
5038
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5039
|
+
}
|
|
5040
|
+
return { rootId: head.root, order: head.order };
|
|
5041
|
+
}
|
|
5042
|
+
_createCtx() {
|
|
5043
|
+
const strategy = this.strategy;
|
|
5044
|
+
const head = strategy.readHead();
|
|
5045
|
+
if (head === null) {
|
|
5046
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5047
|
+
}
|
|
5048
|
+
return {
|
|
5049
|
+
rootId: head.root,
|
|
5050
|
+
order: head.order,
|
|
5051
|
+
headData: () => strategy.head.data
|
|
5052
|
+
};
|
|
5053
|
+
}
|
|
5037
5054
|
init() {
|
|
5038
5055
|
const { ops, flush } = this._createBufferedOps();
|
|
5039
|
-
|
|
5056
|
+
const ctx = {
|
|
5040
5057
|
rootId: "",
|
|
5041
5058
|
order: this.strategy.order,
|
|
5042
5059
|
headData: () => this.strategy.head.data
|
|
5043
5060
|
};
|
|
5044
5061
|
initOp(
|
|
5045
5062
|
ops,
|
|
5046
|
-
|
|
5063
|
+
ctx,
|
|
5047
5064
|
this.strategy.order,
|
|
5048
5065
|
this.strategy.head,
|
|
5049
5066
|
(head) => {
|
|
@@ -5051,19 +5068,18 @@ var BPTreePureSync = class {
|
|
|
5051
5068
|
}
|
|
5052
5069
|
);
|
|
5053
5070
|
flush();
|
|
5054
|
-
this._ops = this._createOps();
|
|
5055
5071
|
}
|
|
5056
5072
|
/**
|
|
5057
5073
|
* Returns the ID of the root node.
|
|
5058
5074
|
*/
|
|
5059
5075
|
getRootId() {
|
|
5060
|
-
return this.
|
|
5076
|
+
return this._readCtx().rootId;
|
|
5061
5077
|
}
|
|
5062
5078
|
/**
|
|
5063
5079
|
* Returns the order of the B+Tree.
|
|
5064
5080
|
*/
|
|
5065
5081
|
getOrder() {
|
|
5066
|
-
return this.
|
|
5082
|
+
return this._readCtx().order;
|
|
5067
5083
|
}
|
|
5068
5084
|
/**
|
|
5069
5085
|
* Verified if the value satisfies the condition.
|
|
@@ -5080,15 +5096,18 @@ var BPTreePureSync = class {
|
|
|
5080
5096
|
}
|
|
5081
5097
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5082
5098
|
get(key) {
|
|
5083
|
-
|
|
5099
|
+
const { rootId } = this._readCtx();
|
|
5100
|
+
return getOp(this._createReadOps(), rootId, key);
|
|
5084
5101
|
}
|
|
5085
5102
|
exists(key, value) {
|
|
5086
|
-
|
|
5103
|
+
const { rootId } = this._readCtx();
|
|
5104
|
+
return existsOp(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5087
5105
|
}
|
|
5088
5106
|
*keysStream(condition, options) {
|
|
5107
|
+
const { rootId } = this._readCtx();
|
|
5089
5108
|
yield* keysStreamOp(
|
|
5090
|
-
this.
|
|
5091
|
-
|
|
5109
|
+
this._createReadOps(),
|
|
5110
|
+
rootId,
|
|
5092
5111
|
condition,
|
|
5093
5112
|
this.comparator,
|
|
5094
5113
|
this._verifierMap,
|
|
@@ -5098,9 +5117,10 @@ var BPTreePureSync = class {
|
|
|
5098
5117
|
);
|
|
5099
5118
|
}
|
|
5100
5119
|
*whereStream(condition, options) {
|
|
5120
|
+
const { rootId } = this._readCtx();
|
|
5101
5121
|
yield* whereStreamOp(
|
|
5102
|
-
this.
|
|
5103
|
-
|
|
5122
|
+
this._createReadOps(),
|
|
5123
|
+
rootId,
|
|
5104
5124
|
condition,
|
|
5105
5125
|
this.comparator,
|
|
5106
5126
|
this._verifierMap,
|
|
@@ -5126,27 +5146,31 @@ var BPTreePureSync = class {
|
|
|
5126
5146
|
// ─── Mutation ────────────────────────────────────────────────────
|
|
5127
5147
|
insert(key, value) {
|
|
5128
5148
|
const { ops, flush } = this._createBufferedOps();
|
|
5129
|
-
|
|
5149
|
+
const ctx = this._createCtx();
|
|
5150
|
+
insertOp(ops, ctx, key, value, this.comparator);
|
|
5130
5151
|
flush();
|
|
5131
5152
|
}
|
|
5132
5153
|
delete(key, value) {
|
|
5133
5154
|
const { ops, flush } = this._createBufferedOps();
|
|
5134
|
-
|
|
5155
|
+
const ctx = this._createCtx();
|
|
5156
|
+
deleteOp(ops, ctx, key, this.comparator, value);
|
|
5135
5157
|
flush();
|
|
5136
5158
|
}
|
|
5137
5159
|
batchInsert(entries) {
|
|
5138
5160
|
const { ops, flush } = this._createBufferedOps();
|
|
5139
|
-
|
|
5161
|
+
const ctx = this._createCtx();
|
|
5162
|
+
batchInsertOp(ops, ctx, entries, this.comparator);
|
|
5140
5163
|
flush();
|
|
5141
5164
|
}
|
|
5142
5165
|
bulkLoad(entries) {
|
|
5143
5166
|
const { ops, flush } = this._createBufferedOps();
|
|
5144
|
-
|
|
5167
|
+
const ctx = this._createCtx();
|
|
5168
|
+
bulkLoadOp(ops, ctx, entries, this.comparator);
|
|
5145
5169
|
flush();
|
|
5146
5170
|
}
|
|
5147
5171
|
// ─── Head Data ───────────────────────────────────────────────────
|
|
5148
5172
|
getHeadData() {
|
|
5149
|
-
const head = this.
|
|
5173
|
+
const head = this.strategy.readHead();
|
|
5150
5174
|
if (head === null) {
|
|
5151
5175
|
throw new Error("Head not found");
|
|
5152
5176
|
}
|
|
@@ -5176,8 +5200,6 @@ var BPTreePureAsync = class {
|
|
|
5176
5200
|
option;
|
|
5177
5201
|
lock = new Ryoiki2();
|
|
5178
5202
|
_cachedRegexp = /* @__PURE__ */ new Map();
|
|
5179
|
-
_ctx;
|
|
5180
|
-
_ops;
|
|
5181
5203
|
_verifierMap;
|
|
5182
5204
|
_searchConfigs;
|
|
5183
5205
|
constructor(strategy, comparator, option) {
|
|
@@ -5191,7 +5213,7 @@ var BPTreePureAsync = class {
|
|
|
5191
5213
|
_ensureValues(v) {
|
|
5192
5214
|
return Array.isArray(v) ? v : [v];
|
|
5193
5215
|
}
|
|
5194
|
-
|
|
5216
|
+
_createReadOps() {
|
|
5195
5217
|
const strategy = this.strategy;
|
|
5196
5218
|
return {
|
|
5197
5219
|
async getNode(id) {
|
|
@@ -5258,6 +5280,25 @@ var BPTreePureAsync = class {
|
|
|
5258
5280
|
}
|
|
5259
5281
|
return { ops, flush };
|
|
5260
5282
|
}
|
|
5283
|
+
async _readCtx() {
|
|
5284
|
+
const head = await this.strategy.readHead();
|
|
5285
|
+
if (head === null) {
|
|
5286
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5287
|
+
}
|
|
5288
|
+
return { rootId: head.root, order: head.order };
|
|
5289
|
+
}
|
|
5290
|
+
async _createCtx() {
|
|
5291
|
+
const strategy = this.strategy;
|
|
5292
|
+
const head = await strategy.readHead();
|
|
5293
|
+
if (head === null) {
|
|
5294
|
+
throw new Error("Tree not initialized. Call init() first.");
|
|
5295
|
+
}
|
|
5296
|
+
return {
|
|
5297
|
+
rootId: head.root,
|
|
5298
|
+
order: head.order,
|
|
5299
|
+
headData: () => strategy.head.data
|
|
5300
|
+
};
|
|
5301
|
+
}
|
|
5261
5302
|
async writeLock(fn) {
|
|
5262
5303
|
let lockId;
|
|
5263
5304
|
return this.lock.writeLock(async (_lockId) => {
|
|
@@ -5270,14 +5311,14 @@ var BPTreePureAsync = class {
|
|
|
5270
5311
|
async init() {
|
|
5271
5312
|
return this.writeLock(async () => {
|
|
5272
5313
|
const { ops, flush } = this._createBufferedOps();
|
|
5273
|
-
|
|
5314
|
+
const ctx = {
|
|
5274
5315
|
rootId: "",
|
|
5275
5316
|
order: this.strategy.order,
|
|
5276
5317
|
headData: () => this.strategy.head.data
|
|
5277
5318
|
};
|
|
5278
5319
|
await initOpAsync(
|
|
5279
5320
|
ops,
|
|
5280
|
-
|
|
5321
|
+
ctx,
|
|
5281
5322
|
this.strategy.order,
|
|
5282
5323
|
this.strategy.head,
|
|
5283
5324
|
(head) => {
|
|
@@ -5285,14 +5326,13 @@ var BPTreePureAsync = class {
|
|
|
5285
5326
|
}
|
|
5286
5327
|
);
|
|
5287
5328
|
await flush();
|
|
5288
|
-
this._ops = this._createOps();
|
|
5289
5329
|
});
|
|
5290
5330
|
}
|
|
5291
|
-
getRootId() {
|
|
5292
|
-
return this.
|
|
5331
|
+
async getRootId() {
|
|
5332
|
+
return (await this._readCtx()).rootId;
|
|
5293
5333
|
}
|
|
5294
|
-
getOrder() {
|
|
5295
|
-
return this.
|
|
5334
|
+
async getOrder() {
|
|
5335
|
+
return (await this._readCtx()).order;
|
|
5296
5336
|
}
|
|
5297
5337
|
verify(nodeValue, condition) {
|
|
5298
5338
|
for (const key in condition) {
|
|
@@ -5304,18 +5344,21 @@ var BPTreePureAsync = class {
|
|
|
5304
5344
|
}
|
|
5305
5345
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5306
5346
|
async get(key) {
|
|
5307
|
-
|
|
5347
|
+
const { rootId } = await this._readCtx();
|
|
5348
|
+
return getOpAsync(this._createReadOps(), rootId, key);
|
|
5308
5349
|
}
|
|
5309
5350
|
async exists(key, value) {
|
|
5310
|
-
|
|
5351
|
+
const { rootId } = await this._readCtx();
|
|
5352
|
+
return existsOpAsync(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5311
5353
|
}
|
|
5312
5354
|
async *keysStream(condition, options) {
|
|
5313
5355
|
let lockId;
|
|
5314
5356
|
try {
|
|
5315
5357
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5358
|
+
const { rootId } = await this._readCtx();
|
|
5316
5359
|
yield* keysStreamOpAsync(
|
|
5317
|
-
this.
|
|
5318
|
-
|
|
5360
|
+
this._createReadOps(),
|
|
5361
|
+
rootId,
|
|
5319
5362
|
condition,
|
|
5320
5363
|
this.comparator,
|
|
5321
5364
|
this._verifierMap,
|
|
@@ -5331,9 +5374,10 @@ var BPTreePureAsync = class {
|
|
|
5331
5374
|
let lockId;
|
|
5332
5375
|
try {
|
|
5333
5376
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5377
|
+
const { rootId } = await this._readCtx();
|
|
5334
5378
|
yield* whereStreamOpAsync(
|
|
5335
|
-
this.
|
|
5336
|
-
|
|
5379
|
+
this._createReadOps(),
|
|
5380
|
+
rootId,
|
|
5337
5381
|
condition,
|
|
5338
5382
|
this.comparator,
|
|
5339
5383
|
this._verifierMap,
|
|
@@ -5363,34 +5407,38 @@ var BPTreePureAsync = class {
|
|
|
5363
5407
|
async insert(key, value) {
|
|
5364
5408
|
return this.writeLock(async () => {
|
|
5365
5409
|
const { ops, flush } = this._createBufferedOps();
|
|
5366
|
-
|
|
5410
|
+
const ctx = await this._createCtx();
|
|
5411
|
+
await insertOpAsync(ops, ctx, key, value, this.comparator);
|
|
5367
5412
|
await flush();
|
|
5368
5413
|
});
|
|
5369
5414
|
}
|
|
5370
5415
|
async delete(key, value) {
|
|
5371
5416
|
return this.writeLock(async () => {
|
|
5372
5417
|
const { ops, flush } = this._createBufferedOps();
|
|
5373
|
-
|
|
5418
|
+
const ctx = await this._createCtx();
|
|
5419
|
+
await deleteOpAsync(ops, ctx, key, this.comparator, value);
|
|
5374
5420
|
await flush();
|
|
5375
5421
|
});
|
|
5376
5422
|
}
|
|
5377
5423
|
async batchInsert(entries) {
|
|
5378
5424
|
return this.writeLock(async () => {
|
|
5379
5425
|
const { ops, flush } = this._createBufferedOps();
|
|
5380
|
-
|
|
5426
|
+
const ctx = await this._createCtx();
|
|
5427
|
+
await batchInsertOpAsync(ops, ctx, entries, this.comparator);
|
|
5381
5428
|
await flush();
|
|
5382
5429
|
});
|
|
5383
5430
|
}
|
|
5384
5431
|
async bulkLoad(entries) {
|
|
5385
5432
|
return this.writeLock(async () => {
|
|
5386
5433
|
const { ops, flush } = this._createBufferedOps();
|
|
5387
|
-
|
|
5434
|
+
const ctx = await this._createCtx();
|
|
5435
|
+
await bulkLoadOpAsync(ops, ctx, entries, this.comparator);
|
|
5388
5436
|
await flush();
|
|
5389
5437
|
});
|
|
5390
5438
|
}
|
|
5391
5439
|
// ─── Head Data ───────────────────────────────────────────────────
|
|
5392
5440
|
async getHeadData() {
|
|
5393
|
-
const head = await this.
|
|
5441
|
+
const head = await this.strategy.readHead();
|
|
5394
5442
|
if (head === null) throw new Error("Head not found");
|
|
5395
5443
|
return head.data;
|
|
5396
5444
|
}
|
|
@@ -9,18 +9,18 @@ export declare class BPTreePureAsync<K, V> {
|
|
|
9
9
|
protected readonly option: BPTreeConstructorOption;
|
|
10
10
|
protected readonly lock: Ryoiki;
|
|
11
11
|
private readonly _cachedRegexp;
|
|
12
|
-
private _ctx;
|
|
13
|
-
private _ops;
|
|
14
12
|
private readonly _verifierMap;
|
|
15
13
|
private readonly _searchConfigs;
|
|
16
14
|
constructor(strategy: SerializeStrategyAsync<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
|
|
17
15
|
private _ensureValues;
|
|
18
|
-
private
|
|
16
|
+
private _createReadOps;
|
|
19
17
|
private _createBufferedOps;
|
|
18
|
+
private _readCtx;
|
|
19
|
+
private _createCtx;
|
|
20
20
|
protected writeLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
21
21
|
init(): Promise<void>;
|
|
22
|
-
getRootId(): string
|
|
23
|
-
getOrder(): number
|
|
22
|
+
getRootId(): Promise<string>;
|
|
23
|
+
getOrder(): Promise<number>;
|
|
24
24
|
verify(nodeValue: V, condition: BPTreeCondition<V>): boolean;
|
|
25
25
|
get(key: K): Promise<V | undefined>;
|
|
26
26
|
exists(key: K, value: V): Promise<boolean>;
|
|
@@ -7,14 +7,14 @@ export declare class BPTreePureSync<K, V> {
|
|
|
7
7
|
protected readonly comparator: ValueComparator<V>;
|
|
8
8
|
protected readonly option: BPTreeConstructorOption;
|
|
9
9
|
private readonly _cachedRegexp;
|
|
10
|
-
private _ctx;
|
|
11
|
-
private _ops;
|
|
12
10
|
private readonly _verifierMap;
|
|
13
11
|
private readonly _searchConfigs;
|
|
14
12
|
constructor(strategy: SerializeStrategySync<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
|
|
15
13
|
private _ensureValues;
|
|
16
|
-
private
|
|
14
|
+
private _createReadOps;
|
|
17
15
|
private _createBufferedOps;
|
|
16
|
+
private _readCtx;
|
|
17
|
+
private _createCtx;
|
|
18
18
|
init(): void;
|
|
19
19
|
/**
|
|
20
20
|
* Returns the ID of the root node.
|