serializable-bptree 6.0.0 → 6.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.
@@ -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) {
@@ -971,6 +991,9 @@ var BPTreeSync = class extends BPTree {
971
991
  }
972
992
  }
973
993
  getNode(id) {
994
+ if (this._nodeUpdateBuffer.has(id)) {
995
+ return this._nodeUpdateBuffer.get(id);
996
+ }
974
997
  if (this._nodeCreateBuffer.has(id)) {
975
998
  return this._nodeCreateBuffer.get(id);
976
999
  }
@@ -978,7 +1001,7 @@ var BPTreeSync = class extends BPTree {
978
1001
  return cache.raw;
979
1002
  }
980
1003
  insertableNode(value) {
981
- let node = this.root;
1004
+ let node = this.getNode(this.root.id);
982
1005
  while (!node.leaf) {
983
1006
  for (let i = 0, len = node.values.length; i < len; i++) {
984
1007
  const nValue = node.values[i];
@@ -1115,21 +1138,14 @@ var BPTreeSync = class extends BPTree {
1115
1138
  [],
1116
1139
  true,
1117
1140
  before.parent,
1118
- before.next,
1119
- before.id
1141
+ null,
1142
+ null
1120
1143
  );
1121
1144
  const mid = Math.ceil(this.order / 2) - 1;
1122
- const beforeNext = before.next;
1123
1145
  after.values = before.values.slice(mid + 1);
1124
1146
  after.keys = before.keys.slice(mid + 1);
1125
1147
  before.values = before.values.slice(0, mid + 1);
1126
1148
  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
1149
  this._insertInParent(before, after.values[0], after);
1134
1150
  this.bufferForNodeUpdate(before);
1135
1151
  }
@@ -1785,6 +1801,10 @@ var BPTreeAsync = class extends BPTree {
1785
1801
  this.strategy.head.root = root.id;
1786
1802
  node.parent = root.id;
1787
1803
  pointer.parent = root.id;
1804
+ if (pointer.leaf) {
1805
+ node.next = pointer.id;
1806
+ pointer.prev = node.id;
1807
+ }
1788
1808
  this.bufferForNodeUpdate(node);
1789
1809
  this.bufferForNodeUpdate(pointer);
1790
1810
  return;
@@ -1801,6 +1821,22 @@ var BPTreeAsync = class extends BPTree {
1801
1821
  parentNode.values.splice(insertIndex, 0, value);
1802
1822
  parentNode.keys.splice(insertIndex + 1, 0, pointer.id);
1803
1823
  pointer.parent = parentNode.id;
1824
+ if (pointer.leaf) {
1825
+ const leftSiblingId = parentNode.keys[insertIndex];
1826
+ const rightSiblingId = parentNode.keys[insertIndex + 2];
1827
+ if (leftSiblingId) {
1828
+ const leftSibling = await this.getNode(leftSiblingId);
1829
+ pointer.prev = leftSibling.id;
1830
+ pointer.next = leftSibling.next;
1831
+ leftSibling.next = pointer.id;
1832
+ this.bufferForNodeUpdate(leftSibling);
1833
+ }
1834
+ if (rightSiblingId) {
1835
+ const rightSibling = await this.getNode(rightSiblingId);
1836
+ rightSibling.prev = pointer.id;
1837
+ this.bufferForNodeUpdate(rightSibling);
1838
+ }
1839
+ }
1804
1840
  this.bufferForNodeUpdate(parentNode);
1805
1841
  this.bufferForNodeUpdate(pointer);
1806
1842
  if (parentNode.keys.length > this.order) {
@@ -1845,6 +1881,9 @@ var BPTreeAsync = class extends BPTree {
1845
1881
  }
1846
1882
  }
1847
1883
  async getNode(id) {
1884
+ if (this._nodeUpdateBuffer.has(id)) {
1885
+ return this._nodeUpdateBuffer.get(id);
1886
+ }
1848
1887
  if (this._nodeCreateBuffer.has(id)) {
1849
1888
  return this._nodeCreateBuffer.get(id);
1850
1889
  }
@@ -1852,7 +1891,7 @@ var BPTreeAsync = class extends BPTree {
1852
1891
  return cache.raw;
1853
1892
  }
1854
1893
  async insertableNode(value) {
1855
- let node = this.root;
1894
+ let node = await this.getNode(this.root.id);
1856
1895
  while (!node.leaf) {
1857
1896
  for (let i = 0, len = node.values.length; i < len; i++) {
1858
1897
  const nValue = node.values[i];
@@ -1994,21 +2033,14 @@ var BPTreeAsync = class extends BPTree {
1994
2033
  [],
1995
2034
  true,
1996
2035
  before.parent,
1997
- before.next,
1998
- before.id
2036
+ null,
2037
+ null
1999
2038
  );
2000
2039
  const mid = Math.ceil(this.order / 2) - 1;
2001
- const beforeNext = before.next;
2002
2040
  after.values = before.values.slice(mid + 1);
2003
2041
  after.keys = before.keys.slice(mid + 1);
2004
2042
  before.values = before.values.slice(0, mid + 1);
2005
2043
  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
2044
  await this._insertInParent(before, after.values[0], after);
2013
2045
  this.bufferForNodeUpdate(before);
2014
2046
  }
@@ -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) {
@@ -937,6 +957,9 @@ var BPTreeSync = class extends BPTree {
937
957
  }
938
958
  }
939
959
  getNode(id) {
960
+ if (this._nodeUpdateBuffer.has(id)) {
961
+ return this._nodeUpdateBuffer.get(id);
962
+ }
940
963
  if (this._nodeCreateBuffer.has(id)) {
941
964
  return this._nodeCreateBuffer.get(id);
942
965
  }
@@ -944,7 +967,7 @@ var BPTreeSync = class extends BPTree {
944
967
  return cache.raw;
945
968
  }
946
969
  insertableNode(value) {
947
- let node = this.root;
970
+ let node = this.getNode(this.root.id);
948
971
  while (!node.leaf) {
949
972
  for (let i = 0, len = node.values.length; i < len; i++) {
950
973
  const nValue = node.values[i];
@@ -1081,21 +1104,14 @@ var BPTreeSync = class extends BPTree {
1081
1104
  [],
1082
1105
  true,
1083
1106
  before.parent,
1084
- before.next,
1085
- before.id
1107
+ null,
1108
+ null
1086
1109
  );
1087
1110
  const mid = Math.ceil(this.order / 2) - 1;
1088
- const beforeNext = before.next;
1089
1111
  after.values = before.values.slice(mid + 1);
1090
1112
  after.keys = before.keys.slice(mid + 1);
1091
1113
  before.values = before.values.slice(0, mid + 1);
1092
1114
  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
1115
  this._insertInParent(before, after.values[0], after);
1100
1116
  this.bufferForNodeUpdate(before);
1101
1117
  }
@@ -1751,6 +1767,10 @@ var BPTreeAsync = class extends BPTree {
1751
1767
  this.strategy.head.root = root.id;
1752
1768
  node.parent = root.id;
1753
1769
  pointer.parent = root.id;
1770
+ if (pointer.leaf) {
1771
+ node.next = pointer.id;
1772
+ pointer.prev = node.id;
1773
+ }
1754
1774
  this.bufferForNodeUpdate(node);
1755
1775
  this.bufferForNodeUpdate(pointer);
1756
1776
  return;
@@ -1767,6 +1787,22 @@ var BPTreeAsync = class extends BPTree {
1767
1787
  parentNode.values.splice(insertIndex, 0, value);
1768
1788
  parentNode.keys.splice(insertIndex + 1, 0, pointer.id);
1769
1789
  pointer.parent = parentNode.id;
1790
+ if (pointer.leaf) {
1791
+ const leftSiblingId = parentNode.keys[insertIndex];
1792
+ const rightSiblingId = parentNode.keys[insertIndex + 2];
1793
+ if (leftSiblingId) {
1794
+ const leftSibling = await this.getNode(leftSiblingId);
1795
+ pointer.prev = leftSibling.id;
1796
+ pointer.next = leftSibling.next;
1797
+ leftSibling.next = pointer.id;
1798
+ this.bufferForNodeUpdate(leftSibling);
1799
+ }
1800
+ if (rightSiblingId) {
1801
+ const rightSibling = await this.getNode(rightSiblingId);
1802
+ rightSibling.prev = pointer.id;
1803
+ this.bufferForNodeUpdate(rightSibling);
1804
+ }
1805
+ }
1770
1806
  this.bufferForNodeUpdate(parentNode);
1771
1807
  this.bufferForNodeUpdate(pointer);
1772
1808
  if (parentNode.keys.length > this.order) {
@@ -1811,6 +1847,9 @@ var BPTreeAsync = class extends BPTree {
1811
1847
  }
1812
1848
  }
1813
1849
  async getNode(id) {
1850
+ if (this._nodeUpdateBuffer.has(id)) {
1851
+ return this._nodeUpdateBuffer.get(id);
1852
+ }
1814
1853
  if (this._nodeCreateBuffer.has(id)) {
1815
1854
  return this._nodeCreateBuffer.get(id);
1816
1855
  }
@@ -1818,7 +1857,7 @@ var BPTreeAsync = class extends BPTree {
1818
1857
  return cache.raw;
1819
1858
  }
1820
1859
  async insertableNode(value) {
1821
- let node = this.root;
1860
+ let node = await this.getNode(this.root.id);
1822
1861
  while (!node.leaf) {
1823
1862
  for (let i = 0, len = node.values.length; i < len; i++) {
1824
1863
  const nValue = node.values[i];
@@ -1960,21 +1999,14 @@ var BPTreeAsync = class extends BPTree {
1960
1999
  [],
1961
2000
  true,
1962
2001
  before.parent,
1963
- before.next,
1964
- before.id
2002
+ null,
2003
+ null
1965
2004
  );
1966
2005
  const mid = Math.ceil(this.order / 2) - 1;
1967
- const beforeNext = before.next;
1968
2006
  after.values = before.values.slice(mid + 1);
1969
2007
  after.keys = before.keys.slice(mid + 1);
1970
2008
  before.values = before.values.slice(0, mid + 1);
1971
2009
  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
2010
  await this._insertInParent(before, after.values[0], after);
1979
2011
  this.bufferForNodeUpdate(before);
1980
2012
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "6.0.0",
3
+ "version": "6.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",