sorted-btree
Version:
A sorted list of key-value pairs in a fast, typed in-memory B+ tree with a powerful API.
2 lines (1 loc) • 20 kB
JavaScript
"use strict";var __extends=this&&this.__extends||function(){var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}}();function defaultComparator(e,t){if(Number.isFinite(e)&&Number.isFinite(t))return e-t;var r=typeof e,i=typeof t;if(r!==i)return r<i?-1:1;if("object"===r){if(null===e)return null===t?0:-1;if(null===t)return 1;if((r=typeof(e=e.valueOf()))!==(i=typeof(t=t.valueOf())))return r<i?-1:1}return e<t?-1:t<e?1:e===t?0:Number.isNaN(e)?Number.isNaN(t)?0:-1:Number.isNaN(t)?1:Array.isArray(e)?0:Number.NaN}function simpleComparator(e,t){return t<e?1:e<t?-1:0}function fixMaxSize(e){return 4<=e?Math.min(0|e,256):32}Object.defineProperty(exports,"__esModule",{value:!0}),exports.EmptyBTree=exports.check=exports.areOverlapping=exports.sumChildSizes=exports.BNodeInternal=exports.BNode=exports.asSet=exports.fixMaxSize=exports.simpleComparator=exports.defaultComparator=void 0,exports.defaultComparator=defaultComparator,exports.simpleComparator=simpleComparator,exports.fixMaxSize=fixMaxSize;var BTree=function(){function r(e,t,r){this._root=EmptyLeaf,this._maxNodeSize=fixMaxSize(r),this._compare=t||defaultComparator,e&&this.setPairs(e)}return Object.defineProperty(r.prototype,"size",{get:function(){return this._root.size()},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"length",{get:function(){return this.size},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"isEmpty",{get:function(){return 0===this._root.size()},enumerable:!1,configurable:!0}),r.prototype.clear=function(){this._root=EmptyLeaf},r.prototype.forEach=function(r,e){var i=this;return void 0!==e&&(r=r.bind(e)),this.forEachPair(function(e,t){return r(t,e,i)})},r.prototype.forEachPair=function(e,t){var r=this.minKey(),i=this.maxKey();return this.forRange(r,i,!0,e,t)},r.prototype.get=function(e,t){return this._root.get(e,t,this)},r.prototype.set=function(e,t,r){this._root.isShared&&(this._root=this._root.clone());r=this._root.set(e,t,r,this);if(!0===r||!1===r)return r;r=[this._root,r];return this._root=new BNodeInternal(r,sumChildSizes(r)),!0},r.prototype.has=function(e){return 0!==this.forRange(e,e,!0,void 0)},r.prototype.delete=function(e){return 0!==this.editRange(e,e,!0,DeleteRange)},r.prototype.with=function(e,t,r){var i=this.clone();return i.set(e,t,r)||r?i:this},r.prototype.withPairs=function(e,t){var r=this.clone();return 0!==r.setPairs(e,t)||t?r:this},r.prototype.withKeys=function(e,t){for(var r=this.clone(),i=!1,n=0;n<e.length;n++)i=r.set(e[n],void 0,!1)||i;return t&&!i?this:r},r.prototype.without=function(e,t){return this.withoutRange(e,e,!0,t)},r.prototype.withoutKeys=function(e,t){var r=this.clone();return r.deleteKeys(e)||!t?r:this},r.prototype.withoutRange=function(e,t,r,i){var n=this.clone();return 0===n.deleteRange(e,t,r)&&i?this:n},r.prototype.filter=function(i,e){var n,t=this.greedyClone();return t.editAll(function(e,t,r){if(!i(e,t,r))return n=Delete}),!n&&e?this:t},r.prototype.mapValues=function(i){var n={},e=this.greedyClone();return e.editAll(function(e,t,r){return n.value=i(t,e,r),n}),e},r.prototype.reduce=function(e,t){for(var r,i=0,n=t,o=this.entries(this.minKey(),ReusedArray);!(r=o.next()).done;)n=e(n,r.value,i++,this);return n},r.prototype.entries=function(e,t){var r=this.findPath(e);if(void 0===r)return iterator();var i=r.nodequeue,n=r.nodeindex,o=r.leaf,s=void 0!==t?1:0,h=void 0===e?-1:o.indexOf(e,0,this._compare)-1;return iterator(function(){e:for(;;)switch(s){case 0:if(++h<o.keys.length)return{done:!1,value:[o.keys[h],o.values[h]]};s=2;continue;case 1:if(++h<o.keys.length)return t[0]=o.keys[h],t[1]=o.values[h],{done:!1,value:t};s=2;case 2:for(var e=-1;;){if(++e>=i.length){s=3;continue e}if(++n[e]<i[e].length)break}for(;0<e;e--)i[e-1]=i[e][n[e]].children,n[e-1]=0;o=i[0][n[0]],h=-1,s=void 0!==t?1:0;continue;case 3:return{done:!0,value:void 0}}})},r.prototype.entriesReversed=function(e,t,r){if(void 0===e&&(r=void 0)===(e=this.maxKey()))return iterator();var i=this.findPath(e)||this.findPath(this.maxKey()),n=i.nodequeue,o=i.nodeindex,s=i.leaf;check(!n[0]||s===n[0][o[0]],"wat!");var h=s.indexOf(e,0,this._compare);!r&&h<s.keys.length&&this._compare(s.keys[h],e)<=0&&h++;var a=void 0!==t?1:0;return iterator(function(){e:for(;;)switch(a){case 0:if(0<=--h)return{done:!1,value:[s.keys[h],s.values[h]]};a=2;continue;case 1:if(0<=--h)return t[0]=s.keys[h],t[1]=s.values[h],{done:!1,value:t};a=2;case 2:for(var e=-1;;){if(++e>=n.length){a=3;continue e}if(0<=--o[e])break}for(;0<e;e--)n[e-1]=n[e][o[e]].children,o[e-1]=n[e-1].length-1;s=n[0][o[0]],h=s.keys.length,a=void 0!==t?1:0;continue;case 3:return{done:!0,value:void 0}}})},r.prototype.findPath=function(e){var t,r,i=this._root;if(i.isLeaf)r=t=EmptyArray;else{t=[],r=[];for(var n=0;!i.isLeaf;n++){if(t[n]=i.children,r[n]=void 0===e?0:i.indexOf(e,0,this._compare),r[n]>=t[n].length)return;i=t[n][r[n]]}t.reverse(),r.reverse()}return{nodequeue:t,nodeindex:r,leaf:i}},r.prototype.keys=function(e){var t=this.entries(e,ReusedArray);return iterator(function(){var e=t.next();return e.value&&(e.value=e.value[0]),e})},r.prototype.values=function(e){var t=this.entries(e,ReusedArray);return iterator(function(){var e=t.next();return e.value&&(e.value=e.value[1]),e})},Object.defineProperty(r.prototype,"maxNodeSize",{get:function(){return this._maxNodeSize},enumerable:!1,configurable:!0}),r.prototype.minKey=function(){return this._root.minKey()},r.prototype.maxKey=function(){return this._root.maxKey()},r.prototype.clone=function(){this._root.isShared=!0;var e=new r(void 0,this._compare,this._maxNodeSize);return e._root=this._root,e},r.prototype.greedyClone=function(e){var t=new r(void 0,this._compare,this._maxNodeSize);return t._root=this._root.greedyClone(e),t},r.prototype.toArray=function(e){void 0===e&&(e=2147483647);var t=this.minKey(),r=this.maxKey();return void 0!==t?this.getRange(t,r,!0,e):[]},r.prototype.keysArray=function(){var r=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,function(e,t){r.push(e)}),r},r.prototype.valuesArray=function(){var r=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,function(e,t){r.push(t)}),r},r.prototype.toString=function(){return this.toArray().toString()},r.prototype.setIfNotPresent=function(e,t){return this.set(e,t,!1)},r.prototype.nextHigherPair=function(e,t){return t=t||[],void 0===e?this._root.minPair(t):this._root.getPairOrNextHigher(e,this._compare,!1,t)},r.prototype.nextHigherKey=function(e){e=this.nextHigherPair(e,ReusedArray);return e&&e[0]},r.prototype.nextLowerPair=function(e,t){return t=t||[],void 0===e?this._root.maxPair(t):this._root.getPairOrNextLower(e,this._compare,!1,t)},r.prototype.nextLowerKey=function(e){e=this.nextLowerPair(e,ReusedArray);return e&&e[0]},r.prototype.getPairOrNextLower=function(e,t){return this._root.getPairOrNextLower(e,this._compare,!0,t||[])},r.prototype.getPairOrNextHigher=function(e,t){return this._root.getPairOrNextHigher(e,this._compare,!0,t||[])},r.prototype.changeIfPresent=function(e,r){return 0!==this.editRange(e,e,!0,function(e,t){return{value:r}})},r.prototype.getRange=function(e,t,r,i){void 0===i&&(i=67108863);var n=[];return this._root.forRange(e,t,r,!1,this,0,function(e,t){return n.push([e,t]),n.length>i?Break:void 0}),n},r.prototype.setPairs=function(e,t){for(var r=0,i=0;i<e.length;i++)this.set(e[i][0],e[i][1],t)&&r++;return r},r.prototype.forRange=function(e,t,r,i,n){i=this._root.forRange(e,t,r,!1,this,n||0,i);return"number"==typeof i?i:i.break},r.prototype.editRange=function(e,t,r,i,n){var o=this._root;o.isShared&&(this._root=o=o.clone());try{var s=o.forRange(e,t,r,!0,this,n||0,i);return"number"==typeof s?s:s.break}finally{for(var h=void 0;o.keys.length<=1&&!o.isLeaf;)h=h||o.isShared,this._root=o=0===o.keys.length?EmptyLeaf:o.children[0];h&&(o.isShared=!0)}},r.prototype.editAll=function(e,t){return this.editRange(this.minKey(),this.maxKey(),!0,e,t)},r.prototype.deleteRange=function(e,t,r){return this.editRange(e,t,r,DeleteRange)},r.prototype.deleteKeys=function(e){for(var t=0,r=0;t<e.length;t++)this.delete(e[t])&&r++;return r},Object.defineProperty(r.prototype,"height",{get:function(){for(var e=this._root,t=-1;e;)t++,e=e.isLeaf?void 0:e.children[0];return t},enumerable:!1,configurable:!0}),r.prototype.freeze=function(){this.clear=this.set=this.editRange=function(){throw new Error("Attempted to modify a frozen BTree")}},r.prototype.unfreeze=function(){delete this.clear,delete this.set,delete this.editRange},Object.defineProperty(r.prototype,"isFrozen",{get:function(){return this.hasOwnProperty("editRange")},enumerable:!1,configurable:!0}),r.prototype.checkValid=function(e){void 0===e&&(e=!1);e=this._root.checkValid(0,this,0,e)[0];check(e===this.size,"size mismatch: counted ",e,"but stored",this.size)},r}();function asSet(e){return e}function iterator(e){void 0===e&&(e=function(){return{done:!0,value:void 0}});e={next:e};return Symbol&&Symbol.iterator&&(e[Symbol.iterator]=function(){return this}),e}exports.default=BTree,exports.asSet=asSet,Symbol&&Symbol.iterator&&(BTree.prototype[Symbol.iterator]=BTree.prototype.entries),BTree.prototype.where=BTree.prototype.filter,BTree.prototype.setRange=BTree.prototype.setPairs,BTree.prototype.add=BTree.prototype.set;var BNode=function(){function t(e,t){void 0===e&&(e=[]),this.keys=e,this.values=t||undefVals,this.isShared=void 0}return Object.defineProperty(t.prototype,"isLeaf",{get:function(){return void 0===this.children},enumerable:!1,configurable:!0}),t.prototype.size=function(){return this.keys.length},t.prototype.maxKey=function(){return this.keys[this.keys.length-1]},t.prototype.indexOf=function(e,t,r){for(var i=this.keys,n=0,o=i.length,s=o>>1;n<o;){var h=r(i[s],e);if(h<0)n=s+1;else{if(!(0<h)){if(0===h)return s;if(e==e)return i.length;throw new Error("BTree: NaN was used as a key")}o=s}s=n+o>>1}return s^t},t.prototype.minKey=function(){return this.keys[0]},t.prototype.minPair=function(e){if(0!==this.keys.length)return e[0]=this.keys[0],e[1]=this.values[0],e},t.prototype.maxPair=function(e){if(0!==this.keys.length){var t=this.keys.length-1;return e[0]=this.keys[t],e[1]=this.values[t],e}},t.prototype.clone=function(){var e=this.values;return new t(this.keys.slice(0),e===undefVals?e:e.slice(0))},t.prototype.greedyClone=function(e){return this.isShared&&!e?this:this.clone()},t.prototype.get=function(e,t,r){r=this.indexOf(e,-1,r._compare);return r<0?t:this.values[r]},t.prototype.getPairOrNextLower=function(e,t,r,i){t=this.indexOf(e,-1,t),t=t<0?~t-1:r?t:t-1;if(0<=t)return i[0]=this.keys[t],i[1]=this.values[t],i},t.prototype.getPairOrNextHigher=function(e,t,r,i){t=this.indexOf(e,-1,t),r=t<0?~t:r?t:t+1,t=this.keys;if(r<t.length)return i[0]=t[r],i[1]=this.values[r],i},t.prototype.checkValid=function(e,t,r,i){var n=this.keys.length,o=this.values.length;if(check(this.values===undefVals?n<=o:n===o,"keys/values length mismatch: depth",e,"with lengths",n,o,"and baseIndex",r),check(0==e||0<n,"empty leaf at depth",e,"and baseIndex",r),!0===i)for(var s=1;s<n;s++)check(t._compare(this.keys[s-1],this.keys[s])<0,"keys out of order at depth",e,"and baseIndex",r+s-1,": ",this.keys[s-1]," !< ",this.keys[s]);return[n,this.keys[0],this.keys[n-1]]},t.prototype.set=function(e,t,r,i){var n=this.indexOf(e,-1,i._compare);if(n<0){if(n=~n,this.keys.length<i._maxNodeSize)return this.insertInLeaf(n,e,t,i);var o=this.splitOffRightSide(),s=this;return n>this.keys.length&&(n-=this.keys.length,s=o),s.insertInLeaf(n,e,t,i),o}return!1!==r&&(void 0!==t&&this.reifyValues(),this.keys[n]=e,this.values[n]=t),!1},t.prototype.reifyValues=function(){return this.values===undefVals?this.values=this.values.slice(0,this.keys.length):this.values},t.prototype.insertInLeaf=function(e,t,r,i){if(this.keys.splice(e,0,t),this.values===undefVals){for(;undefVals.length<i._maxNodeSize;)undefVals.push(void 0);if(void 0===r)return!0;this.values=undefVals.slice(0,this.keys.length-1)}return this.values.splice(e,0,r),!0},t.prototype.takeFromRight=function(e){var t=this.values;e.values===undefVals?t!==undefVals&&t.push(void 0):(t=this.reifyValues()).push(e.values.shift()),this.keys.push(e.keys.shift())},t.prototype.takeFromLeft=function(e){var t=this.values;e.values===undefVals?t!==undefVals&&t.unshift(void 0):(t=this.reifyValues()).unshift(e.values.pop()),this.keys.unshift(e.keys.pop())},t.prototype.splitOffRightSide=function(){var e=this.keys.length>>1;return new t(this.keys.splice(e),this.values===undefVals?undefVals:this.values.splice(e))},t.prototype.forRange=function(e,t,r,i,n,o,s){var h,a,n=n._compare;if(t===e){if(!r)return o;if(a=(h=this.indexOf(e,-1,n))+1,h<0)return o}else h=this.indexOf(e,0,n),(a=this.indexOf(t,-1,n))<0?a=~a:!0===r&&a++;var u=this.keys,l=this.values;if(void 0!==s)for(var p=h;p<a;p++){var f=u[p],c=s(f,l[p],o++);if(void 0!==c){if(!0===i){if(f!==u[p]||!0===this.isShared)throw new Error("BTree illegally changed or cloned in editRange");c.delete?(this.keys.splice(p,1),this.values!==undefVals&&this.values.splice(p,1),p--,a--):c.hasOwnProperty("value")&&(l[p]=c.value)}if(void 0!==c.break)return c}}else o+=a-h;return o},t.prototype.mergeSibling=function(e,t){if(this.keys.push.apply(this.keys,e.keys),this.values===undefVals){if(e.values===undefVals)return;this.values=this.values.slice(0,this.keys.length)}this.values.push.apply(this.values,e.reifyValues())},t}(),BNodeInternal=function(o){function i(e,t,r){var i=this;if(!r){r=[];for(var n=0;n<e.length;n++)r[n]=e[n].maxKey()}return(i=o.call(this,r)||this).children=e,i._size=t,i}return __extends(i,o),i.prototype.clone=function(){for(var e=this.children.slice(0),t=0;t<e.length;t++)e[t].isShared=!0;return new i(e,this._size,this.keys.slice(0))},i.prototype.size=function(){return this._size},i.prototype.greedyClone=function(e){if(this.isShared&&!e)return this;for(var t=new i(this.children.slice(0),this._size,this.keys.slice(0)),r=0;r<t.children.length;r++)t.children[r]=t.children[r].greedyClone(e);return t},i.prototype.minKey=function(){return this.children[0].minKey()},i.prototype.minPair=function(e){return this.children[0].minPair(e)},i.prototype.maxPair=function(e){return this.children[this.children.length-1].maxPair(e)},i.prototype.get=function(e,t,r){var i=this.indexOf(e,0,r._compare),n=this.children;return i<n.length?n[i].get(e,t,r):void 0},i.prototype.getPairOrNextLower=function(e,t,r,i){var n=this.indexOf(e,0,t),o=this.children;if(n>=o.length)return this.maxPair(i);r=o[n].getPairOrNextLower(e,t,r,i);return void 0===r&&0<n?o[n-1].maxPair(i):r},i.prototype.getPairOrNextHigher=function(e,t,r,i){var n=this.indexOf(e,0,t),o=this.children,s=o.length;if(!(s<=n)){r=o[n].getPairOrNextHigher(e,t,r,i);return void 0===r&&n<s-1?o[n+1].minPair(i):r}},i.prototype.checkValid=function(e,t,r,i){var n=this.keys.length,o=this.children.length;check(n===o,"keys/children length mismatch: depth",e,"lengths",n,o,"baseIndex",r),check(1<n||0<e,"internal node has length",n,"at depth",e,"baseIndex",r);for(var s=0,h=this.children,a=this.keys,u=0,l=void 0,p=void 0,f=0;f<o;f++){var c=h[f],y=c.checkValid(e+1,t,r+s,i),d=y[0],v=y[1],y=y[2];check(d===c.size(),"cached size mismatch at depth",e,"index",f,"baseIndex",r),check(1===d||t._compare(v,y)<0,"child node keys not sorted at depth",e,"index",f,"baseIndex",r),void 0!==l&&void 0!==p&&i&&(check(!areOverlapping(l,p,v,y,t._compare),"children keys not sorted at depth",e,"index",f,"baseIndex",r,": ",p," !< ",v),check(t._compare(p,v)<0,"children keys not sorted at depth",e,"index",f,"baseIndex",r,": ",p," !< ",v)),l=v,p=y,s+=d,check((u+=c.keys.length)<=s,"wtf",r),check(0===f||h[f-1].constructor===c.constructor,"type mismatch, baseIndex:",r),c.maxKey()!=a[f]&&check(!1,"keys[",f,"] =",a[f],"is wrong, should be ",c.maxKey(),"at depth",e,"baseIndex",r),0===f||t._compare(a[f-1],a[f])<0||check(!1,"sort violation at depth",e,"index",f,"keys",a[f-1],a[f])}check(this._size===s,"internal node cached size mismatch at depth",e,"baseIndex",r,"cached",this._size,"actual",s);n=0===u;return(n||u>t.maxNodeSize*o)&&check(!1,n?"too few":"too many","children (",u,s,") at depth",e,"maxNodeSize:",t.maxNodeSize,"children.length:",o,"baseIndex:",r),[s,this.minKey(),this.maxKey()]},i.prototype.set=function(e,t,r,i){var n,o=this.children,s=i._maxNodeSize,h=i._compare,a=Math.min(this.indexOf(e,0,h),o.length-1),u=o[a];u.isShared&&(o[a]=u=u.clone()),u.keys.length>=s&&(0<a&&(n=o[a-1]).keys.length<s&&h(u.keys[0],e)<0?(n.isShared&&(o[a-1]=n=n.clone()),n.takeFromRight(u),this.keys[a-1]=n.maxKey()):void 0!==(n=o[a+1])&&n.keys.length<s&&h(u.maxKey(),e)<0&&(n.isShared&&(o[a+1]=n=n.clone()),n.takeFromLeft(u),this.keys[a]=o[a].maxKey()));o=u.size(),i=u.set(e,t,r,i);if(this._size+=u.size()-o,!1===i)return!1;if(this.keys[a]=u.maxKey(),!0===i)return!0;if(this.keys.length<s)return this.insert(a+1,i),!0;u=this.splitOffRightSide(),s=this;return 0<h(i.maxKey(),this.maxKey())&&(s=u,a-=this.keys.length),s.insert(a+1,i),u},i.prototype.insert=function(e,t){this.children.splice(e,0,t),this.keys.splice(e,0,t.maxKey()),this._size+=t.size()},i.prototype.splitOffRightSide=function(){var e=this.children.length>>1,t=this.children.splice(e),r=this.keys.splice(e),e=this._size;return this._size=sumChildSizes(this.children),new i(t,e-this._size,r)},i.prototype.splitOffLeftSide=function(){var e=this.children.length>>1,t=this.children.splice(0,e),r=this.keys.splice(0,e),e=this._size;return this._size=sumChildSizes(this.children),new i(t,e-this._size,r)},i.prototype.takeFromRight=function(e){var t=e;this.keys.push(e.keys.shift());e=t.children.shift();this.children.push(e);e=e.size();t._size-=e,this._size+=e},i.prototype.takeFromLeft=function(e){var t=e,r=t.children.pop();this.keys.unshift(e.keys.pop()),this.children.unshift(r);r=r.size();t._size-=r,this._size+=r},i.prototype.forRange=function(e,t,r,i,n,o,s){var h=n._compare,a=this.keys,u=this.children,l=this.indexOf(e,0,h),p=l,f=Math.min(t===e?l:this.indexOf(t,0,h),a.length-1);if(i){if(p<=f)try{for(;p<=f;p++){var c=u[p];c.isShared&&(u[p]=c=c.clone());var y=c.size(),d=c.forRange(e,t,r,i,n,o,s);if(a[p]=c.maxKey(),this._size+=c.size()-y,"number"!=typeof d)return d;o=d}}finally{var v=n._maxNodeSize>>1;for(0<l&&l--,p=f;l<=p;p--)u[p].keys.length<=v&&(0!==u[p].keys.length?this.tryMerge(p,n._maxNodeSize):(a.splice(p,1),check(0===u.splice(p,1)[0].size(),"emptiness cleanup")));0!==u.length&&0===u[0].keys.length&&check(!1,"emptiness bug")}}else for(;p<=f;p++){var g=u[p].forRange(e,t,r,i,n,o,s);if("number"!=typeof g)return g;o=g}return o},i.prototype.tryMerge=function(e,t){var r=this.children;return 0<=e&&e+1<r.length&&r[e].keys.length+r[e+1].keys.length<=t&&(r[e].isShared&&(r[e]=r[e].clone()),r[e].mergeSibling(r[e+1],t),r.splice(e+1,1),this.keys.splice(e+1,1),this.keys[e]=r[e].maxKey(),!0)},i.prototype.mergeSibling=function(e,t){var r=this.keys.length;this.keys.push.apply(this.keys,e.keys);var i=e.children;if(this.children.push.apply(this.children,i),this._size+=e.size(),e.isShared&&!this.isShared)for(var n=0;n<i.length;n++)i[n].isShared=!0;this.tryMerge(r-1,t)},i}(exports.BNode=BNode);exports.BNodeInternal=BNodeInternal;var undefVals=[];function sumChildSizes(e){for(var t=0,r=0;r<e.length;r++)t+=e[r].size();return t}function areOverlapping(e,t,r,i,n){return n(e,i)<=0&&0<=n(t,r)}exports.sumChildSizes=sumChildSizes,exports.areOverlapping=areOverlapping;var Delete={delete:!0},DeleteRange=function(){return Delete},Break={break:!0},EmptyLeaf=function(){var e=new BNode;return e.isShared=!0,e}(),EmptyArray=[],ReusedArray=[];function check(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(!e)throw t.unshift("B+ tree"),new Error(t.join(" "))}exports.check=check,exports.EmptyBTree=function(){var e=new BTree;return e.freeze(),e}();