serializable-bptree 6.0.0 → 6.0.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.
@@ -911,6 +911,10 @@ var BPTreeSync = class extends BPTree {
911
911
  this.strategy.head.root = root.id;
912
912
  node.parent = root.id;
913
913
  pointer.parent = root.id;
914
+ if (pointer.leaf) {
915
+ node.next = pointer.id;
916
+ pointer.prev = node.id;
917
+ }
914
918
  this.bufferForNodeUpdate(node);
915
919
  this.bufferForNodeUpdate(pointer);
916
920
  return;
@@ -927,6 +931,22 @@ var BPTreeSync = class extends BPTree {
927
931
  parentNode.values.splice(insertIndex, 0, value);
928
932
  parentNode.keys.splice(insertIndex + 1, 0, pointer.id);
929
933
  pointer.parent = parentNode.id;
934
+ if (pointer.leaf) {
935
+ const leftSiblingId = parentNode.keys[insertIndex];
936
+ const rightSiblingId = parentNode.keys[insertIndex + 2];
937
+ if (leftSiblingId) {
938
+ const leftSibling = this.getNode(leftSiblingId);
939
+ pointer.prev = leftSibling.id;
940
+ pointer.next = leftSibling.next;
941
+ leftSibling.next = pointer.id;
942
+ this.bufferForNodeUpdate(leftSibling);
943
+ }
944
+ if (rightSiblingId) {
945
+ const rightSibling = this.getNode(rightSiblingId);
946
+ rightSibling.prev = pointer.id;
947
+ this.bufferForNodeUpdate(rightSibling);
948
+ }
949
+ }
930
950
  this.bufferForNodeUpdate(parentNode);
931
951
  this.bufferForNodeUpdate(pointer);
932
952
  if (parentNode.keys.length > this.order) {
@@ -1115,21 +1135,14 @@ var BPTreeSync = class extends BPTree {
1115
1135
  [],
1116
1136
  true,
1117
1137
  before.parent,
1118
- before.next,
1119
- before.id
1138
+ null,
1139
+ null
1120
1140
  );
1121
1141
  const mid = Math.ceil(this.order / 2) - 1;
1122
- const beforeNext = before.next;
1123
1142
  after.values = before.values.slice(mid + 1);
1124
1143
  after.keys = before.keys.slice(mid + 1);
1125
1144
  before.values = before.values.slice(0, mid + 1);
1126
1145
  before.keys = before.keys.slice(0, mid + 1);
1127
- before.next = after.id;
1128
- if (beforeNext) {
1129
- const node = this.getNode(beforeNext);
1130
- node.prev = after.id;
1131
- this.bufferForNodeUpdate(node);
1132
- }
1133
1146
  this._insertInParent(before, after.values[0], after);
1134
1147
  this.bufferForNodeUpdate(before);
1135
1148
  }
@@ -1785,6 +1798,10 @@ var BPTreeAsync = class extends BPTree {
1785
1798
  this.strategy.head.root = root.id;
1786
1799
  node.parent = root.id;
1787
1800
  pointer.parent = root.id;
1801
+ if (pointer.leaf) {
1802
+ node.next = pointer.id;
1803
+ pointer.prev = node.id;
1804
+ }
1788
1805
  this.bufferForNodeUpdate(node);
1789
1806
  this.bufferForNodeUpdate(pointer);
1790
1807
  return;
@@ -1801,6 +1818,22 @@ var BPTreeAsync = class extends BPTree {
1801
1818
  parentNode.values.splice(insertIndex, 0, value);
1802
1819
  parentNode.keys.splice(insertIndex + 1, 0, pointer.id);
1803
1820
  pointer.parent = parentNode.id;
1821
+ if (pointer.leaf) {
1822
+ const leftSiblingId = parentNode.keys[insertIndex];
1823
+ const rightSiblingId = parentNode.keys[insertIndex + 2];
1824
+ if (leftSiblingId) {
1825
+ const leftSibling = await this.getNode(leftSiblingId);
1826
+ pointer.prev = leftSibling.id;
1827
+ pointer.next = leftSibling.next;
1828
+ leftSibling.next = pointer.id;
1829
+ this.bufferForNodeUpdate(leftSibling);
1830
+ }
1831
+ if (rightSiblingId) {
1832
+ const rightSibling = await this.getNode(rightSiblingId);
1833
+ rightSibling.prev = pointer.id;
1834
+ this.bufferForNodeUpdate(rightSibling);
1835
+ }
1836
+ }
1804
1837
  this.bufferForNodeUpdate(parentNode);
1805
1838
  this.bufferForNodeUpdate(pointer);
1806
1839
  if (parentNode.keys.length > this.order) {
@@ -1994,21 +2027,14 @@ var BPTreeAsync = class extends BPTree {
1994
2027
  [],
1995
2028
  true,
1996
2029
  before.parent,
1997
- before.next,
1998
- before.id
2030
+ null,
2031
+ null
1999
2032
  );
2000
2033
  const mid = Math.ceil(this.order / 2) - 1;
2001
- const beforeNext = before.next;
2002
2034
  after.values = before.values.slice(mid + 1);
2003
2035
  after.keys = before.keys.slice(mid + 1);
2004
2036
  before.values = before.values.slice(0, mid + 1);
2005
2037
  before.keys = before.keys.slice(0, mid + 1);
2006
- before.next = after.id;
2007
- if (beforeNext) {
2008
- const node = await this.getNode(beforeNext);
2009
- node.prev = after.id;
2010
- this.bufferForNodeUpdate(node);
2011
- }
2012
2038
  await this._insertInParent(before, after.values[0], after);
2013
2039
  this.bufferForNodeUpdate(before);
2014
2040
  }
@@ -877,6 +877,10 @@ var BPTreeSync = class extends BPTree {
877
877
  this.strategy.head.root = root.id;
878
878
  node.parent = root.id;
879
879
  pointer.parent = root.id;
880
+ if (pointer.leaf) {
881
+ node.next = pointer.id;
882
+ pointer.prev = node.id;
883
+ }
880
884
  this.bufferForNodeUpdate(node);
881
885
  this.bufferForNodeUpdate(pointer);
882
886
  return;
@@ -893,6 +897,22 @@ var BPTreeSync = class extends BPTree {
893
897
  parentNode.values.splice(insertIndex, 0, value);
894
898
  parentNode.keys.splice(insertIndex + 1, 0, pointer.id);
895
899
  pointer.parent = parentNode.id;
900
+ if (pointer.leaf) {
901
+ const leftSiblingId = parentNode.keys[insertIndex];
902
+ const rightSiblingId = parentNode.keys[insertIndex + 2];
903
+ if (leftSiblingId) {
904
+ const leftSibling = this.getNode(leftSiblingId);
905
+ pointer.prev = leftSibling.id;
906
+ pointer.next = leftSibling.next;
907
+ leftSibling.next = pointer.id;
908
+ this.bufferForNodeUpdate(leftSibling);
909
+ }
910
+ if (rightSiblingId) {
911
+ const rightSibling = this.getNode(rightSiblingId);
912
+ rightSibling.prev = pointer.id;
913
+ this.bufferForNodeUpdate(rightSibling);
914
+ }
915
+ }
896
916
  this.bufferForNodeUpdate(parentNode);
897
917
  this.bufferForNodeUpdate(pointer);
898
918
  if (parentNode.keys.length > this.order) {
@@ -1081,21 +1101,14 @@ var BPTreeSync = class extends BPTree {
1081
1101
  [],
1082
1102
  true,
1083
1103
  before.parent,
1084
- before.next,
1085
- before.id
1104
+ null,
1105
+ null
1086
1106
  );
1087
1107
  const mid = Math.ceil(this.order / 2) - 1;
1088
- const beforeNext = before.next;
1089
1108
  after.values = before.values.slice(mid + 1);
1090
1109
  after.keys = before.keys.slice(mid + 1);
1091
1110
  before.values = before.values.slice(0, mid + 1);
1092
1111
  before.keys = before.keys.slice(0, mid + 1);
1093
- before.next = after.id;
1094
- if (beforeNext) {
1095
- const node = this.getNode(beforeNext);
1096
- node.prev = after.id;
1097
- this.bufferForNodeUpdate(node);
1098
- }
1099
1112
  this._insertInParent(before, after.values[0], after);
1100
1113
  this.bufferForNodeUpdate(before);
1101
1114
  }
@@ -1751,6 +1764,10 @@ var BPTreeAsync = class extends BPTree {
1751
1764
  this.strategy.head.root = root.id;
1752
1765
  node.parent = root.id;
1753
1766
  pointer.parent = root.id;
1767
+ if (pointer.leaf) {
1768
+ node.next = pointer.id;
1769
+ pointer.prev = node.id;
1770
+ }
1754
1771
  this.bufferForNodeUpdate(node);
1755
1772
  this.bufferForNodeUpdate(pointer);
1756
1773
  return;
@@ -1767,6 +1784,22 @@ var BPTreeAsync = class extends BPTree {
1767
1784
  parentNode.values.splice(insertIndex, 0, value);
1768
1785
  parentNode.keys.splice(insertIndex + 1, 0, pointer.id);
1769
1786
  pointer.parent = parentNode.id;
1787
+ if (pointer.leaf) {
1788
+ const leftSiblingId = parentNode.keys[insertIndex];
1789
+ const rightSiblingId = parentNode.keys[insertIndex + 2];
1790
+ if (leftSiblingId) {
1791
+ const leftSibling = await this.getNode(leftSiblingId);
1792
+ pointer.prev = leftSibling.id;
1793
+ pointer.next = leftSibling.next;
1794
+ leftSibling.next = pointer.id;
1795
+ this.bufferForNodeUpdate(leftSibling);
1796
+ }
1797
+ if (rightSiblingId) {
1798
+ const rightSibling = await this.getNode(rightSiblingId);
1799
+ rightSibling.prev = pointer.id;
1800
+ this.bufferForNodeUpdate(rightSibling);
1801
+ }
1802
+ }
1770
1803
  this.bufferForNodeUpdate(parentNode);
1771
1804
  this.bufferForNodeUpdate(pointer);
1772
1805
  if (parentNode.keys.length > this.order) {
@@ -1960,21 +1993,14 @@ var BPTreeAsync = class extends BPTree {
1960
1993
  [],
1961
1994
  true,
1962
1995
  before.parent,
1963
- before.next,
1964
- before.id
1996
+ null,
1997
+ null
1965
1998
  );
1966
1999
  const mid = Math.ceil(this.order / 2) - 1;
1967
- const beforeNext = before.next;
1968
2000
  after.values = before.values.slice(mid + 1);
1969
2001
  after.keys = before.keys.slice(mid + 1);
1970
2002
  before.values = before.values.slice(0, mid + 1);
1971
2003
  before.keys = before.keys.slice(0, mid + 1);
1972
- before.next = after.id;
1973
- if (beforeNext) {
1974
- const node = await this.getNode(beforeNext);
1975
- node.prev = after.id;
1976
- this.bufferForNodeUpdate(node);
1977
- }
1978
2004
  await this._insertInParent(before, after.values[0], after);
1979
2005
  this.bufferForNodeUpdate(before);
1980
2006
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
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",