serializable-bptree 5.0.0 → 5.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.
@@ -102,6 +102,7 @@ var BPTree = class {
102
102
  nodes;
103
103
  order;
104
104
  root;
105
+ _strategyDirty;
105
106
  _nodeCreateBuffer;
106
107
  _nodeUpdateBuffer;
107
108
  _nodeDeleteBuffer;
@@ -152,6 +153,7 @@ var BPTree = class {
152
153
  like: true
153
154
  };
154
155
  constructor(strategy, comparator) {
156
+ this._strategyDirty = false;
155
157
  this._cachedRegexp = new InvertedWeakMap();
156
158
  this._nodeCreateBuffer = /* @__PURE__ */ new Map();
157
159
  this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
@@ -324,6 +326,7 @@ var BPTreeSync = class extends BPTree {
324
326
  this.root = this.getNode(keys[0]);
325
327
  this.root.parent = null;
326
328
  this.strategy.head.root = this.root.id;
329
+ this._strategyDirty = true;
327
330
  this.bufferForNodeUpdate(this.root);
328
331
  return;
329
332
  } else if (this.root === node) {
@@ -507,6 +510,7 @@ var BPTreeSync = class extends BPTree {
507
510
  const root = this._createNode(false, [node.id, pointer.id], [value]);
508
511
  this.root = root;
509
512
  this.strategy.head.root = root.id;
513
+ this._strategyDirty = true;
510
514
  node.parent = root.id;
511
515
  pointer.parent = root.id;
512
516
  this.bufferForNodeCreate(root);
@@ -605,6 +609,10 @@ var BPTreeSync = class extends BPTree {
605
609
  return node;
606
610
  }
607
611
  commitHeadBuffer() {
612
+ if (!this._strategyDirty) {
613
+ return;
614
+ }
615
+ this._strategyDirty = false;
608
616
  this.strategy.writeHead(this.strategy.head);
609
617
  }
610
618
  commitNodeCreateBuffer() {
@@ -749,6 +757,7 @@ var BPTreeSync = class extends BPTree {
749
757
  }
750
758
  setHeadData(data) {
751
759
  this.strategy.head.data = data;
760
+ this._strategyDirty = true;
752
761
  this.commitHeadBuffer();
753
762
  }
754
763
  forceUpdate() {
@@ -880,6 +889,7 @@ var BPTreeAsync = class extends BPTree {
880
889
  this.root = await this.getNode(keys[0]);
881
890
  this.root.parent = null;
882
891
  this.strategy.head.root = this.root.id;
892
+ this._strategyDirty = true;
883
893
  this.bufferForNodeUpdate(this.root);
884
894
  return;
885
895
  } else if (this.root === node) {
@@ -1063,6 +1073,7 @@ var BPTreeAsync = class extends BPTree {
1063
1073
  const root = await this._createNode(false, [node.id, pointer.id], [value]);
1064
1074
  this.root = root;
1065
1075
  this.strategy.head.root = root.id;
1076
+ this._strategyDirty = true;
1066
1077
  node.parent = root.id;
1067
1078
  pointer.parent = root.id;
1068
1079
  this.bufferForNodeCreate(root);
@@ -1114,8 +1125,8 @@ var BPTreeAsync = class extends BPTree {
1114
1125
  this.root = await this._createNode(true, [], [], true);
1115
1126
  this.strategy.head.root = this.root.id;
1116
1127
  this.bufferForNodeCreate(this.root);
1117
- this.commitHeadBuffer();
1118
- this.commitNodeCreateBuffer();
1128
+ await this.commitHeadBuffer();
1129
+ await this.commitNodeCreateBuffer();
1119
1130
  } else {
1120
1131
  const { root, order } = head;
1121
1132
  this.strategy.head = head;
@@ -1161,6 +1172,10 @@ var BPTreeAsync = class extends BPTree {
1161
1172
  return node;
1162
1173
  }
1163
1174
  async commitHeadBuffer() {
1175
+ if (!this._strategyDirty) {
1176
+ return;
1177
+ }
1178
+ this._strategyDirty = false;
1164
1179
  await this.strategy.writeHead(this.strategy.head);
1165
1180
  }
1166
1181
  async commitNodeCreateBuffer() {
@@ -1305,6 +1320,7 @@ var BPTreeAsync = class extends BPTree {
1305
1320
  }
1306
1321
  async setHeadData(data) {
1307
1322
  this.strategy.head.data = data;
1323
+ this._strategyDirty = true;
1308
1324
  await this.commitHeadBuffer();
1309
1325
  }
1310
1326
  async forceUpdate() {
@@ -68,6 +68,7 @@ var BPTree = class {
68
68
  nodes;
69
69
  order;
70
70
  root;
71
+ _strategyDirty;
71
72
  _nodeCreateBuffer;
72
73
  _nodeUpdateBuffer;
73
74
  _nodeDeleteBuffer;
@@ -118,6 +119,7 @@ var BPTree = class {
118
119
  like: true
119
120
  };
120
121
  constructor(strategy, comparator) {
122
+ this._strategyDirty = false;
121
123
  this._cachedRegexp = new InvertedWeakMap();
122
124
  this._nodeCreateBuffer = /* @__PURE__ */ new Map();
123
125
  this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
@@ -290,6 +292,7 @@ var BPTreeSync = class extends BPTree {
290
292
  this.root = this.getNode(keys[0]);
291
293
  this.root.parent = null;
292
294
  this.strategy.head.root = this.root.id;
295
+ this._strategyDirty = true;
293
296
  this.bufferForNodeUpdate(this.root);
294
297
  return;
295
298
  } else if (this.root === node) {
@@ -473,6 +476,7 @@ var BPTreeSync = class extends BPTree {
473
476
  const root = this._createNode(false, [node.id, pointer.id], [value]);
474
477
  this.root = root;
475
478
  this.strategy.head.root = root.id;
479
+ this._strategyDirty = true;
476
480
  node.parent = root.id;
477
481
  pointer.parent = root.id;
478
482
  this.bufferForNodeCreate(root);
@@ -571,6 +575,10 @@ var BPTreeSync = class extends BPTree {
571
575
  return node;
572
576
  }
573
577
  commitHeadBuffer() {
578
+ if (!this._strategyDirty) {
579
+ return;
580
+ }
581
+ this._strategyDirty = false;
574
582
  this.strategy.writeHead(this.strategy.head);
575
583
  }
576
584
  commitNodeCreateBuffer() {
@@ -715,6 +723,7 @@ var BPTreeSync = class extends BPTree {
715
723
  }
716
724
  setHeadData(data) {
717
725
  this.strategy.head.data = data;
726
+ this._strategyDirty = true;
718
727
  this.commitHeadBuffer();
719
728
  }
720
729
  forceUpdate() {
@@ -846,6 +855,7 @@ var BPTreeAsync = class extends BPTree {
846
855
  this.root = await this.getNode(keys[0]);
847
856
  this.root.parent = null;
848
857
  this.strategy.head.root = this.root.id;
858
+ this._strategyDirty = true;
849
859
  this.bufferForNodeUpdate(this.root);
850
860
  return;
851
861
  } else if (this.root === node) {
@@ -1029,6 +1039,7 @@ var BPTreeAsync = class extends BPTree {
1029
1039
  const root = await this._createNode(false, [node.id, pointer.id], [value]);
1030
1040
  this.root = root;
1031
1041
  this.strategy.head.root = root.id;
1042
+ this._strategyDirty = true;
1032
1043
  node.parent = root.id;
1033
1044
  pointer.parent = root.id;
1034
1045
  this.bufferForNodeCreate(root);
@@ -1080,8 +1091,8 @@ var BPTreeAsync = class extends BPTree {
1080
1091
  this.root = await this._createNode(true, [], [], true);
1081
1092
  this.strategy.head.root = this.root.id;
1082
1093
  this.bufferForNodeCreate(this.root);
1083
- this.commitHeadBuffer();
1084
- this.commitNodeCreateBuffer();
1094
+ await this.commitHeadBuffer();
1095
+ await this.commitNodeCreateBuffer();
1085
1096
  } else {
1086
1097
  const { root, order } = head;
1087
1098
  this.strategy.head = head;
@@ -1127,6 +1138,10 @@ var BPTreeAsync = class extends BPTree {
1127
1138
  return node;
1128
1139
  }
1129
1140
  async commitHeadBuffer() {
1141
+ if (!this._strategyDirty) {
1142
+ return;
1143
+ }
1144
+ this._strategyDirty = false;
1130
1145
  await this.strategy.writeHead(this.strategy.head);
1131
1146
  }
1132
1147
  async commitNodeCreateBuffer() {
@@ -1271,6 +1286,7 @@ var BPTreeAsync = class extends BPTree {
1271
1286
  }
1272
1287
  async setHeadData(data) {
1273
1288
  this.strategy.head.data = data;
1289
+ this._strategyDirty = true;
1274
1290
  await this.commitHeadBuffer();
1275
1291
  }
1276
1292
  async forceUpdate() {
@@ -47,6 +47,7 @@ export declare abstract class BPTree<K, V> {
47
47
  protected readonly nodes: InvertedWeakMap<string, BPTreeUnknownNode<K, V>>;
48
48
  protected order: number;
49
49
  protected root: BPTreeUnknownNode<K, V>;
50
+ protected _strategyDirty: boolean;
50
51
  protected readonly _nodeCreateBuffer: Map<string, BPTreeUnknownNode<K, V>>;
51
52
  protected readonly _nodeUpdateBuffer: Map<string, BPTreeUnknownNode<K, V>>;
52
53
  protected readonly _nodeDeleteBuffer: Map<string, BPTreeUnknownNode<K, V>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
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",