Files

8 lines
19 KiB
JavaScript

/**
* Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.37.0.
* Original file: ./orama/dist/browser/trees.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
function t(t,e,n){const r=function(t,e,n){if(n<0)return-1;if(t===e)return 0;const r=t.length,o=e.length;if(0===r)return o<=n?o:-1;if(0===o)return r<=n?r:-1;const s=Math.abs(r-o);if(t.startsWith(e))return s<=n?s:-1;if(e.startsWith(t))return 0;if(s>n)return-1;const i=[];for(let t=0;t<=r;t++){i[t]=[t];for(let e=1;e<=o;e++)i[t][e]=0===t?e:0}for(let s=1;s<=r;s++){let r=1/0;for(let n=1;n<=o;n++)t[s-1]===e[n-1]?i[s][n]=i[s-1][n-1]:i[s][n]=Math.min(i[s-1][n]+1,i[s][n-1]+1,i[s-1][n-1]+1),r=Math.min(r,i[s][n]);if(r>n)return-1}return i[r][o]<=n?i[r][o]:-1}(t,e,n);return{distance:r,isBounded:r>=0}}function e(t,e){return void 0===Object.hasOwn?Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0:Object.hasOwn(t,e)?t[e]:void 0}Object.keys({arabic:"ar",armenian:"am",bulgarian:"bg",danish:"dk",dutch:"nl",english:"en",finnish:"fi",french:"fr",german:"de",greek:"gr",hungarian:"hu",indian:"in",indonesian:"id",irish:"ie",italian:"it",lithuanian:"lt",nepali:"np",norwegian:"no",portuguese:"pt",romanian:"ro",russian:"ru",serbian:"rs",slovenian:"ru",spanish:"es",swedish:"se",tamil:"ta",turkish:"tr",ukrainian:"uk",sanskrit:"sk"}).join("\n - "),Date.now().toString().slice(5),BigInt(1e3),BigInt(1e6),BigInt(1e9);const n="union"in new Set;function r(t,e){return n?t?t.union(e):e:t?new Set([...t,...e]):new Set(e)}class o{k;s;c=new Map;d=new Set;e;w="";constructor(t,e,n){this.k=t,this.s=e,this.e=n}updateParent(t){this.w=t.w+this.s}addDocument(t){this.d.add(t)}removeDocument(t){return this.d.delete(t)}findAllWords(n,r,o,s){const i=[this];for(;i.length>0;){const l=i.pop();if(l.e){const{w:i,d:a}=l;if(o&&i!==r)continue;if(null!==e(n,i))if(s){if(!(Math.abs(r.length-i.length)<=s&&t(r,i,s).isBounded))continue;n[i]=[]}else n[i]=[];if(null!=e(n,i)&&a.size>0){const t=n[i];for(const e of a)t.includes(e)||t.push(e)}}l.c.size>0&&i.push(...l.c.values())}return n}insert(t,e){let n=this,r=0;const s=t.length;for(;r<s;){const i=t[r],l=n.c.get(i);if(l){const i=l.s,a=i.length;let h=0;for(;h<a&&r+h<s&&i[h]===t[r+h];)h++;if(h===a){if(n=l,r+=h,r===s)return l.e||(l.e=!0),void l.addDocument(e);continue}const u=i.slice(0,h),c=i.slice(h),f=t.slice(r+h),d=new o(u[0],u,!1);if(n.c.set(u[0],d),d.updateParent(n),l.s=c,l.k=c[0],d.c.set(c[0],l),l.updateParent(d),f){const t=new o(f[0],f,!0);t.addDocument(e),d.c.set(f[0],t),t.updateParent(d)}else d.e=!0,d.addDocument(e);return}{const s=new o(i,t.slice(r),!0);return s.addDocument(e),n.c.set(i,s),void s.updateParent(n)}}n.e||(n.e=!0),n.addDocument(e)}_findLevenshtein(n,r,o,s,i){const l=[{node:this,index:r,tolerance:o}];for(;l.length>0;){const{node:r,index:o,tolerance:a}=l.pop();if(r.w.startsWith(n)){r.findAllWords(i,n,!1,0);continue}if(a<0)continue;if(r.e){const{w:o,d:l}=r;if(o&&(t(n,o,s).isBounded&&(i[o]=[]),void 0!==e(i,o)&&l.size>0)){const t=new Set(i[o]);for(const e of l)t.add(e);i[o]=Array.from(t)}}if(o>=n.length)continue;const h=n[o];if(r.c.has(h)){const t=r.c.get(h);l.push({node:t,index:o+1,tolerance:a})}l.push({node:r,index:o+1,tolerance:a-1});for(const[t,e]of r.c)l.push({node:e,index:o,tolerance:a-1}),t!==h&&l.push({node:e,index:o+1,tolerance:a-1})}}find(t){const{term:e,exact:n,tolerance:r}=t;if(r&&!n){const t={};return this._findLevenshtein(e,0,r,r,t),t}{let t=this,o=0;const s=e.length;for(;o<s;){const i=e[o],l=t.c.get(i);if(!l)return{};{const i=l.s,a=i.length;let h=0;for(;h<a&&o+h<s&&i[h]===e[o+h];)h++;if(h!==a){if(o+h===s){if(n)return{};{const t={};return l.findAllWords(t,e,n,r),t}}return{}}t=l,o+=h}}const i={};return t.findAllWords(i,e,n,r),i}}contains(t){let e=this,n=0;const r=t.length;for(;n<r;){const o=t[n],s=e.c.get(o);if(!s)return!1;{const o=s.s,i=o.length;let l=0;for(;l<i&&n+l<r&&o[l]===t[n+l];)l++;if(l<i)return!1;n+=i,e=s}}return!0}removeWord(t){if(!t)return!1;let e=this;const n=t.length,r=[];for(let o=0;o<n;o++){const n=t[o];if(!e.c.has(n))return!1;{const t=e.c.get(n);r.push({parent:e,character:n}),o+=t.s.length-1,e=t}}for(e.d.clear(),e.e=!1;r.length>0&&0===e.c.size&&!e.e&&0===e.d.size;){const{parent:t,character:n}=r.pop();t.c.delete(n),e=t}return!0}removeDocumentByWord(t,e,n=!0){if(!t)return!0;let r=this;const o=t.length;for(let s=0;s<o;s++){const o=t[s];if(!r.c.has(o))return!1;{const i=r.c.get(o);s+=i.s.length-1,r=i,n&&r.w!==t||r.removeDocument(e)}}return!0}static getCommonPrefix(t,e){const n=Math.min(t.length,e.length);let r=0;for(;r<n&&t.charCodeAt(r)===e.charCodeAt(r);)r++;return t.slice(0,r)}toJSON(){return{w:this.w,s:this.s,e:this.e,k:this.k,d:Array.from(this.d),c:Array.from(this.c?.entries())?.map((([t,e])=>[t,e.toJSON()]))}}static fromJSON(t){const e=new o(t.k,t.s,t.e);return e.w=t.w,e.d=new Set(t.d),e.c=new Map(t?.c?.map((([t,e])=>[t,o.fromJSON(e)]))),e}}class s extends o{constructor(){super("","",!1)}static fromJSON(t){const e=new s;return e.w=t.w,e.s=t.s,e.e=t.e,e.k=t.k,e.d=new Set(t.d),e.c=new Map(t.c?.map((([t,e])=>[t,o.fromJSON(e)]))),e}toJSON(){return super.toJSON()}}var i=Object.freeze({__proto__:null,RadixNode:o,RadixTree:s});class l{k;v;l=null;r=null;h=1;constructor(t,e){this.k=t,this.v=new Set(e)}updateHeight(){this.h=Math.max(l.getHeight(this.l),l.getHeight(this.r))+1}static getHeight(t){return t?t.h:0}getBalanceFactor(){return l.getHeight(this.l)-l.getHeight(this.r)}rotateLeft(){const t=this.r;return this.r=t.l,t.l=this,this.updateHeight(),t.updateHeight(),t}rotateRight(){const t=this.l;return this.l=t.r,t.r=this,this.updateHeight(),t.updateHeight(),t}toJSON(){return{k:this.k,v:Array.from(this.v),l:this.l?this.l.toJSON():null,r:this.r?this.r.toJSON():null,h:this.h}}static fromJSON(t){const e=new l(t.k,t.v);return e.l=t.l?l.fromJSON(t.l):null,e.r=t.r?l.fromJSON(t.r):null,e.h=t.h,e}}class a{root=null;insertCount=0;constructor(t,e){void 0!==t&&void 0!==e&&(this.root=new l(t,e))}insert(t,e,n=1e3){this.root=this.insertNode(this.root,t,e,n)}insertMultiple(t,e,n=1e3){for(const r of e)this.insert(t,r,n)}rebalance(){this.root&&(this.root=this.rebalanceNode(this.root))}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(t){const e=new a;return e.root=t.root?l.fromJSON(t.root):null,e.insertCount=t.insertCount||0,e}insertNode(t,e,n,r){if(null===t)return new l(e,[n]);const o=[];let s=t,i=null;for(;null!==s;)if(o.push({parent:i,node:s}),e<s.k){if(null===s.l){s.l=new l(e,[n]),o.push({parent:s,node:s.l});break}i=s,s=s.l}else{if(!(e>s.k))return s.v.add(n),t;if(null===s.r){s.r=new l(e,[n]),o.push({parent:s,node:s.r});break}i=s,s=s.r}let a=!1;this.insertCount++%r==0&&(a=!0);for(let e=o.length-1;e>=0;e--){const{parent:n,node:r}=o[e];if(r.updateHeight(),a){const e=this.rebalanceNode(r);n?n.l===r?n.l=e:n.r===r&&(n.r=e):t=e}}return t}rebalanceNode(t){const e=t.getBalanceFactor();if(e>1){if(t.l&&t.l.getBalanceFactor()>=0)return t.rotateRight();if(t.l)return t.l=t.l.rotateLeft(),t.rotateRight()}if(e<-1){if(t.r&&t.r.getBalanceFactor()<=0)return t.rotateLeft();if(t.r)return t.r=t.r.rotateRight(),t.rotateLeft()}return t}find(t){const e=this.findNodeByKey(t);return e?e.v:null}contains(t){return null!==this.find(t)}getSize(){let t=0;const e=[];let n=this.root;for(;n||e.length>0;){for(;n;)e.push(n),n=n.l;n=e.pop(),t++,n=n.r}return t}isBalanced(){if(!this.root)return!0;const t=[this.root];for(;t.length>0;){const e=t.pop(),n=e.getBalanceFactor();if(Math.abs(n)>1)return!1;e.l&&t.push(e.l),e.r&&t.push(e.r)}return!0}remove(t){this.root=this.removeNode(this.root,t)}removeDocument(t,e){const n=this.findNodeByKey(t);n&&(1===n.v.size?this.root=this.removeNode(this.root,t):n.v=new Set([...n.v.values()].filter((t=>t!==e))))}findNodeByKey(t){let e=this.root;for(;e;)if(t<e.k)e=e.l;else{if(!(t>e.k))return e;e=e.r}return null}removeNode(t,e){if(null===t)return null;const n=[];let r=t;for(;null!==r&&r.k!==e;)n.push(r),r=e<r.k?r.l:r.r;if(null===r)return t;if(null===r.l||null===r.r){const e=r.l?r.l:r.r;if(0===n.length)t=e;else{const t=n[n.length-1];t.l===r?t.l=e:t.r=e}}else{let t=r,e=r.r;for(;null!==e.l;)t=e,e=e.l;r.k=e.k,r.v=e.v,t.l===e?t.l=e.r:t.r=e.r,r=t}n.push(r);for(let e=n.length-1;e>=0;e--){const r=n[e];r.updateHeight();const o=this.rebalanceNode(r);if(e>0){const t=n[e-1];t.l===r?t.l=o:t.r===r&&(t.r=o)}else t=o}return t}rangeSearch(t,e){let n=new Set;const o=[];let s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.l;if(s=o.pop(),s.k>=t&&s.k<=e&&(n=r(n,s.v)),s.k>e)break;s=s.r}return n}greaterThan(t,e=!1){let n=new Set;const o=[];let s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.r;if(s=o.pop(),e&&s.k>=t||!e&&s.k>t)n=r(n,s.v);else if(s.k<=t)break;s=s.l}return n}lessThan(t,e=!1){let n=new Set;const o=[];let s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.l;if(s=o.pop(),e&&s.k<=t||!e&&s.k<t)n=r(n,s.v);else if(s.k>t)break;s=s.r}return n}}var h=Object.freeze({__proto__:null,AVLNode:l,AVLTree:a});class u{k;v;n;l;r;p;constructor(t,e,n){this.k=t,this.v=e,this.n=n,this.l=null,this.r=null,this.p=null}}class c{root;constructor(){this.root=null}randomRank(){const t=Math.random();return Math.floor(Math.log(1-t)/Math.log(.5))}insert(t,e){const n=new u(t,e,this.randomRank());if(!this.root)return void(this.root=n);let r=this.root,o=null;for(;null!=r;)if(o=r,t<r.k)r=r.l;else{if(!(t>r.k))return void(r.v=e);r=r.r}n.p=o,null!=o&&(t<o.k?o.l=n:o.r=n),this.bubbleUp(n)}bubbleUp(t){for(;null!=t.p&&t.p.n<t.n;)t===t.p.l?this.rotateRight(t.p):this.rotateLeft(t.p);null==t.p&&(this.root=t)}rotateLeft(t){const e=t.r;t.r=e.l,null!=e.l&&(e.l.p=t),e.l=t,e.p=t.p,null==t.p?this.root=e:t===t.p.l?t.p.l=e:t.p.r=e,t.p=e}rotateRight(t){const e=t.l;t.l=e.r,null!=e.r&&(e.r.p=t),e.r=t,e.p=t.p,null==t.p?this.root=e:t===t.p.l?t.p.l=e:t.p.r=e,t.p=e}remove(t){const e=this.getNodeByKey(t);null!=e&&this.removeNode(e)}removeNode(t){for(;null!=t.l||null!=t.r;)null==t.l?this.rotateLeft(t):null==t.r||t.l.n>t.r.n?this.rotateRight(t):this.rotateLeft(t);null!=t.p?t===t.p.l?t.p.l=null:t.p.r=null:this.root=null}find(t){const e=this.getNodeByKey(t);return e?e.v:null}contains(t){return null!=this.getNodeByKey(t)}getNodeByKey(t){let e=this.root;for(;null!==e;){if(e.k===t)return e;e=t<e.k?e.l:e.r}return null}rangeSearch(t,e){const n=[];return this.inOrderTraversal(this.root,(r=>{r.k>=t&&r.k<=e&&n.push(r.v)})),n}greaterThan(t){const e=[];return this.inOrderTraversal(this.root,(n=>{n.k>t&&e.push(n.v)})),e}lessThan(t){const e=[];return this.inOrderTraversal(this.root,(n=>{n.k<t&&e.push(n.v)})),e}getSize(){let t=0;return this.inOrderTraversal(this.root,(()=>{t++})),t}inOrderTraversal(t,e){null!=t&&(this.inOrderTraversal(t.l,e),e(t),this.inOrderTraversal(t.r,e))}removeDocument(t,e){const n=this.getNodeByKey(e);if(null!=n)if(Array.isArray(n.v)){const r=n.v.indexOf(t);-1!==r&&(n.v.splice(r,1),0===n.v.length&&this.remove(e))}else n.v===t&&this.remove(e)}toJSON(){return{root:this.nodeToJSON(this.root)}}nodeToJSON(t){return null==t?null:{k:t.k,v:t.v,n:t.n,l:this.nodeToJSON(t.l),r:this.nodeToJSON(t.r)}}static fromJSON(t){const e=new c;return e.root=e.nodeFromJSON(t.root,null),e}nodeFromJSON(t,e){if(null==t)return null;const n=new u(t.k,t.v,t.n);return n.p=e,n.l=this.nodeFromJSON(t.l,n),n.r=this.nodeFromJSON(t.r,n),n}}var f=Object.freeze({__proto__:null,ZipNode:u,ZipTree:c});class d{point;docIDs;left;right;parent;constructor(t,e){this.point=t,this.docIDs=new Set(e),this.left=null,this.right=null,this.parent=null}toJSON(){return{point:this.point,docIDs:Array.from(this.docIDs),left:this.left?this.left.toJSON():null,right:this.right?this.right.toJSON():null}}static fromJSON(t,e=null){const n=new d(t.point,t.docIDs);return n.parent=e,t.left&&(n.left=d.fromJSON(t.left,n)),t.right&&(n.right=d.fromJSON(t.right,n)),n}}class p{root;nodeMap;constructor(){this.root=null,this.nodeMap=new Map}getPointKey(t){return`${t.lon},${t.lat}`}insert(t,e){const n=this.getPointKey(t),r=this.nodeMap.get(n);if(r)return void e.forEach((t=>r.docIDs.add(t)));const o=new d(t,e);if(this.nodeMap.set(n,o),null==this.root)return void(this.root=o);let s=this.root,i=0;for(;;){if(0===i%2)if(t.lon<s.point.lon){if(null==s.left)return s.left=o,void(o.parent=s);s=s.left}else{if(null==s.right)return s.right=o,void(o.parent=s);s=s.right}else if(t.lat<s.point.lat){if(null==s.left)return s.left=o,void(o.parent=s);s=s.left}else{if(null==s.right)return s.right=o,void(o.parent=s);s=s.right}i++}}contains(t){const e=this.getPointKey(t);return this.nodeMap.has(e)}getDocIDsByCoordinates(t){const e=this.getPointKey(t),n=this.nodeMap.get(e);return n?Array.from(n.docIDs):null}removeDocByID(t,e){const n=this.getPointKey(t),r=this.nodeMap.get(n);r&&(r.docIDs.delete(e),0===r.docIDs.size&&(this.nodeMap.delete(n),this.deleteNode(r)))}deleteNode(t){const e=t.parent,n=t.left?t.left:t.right;n&&(n.parent=e),e?e.left===t?e.left=n:e.right===t&&(e.right=n):(this.root=n,this.root&&(this.root.parent=null))}searchByRadius(t,e,n=!0,r="asc",o=!1){const s=o?p.vincentyDistance:p.haversineDistance,i=[{node:this.root,depth:0}],l=[];for(;i.length>0;){const{node:r,depth:o}=i.pop();if(null==r)continue;const a=s(t,r.point);(n?a<=e:a>e)&&l.push({point:r.point,docIDs:Array.from(r.docIDs)}),null!=r.left&&i.push({node:r.left,depth:o+1}),null!=r.right&&i.push({node:r.right,depth:o+1})}return r&&l.sort(((e,n)=>{const o=s(t,e.point),i=s(t,n.point);return"asc"===r.toLowerCase()?o-i:i-o})),l}searchByPolygon(t,e=!0,n=null,r=!1){const o=[{node:this.root,depth:0}],s=[];for(;o.length>0;){const{node:n,depth:r}=o.pop();if(null==n)continue;null!=n.left&&o.push({node:n.left,depth:r+1}),null!=n.right&&o.push({node:n.right,depth:r+1});const i=p.isPointInPolygon(t,n.point);(i&&e||!i&&!e)&&s.push({point:n.point,docIDs:Array.from(n.docIDs)})}const i=p.calculatePolygonCentroid(t);if(n){const t=r?p.vincentyDistance:p.haversineDistance;s.sort(((e,r)=>{const o=t(i,e.point),s=t(i,r.point);return"asc"===n.toLowerCase()?o-s:s-o}))}return s}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(t){const e=new p;return t.root&&(e.root=d.fromJSON(t.root),e.buildNodeMap(e.root)),e}buildNodeMap(t){if(null==t)return;const e=this.getPointKey(t.point);this.nodeMap.set(e,t),t.left&&this.buildNodeMap(t.left),t.right&&this.buildNodeMap(t.right)}static calculatePolygonCentroid(t){let e=0,n=0,r=0;const o=t.length;for(let s=0,i=o-1;s<o;i=s++){const o=t[s].lon,l=t[s].lat,a=t[i].lon,h=t[i].lat,u=o*h-a*l;e+=u,n+=(o+a)*u,r+=(l+h)*u}e/=2;const s=6*e;return n/=s,r/=s,{lon:n,lat:r}}static isPointInPolygon(t,e){let n=!1;const r=e.lon,o=e.lat,s=t.length;for(let e=0,i=s-1;e<s;i=e++){const s=t[e].lon,l=t[e].lat,a=t[i].lon,h=t[i].lat;l>o!=h>o&&r<(a-s)*(o-l)/(h-l)+s&&(n=!n)}return n}static haversineDistance(t,e){const n=Math.PI/180,r=t.lat*n,o=e.lat*n,s=(e.lat-t.lat)*n,i=(e.lon-t.lon)*n,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(r)*Math.cos(o)*Math.sin(i/2)*Math.sin(i/2);return 6371e3*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))}static vincentyDistance(t,e){const n=6378137,r=1/298.257223563,o=(1-r)*n,s=Math.PI/180,i=t.lat*s,l=e.lat*s,a=(e.lon-t.lon)*s,h=Math.atan((1-r)*Math.tan(i)),u=Math.atan((1-r)*Math.tan(l)),c=Math.sin(h),f=Math.cos(h),d=Math.sin(u),p=Math.cos(u);let g,m,v,w,S,N,O,y=a,b=1e3;do{const t=Math.sin(y),e=Math.cos(y);if(m=Math.sqrt(p*t*(p*t)+(f*d-c*p*e)*(f*d-c*p*e)),0===m)return 0;v=c*d+f*p*e,w=Math.atan2(m,v),S=f*p*t/m,N=1-S*S,O=v-2*c*d/N,isNaN(O)&&(O=0);const n=r/16*N*(4+r*(4-3*N));g=y,y=a+(1-n)*r*S*(w+n*m*(O+n*v*(2*O*O-1)))}while(Math.abs(y-g)>1e-12&&--b>0);if(0===b)return NaN;const k=N*(n*n-o*o)/(o*o),D=k/1024*(256+k*(k*(74-47*k)-128));return o*(1+k/16384*(4096+k*(k*(320-175*k)-768)))*(w-D*m*(O+D/4*(v*(2*O*O-1)-D/6*O*(4*m*m-3)*(4*O*O-3))))}}var g=Object.freeze({__proto__:null,BKDTree:p});class m{numberToDocumentId;constructor(){this.numberToDocumentId=new Map}insert(t,e){this.numberToDocumentId.has(t)?this.numberToDocumentId.get(t).add(e):this.numberToDocumentId.set(t,new Set([e]))}find(t){const e=this.numberToDocumentId.get(t);return e?Array.from(e):null}remove(t){this.numberToDocumentId.delete(t)}removeDocument(t,e){const n=this.numberToDocumentId.get(e);n&&(n.delete(t),0===n.size&&this.numberToDocumentId.delete(e))}contains(t){return this.numberToDocumentId.has(t)}getSize(){let t=0;for(const e of this.numberToDocumentId.values())t+=e.size;return t}filter(t){const e=Object.keys(t);if(1!==e.length)throw new Error("Invalid operation");const n=e[0];switch(n){case"eq":{const e=t[n],r=this.numberToDocumentId.get(e);return r?Array.from(r):[]}case"in":{const e=t[n],r=new Set;for(const t of e){const e=this.numberToDocumentId.get(t);if(e)for(const t of e)r.add(t)}return Array.from(r)}case"nin":{const e=new Set(t[n]),r=new Set;for(const[t,n]of this.numberToDocumentId.entries())if(!e.has(t))for(const t of n)r.add(t);return Array.from(r)}default:throw new Error("Invalid operation")}}filterArr(t){const e=Object.keys(t);if(1!==e.length)throw new Error("Invalid operation");const n=e[0];switch(n){case"containsAll":{const e=t[n].map((t=>this.numberToDocumentId.get(t)??new Set));if(0===e.length)return[];const r=e.reduce(((t,e)=>new Set([...t].filter((t=>e.has(t))))));return Array.from(r)}case"containsAny":{const e=t[n].map((t=>this.numberToDocumentId.get(t)??new Set));if(0===e.length)return[];const r=e.reduce(((t,e)=>new Set([...t,...e])));return Array.from(r)}default:throw new Error("Invalid operation")}}static fromJSON(t){if(!t.numberToDocumentId)throw new Error("Invalid Flat Tree JSON");const e=new m;for(const[n,r]of t.numberToDocumentId)e.numberToDocumentId.set(n,new Set(r));return e}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map((([t,e])=>[t,Array.from(e)]))}}}var v=Object.freeze({__proto__:null,FlatTree:m});class w{true;false;constructor(){this.true=new Set,this.false=new Set}insert(t,e){e?this.true.add(t):this.false.add(t)}delete(t,e){e?this.true.delete(t):this.false.delete(t)}getSize(){return this.true.size+this.false.size}toJSON(){return{true:Array.from(this.true),false:Array.from(this.false)}}static fromJSON(t){const e=new w;return e.true=new Set(t.true),e.false=new Set(t.false),e}}var S=Object.freeze({__proto__:null,BoolNode:w});class N{size;vectors=new Map;constructor(t){this.size=t}add(t,e){e instanceof Float32Array||(e=new Float32Array(e));const n=O(e,this.size);this.vectors.set(t,[n,e])}remove(t){this.vectors.delete(t)}find(t,e,n){t instanceof Float32Array||(t=new Float32Array(t));return y(t,n,this.vectors,this.size,e)}toJSON(){const t=[];for(const[e,[n,r]]of this.vectors)t.push([e,[n,Array.from(r)]]);return{size:this.size,vectors:t}}static fromJSON(t){const e=t,n=new N(e.size);for(const[t,[r,o]]of e.vectors)n.vectors.set(t,[r,new Float32Array(o)]);return n}}function O(t,e){let n=0;for(let r=0;r<e;r++)n+=t[r]*t[r];return Math.sqrt(n)}function y(t,e,n,r,o){const s=O(t,r),i=[],l=e||n.keys();for(const e of l){const l=n.get(e);if(!l)continue;const a=l[0],h=l[1];let u=0;for(let e=0;e<r;e++)u+=t[e]*h[e];const c=u/(s*a);c>=o&&i.push([e,c])}return i}var b=Object.freeze({__proto__:null,DEFAULT_SIMILARITY:.8,VectorIndex:N,getMagnitude:O,findSimilarVectors:y});export{h as avl,g as bkd,S as bool,v as flat,i as radix,b as vector,f as zip};export default null;
//# sourceMappingURL=/sm/afde1c2b1a5de8546b085aacd0b6b541543a2886576d532cf3833fe1b168d571.map