// https://github.com/vasturiano/d3-binarytree v0.2.0 Copyright 2021 Vasco Asturiano !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";function r(t,r,e){if(isNaN(r))return t;var n,i,o,s,h,u,a=t._root,f={data:e},l=t._x0,x=t._x1;if(!a)return t._root=f,t;for(;a.length;)if((s=r>=(i=(l+x)/2))?l=i:x=i,n=a,!(a=a[h=+s]))return n[h]=f,t;if(r===(o=+t._x.call(null,a.data)))return f.next=a,n?n[h]=f:t._root=f,t;do{n=n?n[h]=new Array(2):t._root=new Array(2),(s=r>=(i=(l+x)/2))?l=i:x=i}while((h=+s)==(u=+(o>=i)));return n[u]=a,n[h]=f,t}function e(t,r,e){this.node=t,this.x0=r,this.x1=e}function n(t){return t[0]}function i(t,r){var e=new o(null==r?n:r,NaN,NaN);return null==t?e:e.addAll(t)}function o(t,r,e){this._x=t,this._x0=r,this._x1=e,this._root=void 0}function s(t){for(var r={data:t.data},e=r;t=t.next;)e=e.next={data:t.data};return r}var h=i.prototype=o.prototype;h.copy=function(){var t,r,e=new o(this._x,this._x0,this._x1),n=this._root;if(!n)return e;if(!n.length)return e._root=s(n),e;for(t=[{source:n,target:e._root=new Array(2)}];n=t.pop();)for(var i=0;i<2;++i)(r=n.source[i])&&(r.length?t.push({source:r,target:n.target[i]=new Array(2)}):n.target[i]=s(r));return e},h.add=function(t){var e=+this._x.call(null,t);return r(this.cover(e),e,t)},h.addAll=function(t){var e,n,i=t.length,o=new Array(i),s=1/0,h=-1/0;for(e=0;eh&&(h=n));if(s>h)return this;for(this.cover(s).cover(h),e=0;et||t>=e;)switch(i=+(ta||(o=s.x1)=x))&&(s=f[f.length-1],f[f.length-1]=f[f.length-1-h],f[f.length-1-h]=s)}else{var _=Math.abs(t-+this._x.call(null,l.data));_=(s=(l+x)/2))?l=s:x=s,r=f,!(f=f[u=+h]))return this;if(!f.length)break;r[u+1&1]&&(e=r,a=u)}for(;f.data!==t;)if(n=f,!(f=f.next))return this;return(i=f.next)&&delete f.next,n?(i?n.next=i:delete n.next,this):r?(i?r[u]=i:delete r[u],(f=r[0]||r[1])&&f===(r[1]||r[0])&&!f.length&&(e?e[a]=f:this._root=f),this):(this._root=i,this)},h.removeAll=function(t){for(var r=0,e=t.length;r