serializable-bptree 3.2.0 → 3.2.1

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.js CHANGED
@@ -81,7 +81,6 @@ var BPTree = class {
81
81
  root;
82
82
  _nodeCreateBuffer;
83
83
  _nodeUpdateBuffer;
84
- _headBuffer;
85
84
  verifierMap = {
86
85
  gt: (nv, v) => this.comparator.isHigher(nv, v),
87
86
  gte: (nv, v) => this.comparator.isHigher(nv, v) || this.comparator.isSame(nv, v),
@@ -126,19 +125,8 @@ var BPTree = class {
126
125
  notEqual: true,
127
126
  like: true
128
127
  };
129
- get headState() {
130
- const root = this.root.id;
131
- const order = this.order;
132
- const data = this.strategy.head.data;
133
- return {
134
- root,
135
- order,
136
- data
137
- };
138
- }
139
128
  constructor(strategy, comparator) {
140
129
  this._regexpCache = new CacheStorage();
141
- this._headBuffer = null;
142
130
  this._nodeCreateBuffer = /* @__PURE__ */ new Map();
143
131
  this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
144
132
  this.nodes = /* @__PURE__ */ new Map();
@@ -172,9 +160,6 @@ var BPTree = class {
172
160
  this.bufferForNodeUpdate(node);
173
161
  }
174
162
  }
175
- bufferForHeadUpdate(head) {
176
- this._headBuffer = head;
177
- }
178
163
  bufferForNodeCreate(node) {
179
164
  this._nodeCreateBuffer.set(node.id, node);
180
165
  }
@@ -306,7 +291,7 @@ var BPTreeSync = class extends BPTree {
306
291
  const keys = node.keys;
307
292
  this.root = this.getNode(keys[0]);
308
293
  this.root.parent = 0;
309
- this.bufferForHeadUpdate(this.headState);
294
+ this.strategy.head.root = this.root.id;
310
295
  this.bufferForNodeUpdate(this.root);
311
296
  return;
312
297
  } else if (this.root === node) {
@@ -512,9 +497,9 @@ var BPTreeSync = class extends BPTree {
512
497
  if (this.root === node) {
513
498
  const root = this._createNode([node.id, pointer.id], [value]);
514
499
  this.root = root;
500
+ this.strategy.head.root = root.id;
515
501
  node.parent = root.id;
516
502
  pointer.parent = root.id;
517
- this.bufferForHeadUpdate(this.headState);
518
503
  this.bufferForNodeCreate(root);
519
504
  this.bufferForNodeUpdate(node);
520
505
  this.bufferForNodeUpdate(pointer);
@@ -562,12 +547,13 @@ var BPTreeSync = class extends BPTree {
562
547
  if (head === null) {
563
548
  this.order = this.strategy.order;
564
549
  this.root = this._createNode([], [], true);
565
- this.bufferForHeadUpdate(this.headState);
550
+ this.strategy.head.root = this.root.id;
566
551
  this.bufferForNodeCreate(this.root);
567
552
  this.commitHeadBuffer();
568
553
  this.commitNodeCreateBuffer();
569
554
  } else {
570
555
  const { root, order } = head;
556
+ this.strategy.head = head;
571
557
  this.order = order;
572
558
  this.root = this.getNode(root);
573
559
  }
@@ -610,10 +596,7 @@ var BPTreeSync = class extends BPTree {
610
596
  return node;
611
597
  }
612
598
  commitHeadBuffer() {
613
- if (this._headBuffer !== null) {
614
- this.strategy.writeHead(this._headBuffer);
615
- }
616
- this.bufferForHeadUpdate(null);
599
+ this.strategy.writeHead(this.strategy.head);
617
600
  }
618
601
  commitNodeCreateBuffer() {
619
602
  for (const node of this._nodeCreateBuffer.values()) {
@@ -737,7 +720,6 @@ var BPTreeSync = class extends BPTree {
737
720
  }
738
721
  setHeadData(data) {
739
722
  this.strategy.head.data = data;
740
- this.bufferForHeadUpdate(this.headState);
741
723
  this.commitHeadBuffer();
742
724
  }
743
725
  forceUpdate() {
@@ -866,7 +848,7 @@ var BPTreeAsync = class extends BPTree {
866
848
  const keys = node.keys;
867
849
  this.root = await this.getNode(keys[0]);
868
850
  this.root.parent = 0;
869
- this.bufferForHeadUpdate(this.headState);
851
+ this.strategy.head.root = this.root.id;
870
852
  this.bufferForNodeUpdate(this.root);
871
853
  return;
872
854
  } else if (this.root === node) {
@@ -1045,9 +1027,9 @@ var BPTreeAsync = class extends BPTree {
1045
1027
  if (this.root === node) {
1046
1028
  const root = await this._createNode([node.id, pointer.id], [value]);
1047
1029
  this.root = root;
1030
+ this.strategy.head.root = root.id;
1048
1031
  node.parent = root.id;
1049
1032
  pointer.parent = root.id;
1050
- this.bufferForHeadUpdate(this.headState);
1051
1033
  this.bufferForNodeCreate(root);
1052
1034
  this.bufferForNodeUpdate(node);
1053
1035
  this.bufferForNodeUpdate(pointer);
@@ -1095,12 +1077,13 @@ var BPTreeAsync = class extends BPTree {
1095
1077
  if (head === null) {
1096
1078
  this.order = this.strategy.order;
1097
1079
  this.root = await this._createNode([], [], true);
1098
- this.bufferForHeadUpdate(this.headState);
1080
+ this.strategy.head.root = this.root.id;
1099
1081
  this.bufferForNodeCreate(this.root);
1100
1082
  this.commitHeadBuffer();
1101
1083
  this.commitNodeCreateBuffer();
1102
1084
  } else {
1103
1085
  const { root, order } = head;
1086
+ this.strategy.head = head;
1104
1087
  this.order = order;
1105
1088
  this.root = await this.getNode(root);
1106
1089
  }
@@ -1143,10 +1126,7 @@ var BPTreeAsync = class extends BPTree {
1143
1126
  return node;
1144
1127
  }
1145
1128
  async commitHeadBuffer() {
1146
- if (this._headBuffer !== null) {
1147
- await this.strategy.writeHead(this._headBuffer);
1148
- }
1149
- this.bufferForHeadUpdate(null);
1129
+ await this.strategy.writeHead(this.strategy.head);
1150
1130
  }
1151
1131
  async commitNodeCreateBuffer() {
1152
1132
  for (const node of this._nodeCreateBuffer.values()) {
@@ -1270,7 +1250,6 @@ var BPTreeAsync = class extends BPTree {
1270
1250
  }
1271
1251
  async setHeadData(data) {
1272
1252
  this.strategy.head.data = data;
1273
- this.bufferForHeadUpdate(this.headState);
1274
1253
  await this.commitHeadBuffer();
1275
1254
  }
1276
1255
  async forceUpdate() {
package/dist/esm/index.js CHANGED
@@ -47,7 +47,6 @@ var BPTree = class {
47
47
  root;
48
48
  _nodeCreateBuffer;
49
49
  _nodeUpdateBuffer;
50
- _headBuffer;
51
50
  verifierMap = {
52
51
  gt: (nv, v) => this.comparator.isHigher(nv, v),
53
52
  gte: (nv, v) => this.comparator.isHigher(nv, v) || this.comparator.isSame(nv, v),
@@ -92,19 +91,8 @@ var BPTree = class {
92
91
  notEqual: true,
93
92
  like: true
94
93
  };
95
- get headState() {
96
- const root = this.root.id;
97
- const order = this.order;
98
- const data = this.strategy.head.data;
99
- return {
100
- root,
101
- order,
102
- data
103
- };
104
- }
105
94
  constructor(strategy, comparator) {
106
95
  this._regexpCache = new CacheStorage();
107
- this._headBuffer = null;
108
96
  this._nodeCreateBuffer = /* @__PURE__ */ new Map();
109
97
  this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
110
98
  this.nodes = /* @__PURE__ */ new Map();
@@ -138,9 +126,6 @@ var BPTree = class {
138
126
  this.bufferForNodeUpdate(node);
139
127
  }
140
128
  }
141
- bufferForHeadUpdate(head) {
142
- this._headBuffer = head;
143
- }
144
129
  bufferForNodeCreate(node) {
145
130
  this._nodeCreateBuffer.set(node.id, node);
146
131
  }
@@ -272,7 +257,7 @@ var BPTreeSync = class extends BPTree {
272
257
  const keys = node.keys;
273
258
  this.root = this.getNode(keys[0]);
274
259
  this.root.parent = 0;
275
- this.bufferForHeadUpdate(this.headState);
260
+ this.strategy.head.root = this.root.id;
276
261
  this.bufferForNodeUpdate(this.root);
277
262
  return;
278
263
  } else if (this.root === node) {
@@ -478,9 +463,9 @@ var BPTreeSync = class extends BPTree {
478
463
  if (this.root === node) {
479
464
  const root = this._createNode([node.id, pointer.id], [value]);
480
465
  this.root = root;
466
+ this.strategy.head.root = root.id;
481
467
  node.parent = root.id;
482
468
  pointer.parent = root.id;
483
- this.bufferForHeadUpdate(this.headState);
484
469
  this.bufferForNodeCreate(root);
485
470
  this.bufferForNodeUpdate(node);
486
471
  this.bufferForNodeUpdate(pointer);
@@ -528,12 +513,13 @@ var BPTreeSync = class extends BPTree {
528
513
  if (head === null) {
529
514
  this.order = this.strategy.order;
530
515
  this.root = this._createNode([], [], true);
531
- this.bufferForHeadUpdate(this.headState);
516
+ this.strategy.head.root = this.root.id;
532
517
  this.bufferForNodeCreate(this.root);
533
518
  this.commitHeadBuffer();
534
519
  this.commitNodeCreateBuffer();
535
520
  } else {
536
521
  const { root, order } = head;
522
+ this.strategy.head = head;
537
523
  this.order = order;
538
524
  this.root = this.getNode(root);
539
525
  }
@@ -576,10 +562,7 @@ var BPTreeSync = class extends BPTree {
576
562
  return node;
577
563
  }
578
564
  commitHeadBuffer() {
579
- if (this._headBuffer !== null) {
580
- this.strategy.writeHead(this._headBuffer);
581
- }
582
- this.bufferForHeadUpdate(null);
565
+ this.strategy.writeHead(this.strategy.head);
583
566
  }
584
567
  commitNodeCreateBuffer() {
585
568
  for (const node of this._nodeCreateBuffer.values()) {
@@ -703,7 +686,6 @@ var BPTreeSync = class extends BPTree {
703
686
  }
704
687
  setHeadData(data) {
705
688
  this.strategy.head.data = data;
706
- this.bufferForHeadUpdate(this.headState);
707
689
  this.commitHeadBuffer();
708
690
  }
709
691
  forceUpdate() {
@@ -832,7 +814,7 @@ var BPTreeAsync = class extends BPTree {
832
814
  const keys = node.keys;
833
815
  this.root = await this.getNode(keys[0]);
834
816
  this.root.parent = 0;
835
- this.bufferForHeadUpdate(this.headState);
817
+ this.strategy.head.root = this.root.id;
836
818
  this.bufferForNodeUpdate(this.root);
837
819
  return;
838
820
  } else if (this.root === node) {
@@ -1011,9 +993,9 @@ var BPTreeAsync = class extends BPTree {
1011
993
  if (this.root === node) {
1012
994
  const root = await this._createNode([node.id, pointer.id], [value]);
1013
995
  this.root = root;
996
+ this.strategy.head.root = root.id;
1014
997
  node.parent = root.id;
1015
998
  pointer.parent = root.id;
1016
- this.bufferForHeadUpdate(this.headState);
1017
999
  this.bufferForNodeCreate(root);
1018
1000
  this.bufferForNodeUpdate(node);
1019
1001
  this.bufferForNodeUpdate(pointer);
@@ -1061,12 +1043,13 @@ var BPTreeAsync = class extends BPTree {
1061
1043
  if (head === null) {
1062
1044
  this.order = this.strategy.order;
1063
1045
  this.root = await this._createNode([], [], true);
1064
- this.bufferForHeadUpdate(this.headState);
1046
+ this.strategy.head.root = this.root.id;
1065
1047
  this.bufferForNodeCreate(this.root);
1066
1048
  this.commitHeadBuffer();
1067
1049
  this.commitNodeCreateBuffer();
1068
1050
  } else {
1069
1051
  const { root, order } = head;
1052
+ this.strategy.head = head;
1070
1053
  this.order = order;
1071
1054
  this.root = await this.getNode(root);
1072
1055
  }
@@ -1109,10 +1092,7 @@ var BPTreeAsync = class extends BPTree {
1109
1092
  return node;
1110
1093
  }
1111
1094
  async commitHeadBuffer() {
1112
- if (this._headBuffer !== null) {
1113
- await this.strategy.writeHead(this._headBuffer);
1114
- }
1115
- this.bufferForHeadUpdate(null);
1095
+ await this.strategy.writeHead(this.strategy.head);
1116
1096
  }
1117
1097
  async commitNodeCreateBuffer() {
1118
1098
  for (const node of this._nodeCreateBuffer.values()) {
@@ -1236,7 +1216,6 @@ var BPTreeAsync = class extends BPTree {
1236
1216
  }
1237
1217
  async setHeadData(data) {
1238
1218
  this.strategy.head.data = data;
1239
- this.bufferForHeadUpdate(this.headState);
1240
1219
  await this.commitHeadBuffer();
1241
1220
  }
1242
1221
  async forceUpdate() {
@@ -1,5 +1,5 @@
1
1
  import { ValueComparator } from './ValueComparator';
2
- import { SerializableData, SerializeStrategy, SerializeStrategyHead } from './SerializeStrategy';
2
+ import { SerializableData, SerializeStrategy } from './SerializeStrategy';
3
3
  type Sync<T> = T;
4
4
  type Async<T> = Promise<T>;
5
5
  type Deferred<T> = Sync<T> | Async<T>;
@@ -51,12 +51,10 @@ export declare abstract class BPTree<K, V> {
51
51
  protected root: BPTreeUnknownNode<K, V>;
52
52
  protected readonly _nodeCreateBuffer: Map<number, BPTreeUnknownNode<K, V>>;
53
53
  protected readonly _nodeUpdateBuffer: Map<number, BPTreeUnknownNode<K, V>>;
54
- protected _headBuffer: SerializeStrategyHead | null;
55
54
  protected readonly verifierMap: Record<keyof BPTreeCondition<V>, (nodeValue: V, value: V) => boolean>;
56
55
  protected readonly verifierStartNode: Record<keyof BPTreeCondition<V>, (value: V) => Deferred<BPTreeLeafNode<K, V>>>;
57
56
  protected readonly verifierDirection: Record<keyof BPTreeCondition<V>, -1 | 1>;
58
57
  protected readonly verifierFullScan: Record<keyof BPTreeCondition<V>, boolean>;
59
- protected get headState(): SerializeStrategyHead;
60
58
  protected constructor(strategy: SerializeStrategy<K, V>, comparator: ValueComparator<V>);
61
59
  protected abstract _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
62
60
  protected abstract _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
@@ -123,7 +121,6 @@ export declare abstract class BPTree<K, V> {
123
121
  */
124
122
  abstract forceUpdate(nodeId: number): Deferred<number>;
125
123
  protected _insertAtLeaf(node: BPTreeLeafNode<K, V>, key: K, value: V): void;
126
- protected bufferForHeadUpdate(head: SerializeStrategyHead | null): Deferred<void>;
127
124
  protected bufferForNodeCreate(node: BPTreeUnknownNode<K, V>): Deferred<void>;
128
125
  protected bufferForNodeUpdate(node: BPTreeUnknownNode<K, V>): Deferred<void>;
129
126
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",