@graphty/cytoscape-extensions 0.0.28 → 0.0.29

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.
Files changed (72) hide show
  1. package/dist/algorithm-options.d.ts +5 -0
  2. package/dist/algorithm-options.d.ts.map +1 -0
  3. package/dist/algorithm-options.js +285 -0
  4. package/dist/algorithm-options.js.map +1 -0
  5. package/dist/algorithms.d.ts +489 -0
  6. package/dist/algorithms.d.ts.map +1 -0
  7. package/dist/algorithms.js +1184 -0
  8. package/dist/algorithms.js.map +1 -0
  9. package/dist/cdn/chunks/elements-DkrLtNP8.js +1 -0
  10. package/dist/cdn/chunks/gpu-platform-browser-VBah74fl.js +2825 -0
  11. package/dist/cdn/chunks/index-C4RZkds_.js +10 -0
  12. package/dist/cdn/chunks/index-CAhmhhmb.js +1 -0
  13. package/dist/cdn/chunks/io-Da5POp5D.js +268 -0
  14. package/dist/cdn/chunks/preload-helper-DEpZAvig.js +1 -0
  15. package/dist/cdn/chunks/samples-BkLzaDJ3.js +1 -0
  16. package/dist/cdn/chunks/sigv4-EokFic1V-CWJiFeEe.js +3 -0
  17. package/dist/cdn/chunks/sources-cypher-BGGD4kJ9.js +5 -0
  18. package/dist/cdn/chunks/sources-ndex-CxnPOYff.js +1 -0
  19. package/dist/cdn/chunks/sources-rest-BPNV8mX-.js +1 -0
  20. package/dist/cdn/chunks/sources-sparql-BiqRQuHD.js +5 -0
  21. package/dist/cdn/cytoscape-extensions.js +1 -0
  22. package/dist/cdn/io.js +1 -0
  23. package/dist/cytoscape-extensions.bundle.js +2825 -0
  24. package/dist/elements.d.ts +69 -0
  25. package/dist/elements.d.ts.map +1 -0
  26. package/dist/elements.js +343 -0
  27. package/dist/elements.js.map +1 -0
  28. package/dist/gpu-platform-browser.d.ts +11 -0
  29. package/dist/gpu-platform-browser.d.ts.map +1 -0
  30. package/dist/gpu-platform-browser.js +22 -0
  31. package/dist/gpu-platform-browser.js.map +1 -0
  32. package/dist/gpu-platform-node.d.ts +15 -0
  33. package/dist/gpu-platform-node.d.ts.map +1 -0
  34. package/dist/gpu-platform-node.js +27 -0
  35. package/dist/gpu-platform-node.js.map +1 -0
  36. package/dist/gpu.d.ts +149 -0
  37. package/dist/gpu.d.ts.map +1 -0
  38. package/dist/gpu.js +312 -0
  39. package/dist/gpu.js.map +1 -0
  40. package/dist/graph-data.d.ts +101 -0
  41. package/dist/graph-data.d.ts.map +1 -0
  42. package/dist/graph-data.js +147 -0
  43. package/dist/graph-data.js.map +1 -0
  44. package/dist/index.d.ts +36 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +48 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/io.d.ts +111 -0
  49. package/dist/io.d.ts.map +1 -0
  50. package/dist/io.js +258 -0
  51. package/dist/io.js.map +1 -0
  52. package/dist/layouts.d.ts +207 -0
  53. package/dist/layouts.d.ts.map +1 -0
  54. package/dist/layouts.js +615 -0
  55. package/dist/layouts.js.map +1 -0
  56. package/dist/lazy.d.ts +21 -0
  57. package/dist/lazy.d.ts.map +1 -0
  58. package/dist/lazy.js +32 -0
  59. package/dist/lazy.js.map +1 -0
  60. package/dist/samples.d.ts +115 -0
  61. package/dist/samples.d.ts.map +1 -0
  62. package/dist/samples.js +237 -0
  63. package/dist/samples.js.map +1 -0
  64. package/dist/snapshot.d.ts +81 -0
  65. package/dist/snapshot.d.ts.map +1 -0
  66. package/dist/snapshot.js +225 -0
  67. package/dist/snapshot.js.map +1 -0
  68. package/dist/webgpu-provider.d.ts +25 -0
  69. package/dist/webgpu-provider.d.ts.map +1 -0
  70. package/dist/webgpu-provider.js +53 -0
  71. package/dist/webgpu-provider.js.map +1 -0
  72. package/package.json +13 -9
@@ -0,0 +1 @@
1
+ const nf=4294967295,rf=4294967294;const es=Symbol.for("@graphty/graph-format/snapshot"),R=256,ts=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,Ne=1,ns=0,an="graphty-snapshot",dn=[71,83,78,80],fn=16909060,_o=Object.freeze({});class f extends Error{constructor(e,t,r){super(t),this.name="GraphFormatError",this.code=e,this.details=r===void 0?_o:Object.freeze({...r})}}const Fe=new WeakMap;function M(n){Fe.set(n,(Fe.get(n)??0)+1)}function Ee(n){Fe.set(n,Math.max(Fe.get(n)??0,1)+1)}function Do(n){return Fe.get(n)??0}function Ye(n){return(Fe.get(n)??0)>1}const To=32;let ir=null,cr=null;function rs(){return ir??=new TextDecoder("utf-8",{ignoreBOM:!0}),ir}function ko(){return cr??=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),cr}function vo(n){let e=0;const t=n.length;for(let r=0;r<t;r++){const s=n.charCodeAt(r);if(s<128)e+=1;else if(s<2048)e+=2;else if(s>=55296&&s<=56319&&r+1<t){const o=n.charCodeAt(r+1);o>=56320&&o<=57343?(e+=4,r++):e+=3}else e+=3}return e}function xo(n,e,t){let r=t;const s=n.length;for(let o=0;o<s;o++){let i=n.charCodeAt(o);if(i<128){e[r++]=i;continue}if(i<2048){e[r++]=192|i>>6,e[r++]=128|i&63;continue}if(i>=55296&&i<=57343){const c=So(n,o,i);if(c>=0){o++,e[r++]=240|c>>18,e[r++]=128|c>>12&63,e[r++]=128|c>>6&63,e[r++]=128|c&63;continue}i=65533}e[r++]=224|i>>12,e[r++]=128|i>>6&63,e[r++]=128|i&63}return r}function So(n,e,t){if(t>56319||e+1>=n.length)return-1;const r=n.charCodeAt(e+1);return r<56320||r>57343?-1:65536+(t-55296<<10)+(r-56320)}const Uo=13;function nt(n){return n.length<Uo?n:` ${n}`.slice(1)}function ss(n){const e=n.length;for(let t=0;t<e;t++){const r=n.charCodeAt(t);if(r<55296||r>57343)continue;if(r>56319||t+1>=e)return!0;const s=n.charCodeAt(t+1);if(s<56320||s>57343)return!0;t++}return!1}function os(n,e,t){const r=t-e;if(r===0)return"";if(r<=To){let s="",o=e;for(;o<t;o++){const i=n[o];if(i>=128)break;s+=String.fromCharCode(i)}if(o===t)return s}return rs().decode(n.subarray(e,t))}function Po(n,e,t){for(let r=e;r<t;r++)if(n[r]>=128)return!1;return!0}function hn(n,e,t,r){const s=new Array(r-t);if(r<=t)return s;const o=e[t],i=e[r];if(Po(n,o,i)){const c=rs().decode(n.subarray(o,i));for(let l=t;l<r;l++)s[l-t]=c.substring(e[l]-o,e[l+1]-o);return s}for(let c=t;c<r;c++)s[c-t]=os(n,e[c],e[c+1]);return s}function Mo(n,e,t){let r=!0;for(let s=e;s<t;s++)if(n[s]>=128){r=!1;break}if(r)return!0;try{return ko().decode(n.subarray(e,t)),!0}catch{return!1}}function wt(n,e){const t=new Uint32Array(e+1);let r=0;for(let i=0;i<e;i++){const c=n[i];typeof c=="string"&&(r+=vo(c)),t[i+1]=r}const s=new Uint8Array(r);let o=0;for(let i=0;i<e;i++){const c=n[i];typeof c=="string"&&(o=xo(c,s,o))}return{offsets:t,utf8:s}}function Dn(n,e,t,r){if(n.length!==t+1)throw new f("E_BAD_SERIALIZATION",`${r}: expected ${t+1} offsets, found ${n.length}`,{ref:r,reason:"offsets length",expected:t+1,found:n.length});let s=n[0];for(let o=1;o<=t;o++){const i=n[o];if(i<s)throw new f("E_BAD_SERIALIZATION",`${r}: offsets decrease at row ${o-1}`,{ref:r,reason:"offsets not monotonic",row:o-1});s=i}if(s>e.length)throw new f("E_BAD_SERIALIZATION",`${r}: offsets end at ${s} but the byte store has ${e.length} bytes`,{ref:r,reason:"offsets exceed utf8",end:s,byteLength:e.length})}class Le{constructor(e,t,r){this.length=e,this.source=t,this.cache=null,this.encodedArrays=r}static fromStrings(e,t=e.length){return new Le(t,e,null)}static fromEncoded(e,t){return new Le(Math.max(0,e.length-1),null,{offsets:e,utf8:t})}get encoded(){return this.encodedArrays!==null}get decoded(){return this.source!==null}get detached(){return this.source===null&&this.length>0&&this.encodedArrays!==null&&this.encodedArrays.offsets.length===0}get offsets(){return this.ensureEncoded().offsets}get utf8(){return this.ensureEncoded().utf8}at(e){if(!(e>=0&&e<this.length)||!Number.isInteger(e))throw new f("E_INDEX_RANGE",`row ${e} out of range (length ${this.length})`,{index:e,size:this.length});if(this.source!==null)return this.source[e];this.cache??=new Array(this.length);const t=this.cache[e];if(t!==void 0)return t;const{offsets:r,utf8:s}=this.ensureEncoded(),o=os(s,r[e],r[e+1]);return this.cache[e]=o,o}slice(e=0,t=this.length){const[r,s]=is(e,t,this.length),{source:o}=this;if(o!==null){const l=new Array(s-r);for(let u=r;u<s;u++)l[u-r]=o[u];return l}const{offsets:i,utf8:c}=this.ensureEncoded();return hn(c,i,r,s)}decodeAll(){return this.slice(0,this.length)}materialiseDecoded(){this.source===null&&(this.source=this.decodeAll(),this.cache=null)}byteLength(){const e=this.encodedArrays;return e===null?0:e.offsets.byteLength+e.utf8.byteLength}firstMalformedRow(){const e=this.encodedArrays;if(this.source!==null||e===null)return-1;const{offsets:t,utf8:r}=e;for(let s=0;s<this.length;s++)if(!Mo(r,t[s],t[s+1]))return s;return-1}ensureEncoded(){let e=this.encodedArrays;return e===null&&(e=wt(this.source,this.length),this.encodedArrays=e,M(e.offsets.buffer),M(e.utf8.buffer)),e}}function is(n,e,t){let r=Math.trunc(n),s=Math.trunc(e);return Number.isNaN(r)&&(r=0),Number.isNaN(s)&&(s=0),r=r<0?Math.max(t+r,0):Math.min(r,t),s=s<0?Math.max(t+s,0):Math.min(s,t),[r,Math.max(r,s)]}function Vo(){try{const n=new ArrayBuffer(0,{maxByteLength:64});return!n.resizable||typeof n.resize!="function"?!1:(n.resize(64),n.byteLength===64&&n.maxByteLength===64)}catch{return!1}}const Tn=Vo(),gn=16,Ro=64,cs=1024*1024,Bo=16,Wo=256*1024*1024;function yt(n,e){const t=n%e;return t===0?n:n+e-t}function mt(n){return yt(n,4)}function Xo(n){return Math.ceil(n/4)}function ve(n,e=R){return yt(n,e)}function jo(n,e=R){const t=[],r=[];let s=0,o=0;for(const i of n){if(i===0){t.push(null),r.push(null);continue}const c=ve(s,e);o+=c-s,t.push(c),s=c+i,r.push(s)}return{offsets:t,ends:r,byteLength:s,padding:o}}function Fo(n){return n.byteOffset%4===0&&n.byteLength%4===0}function kn(n){const{buffer:e}=n;return e instanceof ArrayBuffer&&!e.resizable}function Rt(n){return n.byteOffset%4===0&&n.byteOffset+mt(n.byteLength)<=n.buffer.byteLength}function zo(n){if(!Rt(n))throw new f("E_COLUMN_ALIGNMENT",`u8 array at byteOffset ${n.byteOffset} with byteLength ${n.byteLength} has no zero-copy padded u32 view`,{byteOffset:n.byteOffset,byteLength:n.byteLength,bufferByteLength:n.buffer.byteLength});return new Uint32Array(n.buffer,n.byteOffset,Xo(n.byteLength))}function Go(n){const e=new Uint8Array(new ArrayBuffer(mt(n.byteLength)),0,n.byteLength);return e.set(n),e}function Yo(n){throw new f("E_UNSUPPORTED",`unsupported dtype ${String(n)}`,{dtype:n})}function Ho(n,e){return yt(Math.max(e,n*2,gn),gn)}function ls(n,e){return yt(n*e,Ro)}function us(n,e=Tn,t=cs){if(!e)return new ArrayBuffer(n);const r=Math.max(n,t);try{return new ArrayBuffer(n,{maxByteLength:r})}catch(s){if(s instanceof RangeError&&r>n)return new ArrayBuffer(n,{maxByteLength:n});throw s}}function lr(n,e,t,r=Tn){if(t<=n.length)return n;const s=e.BYTES_PER_ELEMENT,o=ls(Ho(n.length,t),s),i=o/s,{buffer:c}=n;if(c.resizable&&n.byteOffset===0&&o<=c.maxByteLength)return c.resize(o),new e(c,0,i);const l=Math.max(c.maxByteLength*2,Math.min(c.maxByteLength*Bo,Wo),cs),u=new e(us(o,r,l),0,i);return u.set(n),u}const wn=4294967295;function v(n){return Math.ceil(n/32)}function as(n){const e=n%32;return e===0?wn:wn>>>32-e}function vn(n,e){const t=v(e);t>0&&t<=n.length&&e%32!==0&&(n[t-1]&=as(e)),t<n.length&&n.fill(0,t)}function ye(n,e=!1){const t=new Uint32Array(v(n));return e&&(t.fill(wn),vn(t,n)),t}function k(n,e){return(n[e>>>5]>>>(e&31)&1)===1}function K(n,e){n[e>>>5]|=1<<(e&31)}function Z(n,e){n[e>>>5]&=~(1<<(e&31))}function yn(n,e,t){t?K(n,e):Z(n,e)}function ur(n){let e=n-(n>>>1&1431655765);return e=(e&858993459)+(e>>>2&858993459),e=e+(e>>>4)&252645135,Math.imul(e,16843009)>>>24}function xe(n,e){const t=Math.floor(e/32);let r=0;for(let s=0;s<t;s++)r+=ur(n[s]);return e%32!==0&&(r+=ur(n[t]&as(e))),r}function qo(n,e){const t=new Uint32Array(xe(n,e));let r=0;for(let s=0;s<e;s++)(n[s>>>5]>>>(s&31)&1)===1&&(t[r++]=s);return t}function ds(n,e,t){const r=Math.max(0,t-e),s=ye(r);if(r===0)return s;const o=e>>>5,i=e&31;if(i===0)s.set(n.subarray(o,o+s.length));else{const c=32-i;for(let l=0;l<s.length;l++){const u=o+l,a=u<n.length?n[u]>>>i:0,d=u+1<n.length?n[u+1]<<c:0;s[l]=a|d}}return vn(s,r),s}function Se(n,e){if(ss(n))throw new f("E_COLUMN_TYPE","string value contains a lone surrogate",{...e,reason:"lone surrogate"})}function Jo(n){const e=new Map;for(let t=0;t<n.length;t++){const r=n[t];e.has(r)||e.set(r,t)}return e}class Ko{constructor(e){if(this.values=[],this.codes=new Map,e!==void 0)for(const t of e)this.intern(t)}get size(){return this.values.length}intern(e){const t=this.codes.get(e);if(t!==void 0)return t;Se(e);const r=this.values.length,s=nt(e);return this.values.push(s),this.codes.set(s,r),r}codeOf(e){const t=this.codes.get(e);return t===void 0?4294967295:t}has(e){return this.codes.has(e)}}const Zo=["bool","i32","f64","string","json"],Qo=/^-?(0|[1-9]\d*)$/,ei=/^[+-]?((0|[1-9]\d*)(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/,fs=-2147483648,hs=2147483647;function ke(n){return Zo.indexOf(n)}function gs(n,e){return n===null?e:e===null?n:ke(e)>ke(n)?e:n}function ti(n){if(n==="true"||n==="false")return"bool";if(Qo.test(n)){const e=Number(n);return e>=fs&&e<=hs?"i32":Number.isFinite(e)?"f64":"string"}return ei.test(n)&&Number.isFinite(Number(n))?"f64":"string"}function Bt(n){if(n==null)return null;switch(typeof n){case"boolean":return"bool";case"number":return Number.isInteger(n)&&n>=fs&&n<=hs?"i32":"f64";case"string":return"string";case"object":return"json";default:throw new f("E_COLUMN_TYPE",`a ${typeof n} value cannot be stored in a column`,{reason:"unsupported value type",found:typeof n})}}function je(n,e){switch(e){case"bool":if(typeof n=="boolean")return n;break;case"i32":case"f64":if(typeof n=="number")return n;if(typeof n=="boolean")return n?1:0;break;case"string":if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean")return String(n);break;case"json":return n;default:{const t=e;throw new f("E_COLUMN_TYPE",`unknown dtype ${t}`,{dtype:t})}}throw new f("E_COLUMN_TYPE",`a ${typeof n} value cannot be stored in a ${e} column`,{dtype:e,found:typeof n})}function ar(n){let e=null;for(const t of n)if(e=gs(e,Bt(t)),e==="json")break;return e}class dr{constructor(){this.current=null}get dtype(){return this.current}observeValue(e){return this.apply(Bt(e))}observeText(e){return this.apply(ti(e))}widenTo(e){return this.apply(e)}apply(e){const t=gs(this.current,e);return t===this.current?!1:(this.current=t,!0)}}const ws=new Set(["f32","f64","i32","u32","u8","bool","dict","string","list","json"]),ni=new Set(["f32","f64","i32","u32","u8"]),fr=16,hr=256,ri=-2147483648,si=2147483647,oi=4294967295,ii=255,ci=new TextDecoder,xt=new WeakMap;function Ue(n){return new Uint8Array(new ArrayBuffer(mt(n)),0,n)}function li(n){switch(n){case"f32":case"i32":case"u32":case"dict":return"direct";case"u8":case"bool":return"packed";case"f64":return"convert";case"string":case"list":case"json":return"none";default:{const e=n;throw new f("E_COLUMN_TYPE",`unknown dtype ${e}`,{dtype:e})}}}function ui(n){return n!=="list"&&ws.has(n)}function me(n){if(typeof n!="object"||n===null)return!1;const e=Object.getPrototypeOf(n);return e===Object.prototype||e===null}function oe(n,e,t=0){if(!(n===null||typeof n=="boolean"||typeof n=="number")){if(typeof n=="string"){Se(n,{field:e});return}if(t>hr)throw new f("E_COLUMN_TYPE",`${e} is nested deeper than ${hr} levels`,{field:e,reason:"nesting"});if(Array.isArray(n)){for(const r of n)oe(r,e,t+1);return}if(me(n)){for(const r of Object.keys(n))oe(n[r],e,t+1);return}throw new f("E_COLUMN_TYPE",`${e} is not a JSON value`,{field:e,found:n===void 0?"undefined":typeof n})}}function Ce(n){if(Array.isArray(n))return n.map(e=>Ce(e));if(me(n)){const e={};for(const t of Object.keys(n))t==="__proto__"?Object.defineProperty(e,t,{value:Ce(n[t]),enumerable:!0,writable:!0,configurable:!0}):e[t]=Ce(n[t]);return e}return n}function Pe(n,e){switch(n){case"f32":case"f64":return!0;case"i32":return Number.isInteger(e)&&e>=ri&&e<=si;case"u32":return Number.isInteger(e)&&e>=0&&e<=oi;case"u8":return Number.isInteger(e)&&e>=0&&e<=ii;default:{const t=n;throw new f("E_COLUMN_TYPE",`unknown dtype ${t}`,{dtype:t})}}}function ys(n,e,t){if(typeof t=="number")return Pe(n,t)?t:null;if(e>1&&Array.isArray(t)&&t.length===e){const r=t[0];if(typeof r!="number"||!Pe(n,r))return null;for(let s=1;s<e;s++)if(!Object.is(t[s],r))return null;return r}return null}function U(n,e,t){return new f("E_COLUMN_TYPE",e,{...t,field:n})}function ai(n){if(n===void 0)return null;if(!me(n))throw U("origin","origin must be a plain object");const e=t=>{const r=n[t];if(r==null)return null;if(typeof r!="string")throw U("origin",`origin.${t} must be a string or null`,{found:typeof r});return r};return{format:e("format"),id:e("id"),title:e("title"),type:e("type"),namespace:e("namespace")}}function gr(n,e,t){if(e===void 0)return 1;if(!Number.isInteger(e)||e<1||e>fr)throw U(n,`${n} must be an integer in 1..${fr}, found ${e}`,{found:e});if(e>1&&!ni.has(t))throw U(n,`${n} > 1 is only allowed for f32 / f64 / i32 / u32 / u8, not ${t}`,{found:e,dtype:t});return e}function di(n,e,t,r,s,o){switch(n){case"f32":case"f64":case"i32":case"u32":case"u8":{if(t!==void 0){if(typeof t!="number")throw U("fill",`fill of a ${n} column must be a number`,{found:typeof t});return t}return o!==null?4294967295:ys(n,e,r)??0}case"bool":{if(t!==void 0){if(typeof t!="boolean")throw U("fill","fill of a bool column must be a boolean",{found:typeof t});return t}return typeof r=="boolean"?r:!1}case"dict":{if(t!==void 0){if(typeof t!="string")throw U("fill","fill of a dict column must be a string",{found:typeof t});return t}return typeof r=="string"&&(s===null||s.includes(r))?r:s!==null&&s.length>0&&typeof s[0]=="string"?s[0]:""}case"string":{if(t!==void 0){if(typeof t!="string")throw U("fill","fill of a string column must be a string",{found:typeof t});return t}return""}case"list":case"json":{if(t!==void 0&&t!=="")throw U("fill",`a ${n} column takes no fill value`,{found:t});return""}default:{const i=n;throw new f("E_COLUMN_TYPE",`unknown dtype ${i}`,{dtype:i})}}}function B(n,e,t){const{dtype:r}=t;if(r===void 0||!ws.has(r))throw U("dtype",`column "${n}" has no valid dtype`,{name:n,found:r});const s=gr("components",t.components,r);let o=null,i=null;if(r==="list"){const{itemDtype:h}=t;if(h===void 0||!ui(h))throw U("itemDtype",`list column "${n}" needs a scalar itemDtype`,{name:n,found:h});o=h,i=gr("itemComponents",t.itemComponents,h)}else if(t.itemDtype!==void 0||t.itemComponents!==void 0)throw U("itemDtype",`itemDtype / itemComponents are only allowed on list columns, not ${r}`,{name:n,dtype:r});const c=t.refersTo??null;if(c!==null){if(c!=="node"&&c!=="edge")throw U("refersTo",'refersTo must be "node" or "edge"',{found:c});if(!(r==="u32"&&s===1||r==="list"&&o==="u32"&&i===1))throw U("refersTo",`refersTo requires a u32 column or a list of u32, not ${r}`,{name:n,dtype:r})}const l=t.default;l!==void 0&&oe(l,"default");let u=null;if(t.options!==void 0){if(!Array.isArray(t.options))throw U("options","options must be an array");if(oe(t.options,"options"),r==="dict"){for(const h of t.options)if(typeof h!="string")throw U("options","options of a dict column must be strings",{found:typeof h})}u=Object.freeze(Ce([...t.options]))}const a=t.extra??{};if(!me(a))throw U("extra","extra must be a plain object");oe(a,"extra");const d=t.role??null;if(d!==null&&typeof d!="string")throw U("role","role must be a string",{found:typeof d});const g=di(r,s,t.fill,l,u,c);return Object.freeze({name:n,domain:e,dtype:r,components:s,itemDtype:o,itemComponents:i,nullable:t.nullable??!0,mutable:t.mutable??!1,role:d,refersTo:c,unique:t.unique??!1,default:Ce(l),fill:g,options:u,origin:ai(t.origin),dynamic:t.dynamic??!1,extra:Object.freeze(Ce({...a}))})}function he(n){return{name:n.name,dtype:n.dtype,components:n.components,itemDtype:n.itemDtype??void 0,itemComponents:n.itemComponents??void 0,nullable:n.nullable,mutable:n.mutable,role:n.role??void 0,refersTo:n.refersTo??void 0,unique:n.unique,default:n.default,fill:n.fill,options:n.options??void 0,origin:n.origin??void 0,dynamic:n.dynamic,extra:n.extra}}class Ve{constructor(e,t,r,s,o){this.versionValue=0,this.defaultCache=null,this.dtype=e,this.meta=t,this.length=r,this.gpu=li(e),this.validityWords=s,this.nullCountValue=o,this.defaultValue=Ce(t.default)}get validity(){return this.validityWords}get nullCount(){return this.nullCountValue}get version(){return this.versionValue}get paddedByteLength(){return this.byteLength}get validityByteLength(){return this.validityWords===null?0:this.validityWords.byteLength}get detached(){if(this.length===0)return!1;const e=this.validityWords;return e!==null&&e.length===0||this.storageDetached()}isSet(e){if(!(e>=0&&e<this.length))return!1;const t=this.validityWords;if(t===null)return!0;if(t.length===0)throw this.detachedError();return k(t,e)}value(e){if(this.assertAttached(),!(Number.isInteger(e)&&e>=0&&e<this.length))throw new f("E_INDEX_RANGE",`row ${e} is out of range for a column of ${this.length} rows`,{row:e,length:this.length,column:this.meta.name});const t=this.validityWords;if(t!==null&&!k(t,e)){const{defaultValue:r}=this;return r===void 0?void 0:Ce(r)}return this.readValue(e)}materializeDefault(){if(this.assertAttached(),this.meta.default===void 0)throw new f("E_NO_DEFAULT",`column "${this.meta.name}" declares no default`,{column:this.meta.name});return this.nullCountValue===0||this.fillIsDefault()?this.self():(this.defaultCache??=this.withDefaults(),this.defaultCache)}paddedU32View(){throw new f("E_GPU_INELIGIBLE",`a ${this.dtype} column has no u32 view`,{column:this.meta.name,dtype:this.dtype})}markDirty(){this.assertMutable("markDirty"),this.assertAttached(),this.versionValue++,this.defaultCache=null,xt.delete(this);const e=this.validityWords;e!==null&&(this.nullCountValue=this.length-xe(e,this.length))}mutableValidity(){return this.assertMutable("mutableValidity"),this.validityWords}setAll(){this.assertMutable("setAll"),this.validityWords=null,this.nullCountValue=0,this.versionValue++,this.defaultCache=null}assertAttached(){if(this.detached)throw this.detachedError()}detachedError(){return new f("E_DETACHED",`column "${this.meta.name}" was transferred away`,{column:this.meta.name})}assertMutable(e){if(!this.meta.mutable)throw new f("E_COLUMN_IMMUTABLE",`${e}() on immutable column "${this.meta.name}"`,{column:this.meta.name,operation:e})}checkRange(e,t){if(this.assertAttached(),!(Number.isInteger(e)&&Number.isInteger(t)&&e>=0&&e<=t&&t<=this.length))throw new f("E_INDEX_RANGE",`row range [${e}, ${t}) is invalid for ${this.length} rows`,{start:e,end:t,length:this.length,column:this.meta.name})}sliceValidity(e,t){const r=this.validityWords;if(r===null)return{validity:null,nullCount:0};const s=t-e,o=e%32===0?He(r.subarray(e>>>5,(e>>>5)+v(s))):ds(r,e,t);return{validity:o,nullCount:s-xe(o,s)}}cloneValidity(){return this.assertAttached(),this.validityWords===null?null:this.validityWords.slice()}}function He(n){return Ee(n.buffer),n}class pt extends Ve{constructor(e,t,r,s,o,i){super(e,t,r,o,i),this.data=s}get byteLength(){return this.data.byteLength+this.validityByteLength}mutableData(){return this.assertMutable("mutableData"),this.assertAttached(),this.data}storageDetached(){return this.data.length===0&&this.length*this.meta.components>0}slice(e,t){this.checkRange(e,t);const{components:r}=this.meta,s=this.sliceData(e*r,t*r),{validity:o,nullCount:i}=this.sliceValidity(e,t);return this.wrap(this.meta,t-e,s,o,i)}clone(){return this.assertAttached(),this.wrap(this.meta,this.length,this.copyData(),this.cloneValidity(),this.nullCountValue)}readValue(e){const{components:t}=this.meta;return t===1?this.data[e]:this.data.subarray(e*t,(e+1)*t)}fillIsDefault(){const{fill:e,default:t,components:r}=this.meta;return typeof e!="number"?!1:ys(this.dtype,r,t)===e}withDefaults(){const{components:e,default:t}=this.meta,r=this.copyData(),s=this.validityWords;if(s!==null)for(let o=0;o<this.length;o++)k(s,o)||ms(this.dtype,r,o*e,e,t,this.meta.name,o);return this.wrap(this.meta,this.length,r,this.cloneValidity(),this.nullCountValue)}sliceData(e,t){return He(this.data.subarray(e,t))}copyData(){return this.data.slice()}}function ms(n,e,t,r,s,o,i){if(typeof s=="number"){wr(n,s,o,i),r===1?e[t]=s:e.fill(s,t,t+r);return}if(r===1||!ps(s,r))throw new f("E_COLUMN_TYPE",`row ${i} of ${n} column "${o}" is not ${r} number(s)`,{column:o,row:i,components:r,found:typeof s});for(let c=0;c<r;c++)wr(n,s[c],o,i);for(let c=0;c<r;c++)e[t+c]=s[c]}function wr(n,e,t,r){if(!Pe(n,e))throw new f("E_COLUMN_TYPE",`row ${r} of ${n} column "${t}": ${e} is not representable`,{column:t,row:r,value:e})}function ps(n,e){if(typeof n!="object"||n===null)return!1;const t=n;if(t.length!==e)return!1;for(let r=0;r<e;r++)if(typeof t[r]!="number")return!1;return!0}class xn extends pt{constructor(e,t,r,s,o){super("f32",e,t,r,s,o)}self(){return this}wrap(e,t,r,s,o){return new xn(e,t,r,s,o)}}class Sn extends pt{constructor(e,t,r,s,o){super("f64",e,t,r,s,o)}self(){return this}wrap(e,t,r,s,o){return new Sn(e,t,r,s,o)}}class Un extends pt{constructor(e,t,r,s,o){super("i32",e,t,r,s,o)}self(){return this}wrap(e,t,r,s,o){return new Un(e,t,r,s,o)}}class Pn extends pt{constructor(e,t,r,s,o){super("u32",e,t,r,s,o)}paddedU32View(){return this.data}self(){return this}wrap(e,t,r,s,o){return new Pn(e,t,r,s,o)}}class Mn extends pt{constructor(e,t,r,s,o){super("u8",e,t,r,s,o)}get paddedByteLength(){return mt(this.data.byteLength)+this.validityByteLength}paddedU32View(){return zo(this.data)}self(){return this}wrap(e,t,r,s,o){return new Mn(e,t,r,s,o)}sliceData(e,t){if(e%4===0)return He(this.data.subarray(e,t));const r=Ue(t-e);return r.set(this.data.subarray(e,t)),r}copyData(){const e=Ue(this.data.length);return e.set(this.data),e}}class rt extends Ve{constructor(e,t,r,s,o){super("bool",e,t,s,o),this.data=r}get byteLength(){return this.data.byteLength+this.validityByteLength}mutableData(){return this.assertMutable("mutableData"),this.assertAttached(),this.data}paddedU32View(){return this.assertAttached(),this.data}slice(e,t){this.checkRange(e,t);const r=t-e,s=e%32===0?He(this.data.subarray(e>>>5,(e>>>5)+v(r))):ds(this.data,e,t),{validity:o,nullCount:i}=this.sliceValidity(e,t);return new rt(this.meta,r,s,o,i)}clone(){return this.assertAttached(),new rt(this.meta,this.length,this.data.slice(),this.cloneValidity(),this.nullCountValue)}storageDetached(){return this.data.length===0}self(){return this}readValue(e){return k(this.data,e)}fillIsDefault(){return this.meta.fill===this.meta.default}withDefaults(){const{default:e,name:t}=this.meta;if(typeof e!="boolean")throw new f("E_COLUMN_TYPE",`default of bool column "${t}" is not a boolean`,{column:t,field:"default"});const r=this.data.slice(),s=this.validityWords;if(s!==null)for(let o=0;o<this.length;o++)k(s,o)||(e?K(r,o):Z(r,o));return new rt(this.meta,this.length,r,this.cloneValidity(),this.nullCountValue)}}class st extends Ve{constructor(e,t,r,s,o,i){super("dict",e,t,o,i),this.codeMap=null,this.codes=r,this.dictionary=s}get byteLength(){return this.codes.byteLength+this.validityByteLength}codeOf(e){this.codeMap??=Jo(this.dictionary);const t=this.codeMap.get(e);return t===void 0?4294967295:t}mutableData(){return this.assertMutable("mutableData"),this.assertAttached(),this.codes}paddedU32View(){return this.assertAttached(),this.codes}slice(e,t){this.checkRange(e,t);const{validity:r,nullCount:s}=this.sliceValidity(e,t);return new st(this.meta,t-e,He(this.codes.subarray(e,t)),this.dictionary,r,s)}storageDetached(){return this.codes.length===0}clone(){return this.assertAttached(),new st(this.meta,this.length,this.codes.slice(),[...this.dictionary],this.cloneValidity(),this.nullCountValue)}self(){return this}readValue(e){return this.dictionary[this.codes[e]]}fillIsDefault(){return this.meta.fill===this.meta.default}withDefaults(){const{default:e,name:t}=this.meta;if(typeof e!="string")throw new f("E_COLUMN_TYPE",`default of dict column "${t}" is not a string`,{column:t,field:"default"});let r=this.dictionary,s=this.codeOf(e);s===4294967295&&(s=r.length,r=[...r,e]);const o=this.codes.slice(),i=this.validityWords;if(i!==null)for(let c=0;c<this.length;c++)k(i,c)||(o[c]=s);return new st(this.meta,this.length,o,r,this.cloneValidity(),this.nullCountValue)}}function fi(n){const e=wt(n,n.length),t=Ue(e.utf8.length);return t.set(e.utf8),{offsets:e.offsets,utf8:t}}class ne extends Ve{constructor(e,t,r,s,o,i,c){super("string",e,t,i,c),this.offsetsStore=r,this.utf8Store=s,this.strings=o}get offsets(){return this.store(),this.offsetsStore}get utf8(){return this.store(),this.utf8Store}get byteLength(){return this.store(),this.offsetsStore.byteLength+this.utf8Store.byteLength+this.validityByteLength}valueAt(e){const t=this.strings?.[e];if(t!==void 0)return t;this.assertAttached(),this.store();const r=this.offsetsStore,s=this.utf8Store,o=ci.decode(s.subarray(r[e],r[e+1]));return this.strings??=new Array(this.length),this.strings[e]=o,o}decodeAll(){const e=new Array(this.length);for(let t=0;t<this.length;t++)e[t]=this.valueAt(t);return e}slice(e,t){this.checkRange(e,t);const r=t-e,{validity:s,nullCount:o}=this.sliceValidity(e,t),i=this.strings===null?null:this.strings.slice(e,t);if(this.offsetsStore===null||this.utf8Store===null)return new ne(this.meta,r,null,null,i,s,o);const c=this.offsetsStore[e],l=new Uint32Array(r+1);for(let a=0;a<=r;a++)l[a]=this.offsetsStore[e+a]-c;const u=He(this.utf8Store.subarray(c,this.offsetsStore[t]));return new ne(this.meta,r,l,u,i,s,o)}clone(){this.assertAttached();const e=this.strings===null?null:[...this.strings];if(this.offsetsStore===null||this.utf8Store===null)return new ne(this.meta,this.length,null,null,e,this.cloneValidity(),this.nullCountValue);const t=Ue(this.utf8Store.length);return t.set(this.utf8Store),new ne(this.meta,this.length,this.offsetsStore.slice(),t,e,this.cloneValidity(),this.nullCountValue)}hasStore(){return this.offsetsStore!==null}decodedCache(){return this.strings}self(){return this}storageDetached(){return this.offsetsStore!==null&&this.offsetsStore.length===0}readValue(e){return this.valueAt(e)}fillIsDefault(){return this.meta.fill===this.meta.default}withDefaults(){const{default:e,name:t}=this.meta;if(typeof e!="string")throw new f("E_COLUMN_TYPE",`default of string column "${t}" is not a string`,{column:t,field:"default"});const r=this.decodeAll(),s=this.validityWords;if(s!==null)for(let o=0;o<this.length;o++)k(s,o)||(r[o]=e);return new ne(this.meta,this.length,null,null,r,this.cloneValidity(),this.nullCountValue)}store(){if(this.offsetsStore!==null&&this.utf8Store!==null){this.assertAttached();return}const e=this.strings??[],t=new Array(this.length);for(let s=0;s<this.length;s++)t[s]=e[s]??"";const r=fi(t);this.offsetsStore=r.offsets,this.utf8Store=r.utf8,M(r.offsets.buffer),M(r.utf8.buffer)}}class ot extends Ve{constructor(e,t,r,s,o,i){super("list",e,t,o,i),this.offsets=r,this.child=s}get byteLength(){return this.offsets.byteLength+this.child.byteLength+this.validityByteLength}sliceOf(e){this.assertAttached();const t=this.offsets[e],r=this.offsets[e+1],s=new Array(r-t);for(let o=t;o<r;o++)s[o-t]=this.child.value(o);return s}slice(e,t){this.checkRange(e,t);const r=t-e,s=this.offsets[e],o=new Uint32Array(r+1);for(let l=0;l<=r;l++)o[l]=this.offsets[e+l]-s;const{validity:i,nullCount:c}=this.sliceValidity(e,t);return new ot(this.meta,r,o,this.child.slice(s,this.offsets[t]),i,c)}clone(){return this.assertAttached(),new ot(this.meta,this.length,this.offsets.slice(),this.child.clone(),this.cloneValidity(),this.nullCountValue)}storageDetached(){return this.offsets.length===0||Vn(this.child)}self(){return this}readValue(e){return this.sliceOf(e)}fillIsDefault(){return!1}withDefaults(){const{default:e,name:t}=this.meta;if(!Array.isArray(e))throw new f("E_COLUMN_TYPE",`default of list column "${t}" is not an array`,{column:t,field:"default"});const r=new Array(this.length),s=this.validityWords;for(let i=0;i<this.length;i++)r[i]=s!==null&&!k(s,i)?e:this.sliceOf(i);const o=bs(this.meta,r);return new ot(this.meta,this.length,o.offsets,o.child,this.cloneValidity(),this.nullCountValue)}}class it extends Ve{constructor(e,t,r,s,o){super("json",e,t,s,o),this.values=r}get byteLength(){return this.validityByteLength}slice(e,t){this.checkRange(e,t);const{validity:r,nullCount:s}=this.sliceValidity(e,t);return new it(this.meta,t-e,this.values.slice(e,t),r,s)}clone(){return this.assertAttached(),new it(this.meta,this.length,[...this.values],this.cloneValidity(),this.nullCountValue)}storageDetached(){return!1}self(){return this}readValue(e){return this.values[e]}fillIsDefault(){return!1}withDefaults(){const{default:e}=this.meta,t=[...this.values],r=this.validityWords;if(r!==null)for(let s=0;s<this.length;s++)k(r,s)||(t[s]=e);return new it(this.meta,this.length,t,this.cloneValidity(),this.nullCountValue)}}function hi(n){return n instanceof Ve}function Vn(n){return n.detached}function Q(n,e,t,r){return new f("E_COLUMN_LENGTH",`column "${n.name}": ${e} has length ${r}, expected ${t}`,{column:n.name,what:e,expected:t,found:r})}function ee(n,e){return new f("E_COLUMN_TYPE",`column "${n.name}": ${e}`,{column:n.name})}function F(n){const{meta:e,length:t}=n;if(!(Number.isInteger(t)&&t>=0))throw new f("E_COLUMN_LENGTH",`column "${e.name}": invalid row count ${t}`,{column:e.name,found:t});const{validity:r}=n;let s=null;if(r!==null){if(!e.nullable)throw ee(e,"a non-nullable column cannot carry a validity bitmap");if(!(r instanceof Uint32Array))throw ee(e,"validity must be a Uint32Array");if(r.length!==v(t))throw Q(e,"validity",v(t),r.length);s=r}const o=s===null?0:t-xe(s,t),{dtype:i}=e;switch(i){case"f32":return new xn(e,t,Qe(n,Float32Array),s,o);case"f64":return new Sn(e,t,Qe(n,Float64Array),s,o);case"i32":return new Un(e,t,Qe(n,Int32Array),s,o);case"u32":return new Pn(e,t,Qe(n,Uint32Array),s,o);case"u8":{const c=Qe(n,Uint8Array);if(!Rt(c))throw new f("E_COLUMN_ALIGNMENT",`column "${e.name}": no padded u32 view over the u8 data`,{column:e.name,byteOffset:c.byteOffset,byteLength:c.byteLength});return new Mn(e,t,c,s,o)}case"bool":{if(!(n.data instanceof Uint32Array))throw ee(e,"bool data must be packed Uint32Array words");if(n.data.length!==v(t))throw Q(e,"data",v(t),n.data.length);return new rt(e,t,n.data,s,o)}case"dict":{if(!(n.data instanceof Uint32Array))throw ee(e,"dict codes must be a Uint32Array");if(n.data.length!==t)throw Q(e,"codes",t,n.data.length);if(n.dictionary===null)throw ee(e,"dict column needs a dictionary");return new st(e,t,n.data,n.dictionary,s,o)}case"string":{if(n.offsets===null||n.utf8===null){const{strings:c}=n;if(c?.length!==t)throw Q(e,"strings",t,c===null?-1:c.length);for(let l=0;l<t;l++)if(typeof c[l]!="string")throw ee(e,`row ${l} is not a decoded string and no Utf8 store is present`);return new ne(e,t,null,null,c,s,o)}if(n.offsets.length!==t+1)throw Q(e,"offsets",t+1,n.offsets.length);if(n.offsets[t]!==n.utf8.length)throw Q(e,"utf8",n.offsets[t],n.utf8.length);return new ne(e,t,n.offsets,n.utf8,n.strings,s,o)}case"list":{if(n.offsets?.length!==t+1)throw Q(e,"offsets",t+1,n.offsets===null?-1:n.offsets.length);const{child:c}=n;if(c===null||c.dtype==="list")throw ee(e,"list column needs a non-list child column");if(c.validity!==null||c.meta.nullable)throw ee(e,"list child must be non-nullable");if(c.dtype!==e.itemDtype||c.meta.components!==e.itemComponents)throw ee(e,`list child is ${c.dtype} x${c.meta.components}, declared ${String(e.itemDtype)} x${String(e.itemComponents)}`);if(n.offsets[t]!==c.length)throw Q(e,"child",n.offsets[t],c.length);return new ot(e,t,n.offsets,c,s,o)}case"json":{if(n.values?.length!==t)throw Q(e,"values",t,n.values===null?-1:n.values.length);return new it(e,t,n.values,s,o)}default:{const c=i;throw new f("E_COLUMN_TYPE",`unknown dtype ${c}`,{dtype:c})}}}function Qe(n,e){const{meta:t,length:r}=n;if(!(n.data instanceof e))throw ee(t,`${t.dtype} data must be a ${e.name}`);const s=r*t.components;if(n.data.length!==s)throw Q(t,"data",s,n.data.length);return n.data}function St(n){const e={meta:n.meta,length:n.length,data:null,validity:n.validity,nullCount:n.nullCount,dictionary:null,offsets:null,utf8:null,strings:null,child:null,values:null},{dtype:t}=n;switch(t){case"f32":case"f64":case"i32":case"u32":case"u8":case"bool":return e.data=n.data,e;case"dict":return e.data=n.codes,e.dictionary=n.dictionary,e;case"string":return n instanceof ne?(e.strings=n.decodedCache(),n.hasStore()&&(e.offsets=n.offsets,e.utf8=n.utf8),e):(e.offsets=n.offsets,e.utf8=n.utf8,e);case"list":return e.offsets=n.offsets,e.child=n.child,e;case"json":return e.values=n.values,e;default:{const r=t;throw new f("E_COLUMN_TYPE",`unknown dtype ${r}`,{dtype:r})}}}function Rn(n){const e=new Set,t=r=>{r!==null&&e.add(r.buffer)};switch(t(n.validity),n.dtype){case"f32":case"f64":case"i32":case"u32":case"u8":case"bool":t(n.data);break;case"dict":t(n.codes);break;case"string":(!(n instanceof ne)||n.hasStore())&&(t(n.offsets),t(n.utf8));break;case"list":t(n.offsets);for(const r of Rn(n.child))e.add(r);break;case"json":break;default:{const r=n;throw new f("E_COLUMN_TYPE",`unknown dtype ${r.dtype}`,{})}}return[...e]}function yr(n,e){const t=n.meta;if(e.dtype!==t.dtype||e.components!==t.components||e.itemDtype!==t.itemDtype||e.itemComponents!==t.itemComponents)throw new f("E_COLUMN_TYPE",`column "${t.name}" is ${t.dtype} x${t.components}; a patch cannot change its dtype`,{column:t.name,field:"dtype"});if(e.fill!==t.fill)throw new f("E_COLUMN_TYPE",`the fill of existing column "${t.name}" cannot change`,{column:t.name,field:"fill"});const r=St(n);if(!e.nullable&&n.validity!==null){if(n.nullCount>0)throw new f("E_COLUMN_TYPE",`column "${t.name}" has ${n.nullCount} unset rows and cannot become non-nullable`,{column:t.name,field:"nullable",nullCount:n.nullCount});r.validity=null}return r.meta=e,F(r)}function gi(n){xt.delete(n)}function wi(n){const{dtype:e}=n;switch(e){case"f32":case"i32":case"u32":case"bool":return n.data;case"u8":return n.paddedU32View();case"dict":return n.codes;case"f64":{let t=xt.get(n);return t===void 0&&(t=new Float32Array(n.data),xt.set(n,t)),t}case"string":case"list":case"json":throw new f("E_GPU_INELIGIBLE",`a ${e} column cannot be bound by the GPU`,{column:n.meta.name,dtype:e});default:{const t=e;throw new f("E_COLUMN_TYPE",`unknown dtype ${t}`,{dtype:t})}}}function yi(n,e,t){const r=typeof e=="string"?e:"",s=n.codeOf(r);return s===4294967295?0:s}function Bn(n){const e=new Ko(n.options===null?void 0:n.options);return typeof n.fill=="string"&&n.fill!==""&&e.intern(n.fill),e}function qe(n,e,t){return{meta:n,length:e,data:null,validity:t,nullCount:t===null?0:e,dictionary:null,offsets:null,utf8:null,strings:null,child:null,values:null}}function mi(n){if(n.itemDtype===null||n.itemComponents===null)throw new f("E_COLUMN_TYPE",`column "${n.name}" is not a list`,{column:n.name,field:"itemDtype"});return B(`${n.name}.item`,n.domain,{dtype:n.itemDtype,components:n.itemComponents,nullable:!1,refersTo:n.refersTo??void 0})}function pi(n,e){return n===void 0||n===null&&e!=="json"}function bs(n,e){const t=new Uint32Array(e.length+1),r=[];for(let o=0;o<e.length;o++){for(const i of e[o])r.push(i);t[o+1]=r.length}const s=ut(mi(n),r);return{offsets:t,child:s}}function ut(n,e){const{length:t}=e,{dtype:r,components:s,fill:o,name:i}=n;let c=null,l=0;for(let d=0;d<t;d++)if(pi(e[d],r)){if(!n.nullable)throw new f("E_COLUMN_TYPE",`row ${d} of non-nullable column "${i}" is unset`,{column:i,row:d});c??=ye(t,!0),Z(c,d),l++}const u=qe(n,t,c);u.nullCount=l;const a=d=>c===null||k(c,d);switch(r){case"f32":case"f64":case"i32":case"u32":case"u8":{const d=Is(r,t*s);o!==0&&d.fill(o);for(let g=0;g<t;g++){if(!a(g))continue;const h=e[g],y=typeof h=="boolean"?Number(h):h;ms(r,d,g*s,s,y,i,g)}u.data=d;break}case"bool":{const d=ye(t,o===!0);for(let g=0;g<t;g++){if(!a(g))continue;je(e[g],"bool")===!0?K(d,g):Z(d,g)}u.data=d;break}case"dict":{const d=Bn(n),g=new Uint32Array(t);c!==null&&g.fill(yi(d,o));for(let h=0;h<t;h++){if(!a(h))continue;const y=je(e[h],"string");if(typeof y!="string")throw new f("E_COLUMN_TYPE",`row ${h} of dict column "${i}" is not a string`,{column:i,row:h});g[h]=d.intern(y)}u.data=g,u.dictionary=d.values;break}case"string":{const d=typeof o=="string"?o:"",g=new Array(t);for(let h=0;h<t;h++){if(!a(h)){g[h]=d;continue}const y=je(e[h],"string");if(typeof y!="string")throw new f("E_COLUMN_TYPE",`row ${h} of string column "${i}" is not a string`,{column:i,row:h});Se(y,{column:i,row:h}),g[h]=y}u.strings=g;break}case"list":{const d=new Array(t);for(let h=0;h<t;h++){if(!a(h)){d[h]=[];continue}const y=e[h];if(!Array.isArray(y))throw new f("E_COLUMN_TYPE",`row ${h} of list column "${i}" is not an array`,{column:i,row:h});d[h]=y}const g=bs(n,d);u.offsets=g.offsets,u.child=g.child;break}case"json":{const d=new Array(t);for(let g=0;g<t;g++){if(!a(g)){d[g]=void 0;continue}oe(e[g],`row ${g}`),d[g]=e[g]}u.values=d;break}default:{const d=r;throw new f("E_COLUMN_TYPE",`unknown dtype ${d}`,{dtype:d})}}return F(u)}function Is(n,e){switch(n){case"f32":return new Float32Array(e);case"f64":return new Float64Array(e);case"i32":return new Int32Array(e);case"u32":return new Uint32Array(e);case"u8":return Ue(e);default:{const t=n;throw new f("E_COLUMN_TYPE",`unknown dtype ${t}`,{dtype:t})}}}function bi(n){let e=!1,t=!1;for(const r of n)r!=null&&(Array.isArray(r)?e=!0:t=!0);return e&&!t?{dtype:"list",itemDtype:ar(Ii(n))??"json"}:{dtype:ar(n)??"json",itemDtype:void 0}}function Ii(n){const e=[];for(const t of n)if(Array.isArray(t))for(const r of t)e.push(r);return e}function Wn(n,e,t,r,s){if(r.length!==e)throw new f("E_COLUMN_LENGTH",`column "${t}": ${r.length} values for ${e} rows`,{column:t,expected:e,found:r.length});let o={nullable:!0,...s};if(o.dtype===void 0){const c=bi(r);o={...o,dtype:c.dtype},c.dtype==="list"&&o.itemDtype===void 0&&(o={...o,itemDtype:c.itemDtype})}const i=B(t,n,o);return ut(i,r)}function Es(n){return n instanceof Float32Array?"f32":n instanceof Float64Array?"f64":n instanceof Int32Array?"i32":n instanceof Uint32Array?"u32":"u8"}function Ei(n,e,t,r,s,o="copy"){const i=Es(r),c=s.dtype??i;if(!(c===i||i==="u32"&&(c==="bool"||c==="dict")))throw new f("E_COLUMN_TYPE",`column "${t}": a ${i} array cannot back a ${c} column`,{column:t,field:"dtype",found:i,expected:c});const u=B(t,n,{nullable:!1,...s,dtype:c}),a=qe(u,e,null),d=Ai(t,c,e,u.components);if(r.length!==d)throw new f("E_COLUMN_LENGTH",`column "${t}": array length ${r.length}, expected ${d}`,{column:t,expected:d,found:r.length});if(!kn(r)){const h=r.buffer instanceof ArrayBuffer?"resizable ArrayBuffer":"SharedArrayBuffer";throw new f("E_UNSUPPORTED",`column "${t}": a view over a ${h} cannot be adopted`,{column:t,reason:h})}let g=r;if(r instanceof Uint8Array&&!Rt(r)){if(o==="strict")throw new f("E_COLUMN_ALIGNMENT",`column "${t}": no zero-copy padded u32 view over the u8 array`,{column:t,byteOffset:r.byteOffset,byteLength:r.byteLength,bufferByteLength:r.buffer.byteLength});const h=Ue(r.length);h.set(r),g=h}return a.data=g,c==="dict"&&(a.dictionary=Ni(u,r,e)),F(a)}function Ai(n,e,t,r){switch(e){case"bool":return v(t);case"dict":return t;case"f32":case"f64":case"i32":case"u32":case"u8":return t*r;default:{const s=e;throw new f("E_COLUMN_TYPE",`column "${n}": a ${s} column cannot adopt a typed array`,{column:n,field:"dtype"})}}}function Ni(n,e,t){const{name:r}=n,s=Bn(n);for(let o=0;o<t;o++){const i=e[o];if(i>=s.size)throw new f("E_COLUMN_TYPE",`column "${r}": code ${i} at row ${o} is outside the ${s.size} declared options`,{column:r,row:o,code:i})}return s.values}function G(n,e,t){if(e!==void 0){if(typeof e!="string"||!t.includes(e))throw new f("E_UNSUPPORTED",`option ${n} has an unsupported value ${Ci(e)}`,{field:n,found:e,reason:"unsupported option"});return e}}function Ci(n){return typeof n=="string"?JSON.stringify(n.length>40?`${n.slice(0,37)}...`:n):typeof n=="number"||typeof n=="boolean"||n===null?String(n):`a ${typeof n}`}const Wt=["first","last","sum","min","max"],Li=[...Wt,"mean","count","drop"];function ge(n){if(typeof n=="number")return String(n);if(typeof n=="string"){const e=n.length>40?`${n.slice(0,37)}...`:n;return JSON.stringify(e)}return n===null?"null":typeof n=="bigint"?`${String(n)}n`:`a value of type ${typeof n}`}function be(n){if(typeof n=="number"){if(!Number.isFinite(n))throw new f("E_INVALID_ID",`invalid node id ${String(n)}: not a finite number`,{id:n,reason:"non-finite"});return n===0?0:n}if(typeof n=="string"){if(ss(n))throw new f("E_INVALID_ID",`invalid node id ${ge(n)}: lone surrogate`,{id:n,reason:"lone surrogate"});return n}throw new f("E_INVALID_ID",`invalid node id: ${ge(n)} is not a string or a number`,{reason:"unsupported type",type:typeof n})}const Xt=new WeakMap;function $i(n){const e=Xt.get(n);if(e===void 0)throw new f("E_UNSUPPORTED","not a NodeIdMap of this package",{reason:"foreign id map"});return e}function se(n,e,t={}){return{kind:n,size:e,offset:0,denseValues:null,denseInverse:null,decoded:null,numbers:null,tags:null,strings:null,map:null,stringIndex:null,...t}}function As(n){return n.size===0?!1:n.denseValues!==null&&n.denseValues.length===0||n.decoded===null&&n.numbers!==null&&n.numbers.length===0||n.decoded===null&&n.tags!==null&&n.tags.length===0||n.decoded===null&&n.strings?.detached===!0}function Oi(n){const e=Xt.get(n);return e!==void 0&&As(e)}function et(n){return n===0?0:n}function Zt(n,e,t){return new f("E_DUPLICATE_ID",`duplicate node id ${ge(n)} at indices ${e} and ${t}`,{id:n,indices:[e,t]})}function Je(n,e){return new f("E_INVALID_SNAPSHOT",`id map violates invariant I11: ${n}`,{invariant:"I11",reason:n,...e})}function ie(n,e,t={}){return new f("E_BAD_SERIALIZATION",`${n}: ${e}`,{ref:n,reason:e,...t})}function Ns(n,e,t){const r=new Uint32Array(e+1).fill(4294967295);for(let s=0;s<n.length;s++){const o=n[s];if(r[o]!==4294967295)throw t(o,r[o],s);r[o]=s}return r}function at(n,e,t){const r=new Map;for(let s=0;s<e;s++){const o=n[s],i=r.get(o);if(i!==void 0)throw t(o,i,s);r.set(o,s)}return r}function _i(n,e){let t=!0,r=!0,s=!0,o=-1,i=0,c=!0;if(e>0){const l=n[0];typeof l=="number"&&Number.isSafeInteger(l)?i=l:c=!1}for(let l=0;l<e;l++){const u=n[l];typeof u=="number"?(r=!1,c&&u!==l+i&&(c=!1),s&&(Number.isInteger(u)&&u>=0&&u<4294967294?u>o&&(o=u):s=!1)):(t=!1,c=!1,s=!1)}return t||(o=-1),{allNumbers:t,allStrings:r,identity:c,offset:i,allDenseIntegers:s,maxId:o}}function Di(n,e){return e===0||n.identity?"identity":n.allDenseIntegers&&n.maxId+1<=2*e?"dense":n.allNumbers?"numeric":n.allStrings?"string":"mixed"}function Ti(n,e){const t=new Uint32Array(e);for(let r=0;r<e;r++){const s=n[r];t[r]=typeof s=="number"?s:4294967295}return t}class H{constructor(e){this.kind=e.kind,this.size=e.size,this.offset=e.kind==="identity"?e.offset:0,this.storage=e,Xt.set(this,e),Object.freeze(this)}idOf(e){if(!(e>=0&&e<this.size)||!Number.isInteger(e))throw new f("E_INDEX_RANGE",`node index ${e} out of range (size ${this.size})`,{index:e,size:this.size});return this.idAt(e)}indexOf(e){const{storage:t}=this;switch(t.kind){case"identity":{if(typeof e!="number")return 4294967295;const r=e-t.offset;return!Number.isInteger(r)||r<0||r>=t.size?4294967295:r===0?0:r}case"dense":{const r=t.denseInverse;return typeof e!="number"||!Number.isInteger(e)||e<0||e>=r.length?4294967295:r[e]}case"numeric":case"string":case"mixed":{const r=this.reverseMap().get(e);return r===void 0||r>=t.size?4294967295:r}default:throw new f("E_UNSUPPORTED",`unknown id map kind ${String(t.kind)}`,{kind:t.kind})}}has(e){return this.indexOf(e)!==4294967295}requireIndex(e){const t=this.indexOf(e);if(t===4294967295)throw new f("E_UNKNOWN_NODE",`unknown node id ${ge(e)}`,{id:e});return t}indicesOf(e,t="invalid"){G("onMissing",t,["invalid","throw"]);const r=t==="throw"?i=>this.requireIndex(i):i=>this.indexOf(i);if(Array.isArray(e)){const i=e,c=new Uint32Array(i.length);for(let l=0;l<i.length;l++)c[l]=r(i[l]);return c}let s=new Uint32Array(16),o=0;for(const i of e){if(o===s.length){const c=new Uint32Array(s.length*2);c.set(s),s=c}s[o++]=r(i)}return s.slice(0,o)}idsSlice(e=0,t=this.size){const[r,s]=is(e,t,this.size),{storage:o}=this;switch(this.assertAttached(),o.kind){case"identity":{const i=new Array(s-r);for(let c=r;c<s;c++)i[c-r]=c+o.offset;return i}case"dense":return Array.from(o.denseValues.subarray(r,s));case"numeric":return o.decoded!==null?o.decoded.slice(r,s):Array.from(o.numbers.subarray(r,s),et);case"string":return o.strings.slice(r,s);case"mixed":{if(o.decoded!==null)return o.decoded.slice(r,s);const i=o.tags,c=o.numbers,l=o.strings,u=new Array(s-r);for(let a=r;a<s;a++)u[a-r]=i[a]===0?et(c[a]):l.at(a);return u}default:throw new f("E_UNSUPPORTED",`unknown id map kind ${String(o.kind)}`,{kind:o.kind})}}toArray(){return this.idsSlice(0,this.size)}*[Symbol.iterator](){for(let e=0;e<this.size;e++)yield this.idAt(e)}toMap(e){const t=new Map;for(let r=0;r<this.size;r++)t.set(this.idAt(r),e[r]);return t}toStringMap(e){const t=new Map;for(let r=0;r<this.size;r++)t.set(String(this.idAt(r)),e[r]);return t}toRecord(e){const t=Object.create(null);for(let r=0;r<this.size;r++)t[String(this.idAt(r))]=e[r];return t}*entries(e){for(let t=0;t<this.size;t++)yield[this.idAt(t),e[t]]}stringIndex(){const{storage:e}=this;if(e.stringIndex===null){const t=new Map;for(let r=0;r<e.size;r++){const s=this.idAt(r),o=String(s);(typeof s=="string"||!t.has(o))&&t.set(o,r)}e.stringIndex=t}return e.stringIndex}byteLength(){const{storage:e}=this;let t=0;return e.denseValues!==null&&(t+=e.denseValues.byteLength),e.denseInverse!==null&&(t+=e.denseInverse.byteLength),e.numbers!==null&&(t+=e.numbers.byteLength),e.tags!==null&&(t+=e.tags.byteLength),e.strings!==null&&(t+=e.strings.byteLength()),t}idAt(e){const{storage:t}=this;switch(this.assertAttached(),t.kind){case"identity":return e+t.offset;case"dense":return t.denseValues[e];case"numeric":return t.decoded!==null?t.decoded[e]:et(t.numbers[e]);case"string":return t.strings.at(e);case"mixed":return t.decoded!==null?t.decoded[e]:t.tags[e]===0?et(t.numbers[e]):t.strings.at(e);default:throw new f("E_UNSUPPORTED",`unknown id map kind ${String(t.kind)}`,{kind:t.kind})}}assertAttached(){if(As(this.storage))throw new f("E_DETACHED","the id map's storage was transferred away",{kind:this.storage.kind})}reverseMap(){const{storage:e}=this;if(e.map===null){this.assertAttached(),e.decoded===null&&e.strings!==null&&e.strings.materialiseDecoded();const t=new Map;for(let r=0;r<e.size;r++)t.set(this.idAt(r),r);e.map=t}return e.map}}function Cs(n,e=0){if(!Number.isInteger(n)||n<0||n>4294967294)throw new f("E_TOO_LARGE",`node count ${n} is not an integer in [0, MAX_COUNT]`,{count:n,max:4294967294});if(!Number.isSafeInteger(e))throw new f("E_INVALID_ID",`identity offset ${e} is not a safe integer`,{offset:e,reason:"non-integer offset"});return new H(se("identity",n,{offset:e}))}function Ls(n,e=n.length,t={}){if(!Number.isInteger(e)||e<0||e>4294967294)throw new f("E_TOO_LARGE",`node count ${e} is not an integer in [0, MAX_COUNT]`,{count:e,max:4294967294});const r=t.map!==void 0||t.validate===!1;let s=n;if(!r){const c=new Array(e);for(let l=0;l<e;l++)c[l]=be(n[l]);s=c}const o=_i(s,e),i=Di(o,e);switch(i){case"identity":return new H(se("identity",e,{offset:e===0?0:o.offset}));case"dense":{const c=Ti(s,e),l=Ns(c,o.maxId,Zt);return new H(se("dense",e,{denseValues:c,denseInverse:l}))}case"numeric":case"mixed":{const c=t.map??(r?null:at(s,e,Zt));return new H(se(i,e,{decoded:s,map:c}))}case"string":{const c=t.map??(r?null:at(s,e,Zt)),l=Le.fromStrings(s,e);return new H(se("string",e,{strings:l,map:c}))}default:throw new f("E_UNSUPPORTED",`unknown id map kind ${String(i)}`,{kind:i})}}function ki(n){const e=Xt.get(n),t=new Set;if(e===void 0)return[];for(const r of[e.denseValues,e.denseInverse,e.numbers,e.tags])r!==null&&t.add(r.buffer);return e.strings?.encoded&&(t.add(e.strings.offsets.buffer),t.add(e.strings.utf8.buffer)),[...t]}function vi(n,e="structure"){const{kind:t,size:r}=n;if(e!=="none"&&(!Number.isInteger(r)||r<0||r>4294967294))throw ie("ids.size",`size ${r} is not an integer in [0, MAX_COUNT]`,{found:r});switch(t){case"identity":return xi(n,e);case"dense":return Si(n,e);case"numeric":return Ui(n,e);case"string":return Pi(n,e);case"mixed":return Ri(n,e);default:throw new f("E_UNSUPPORTED",`unknown id map kind ${String(t)}`,{kind:t})}}function Xn(n,e,t){return Je(`duplicate id ${ge(n)}`,{id:n,indices:[e,t]})}function Ut(n,e,t,r){if(t!==r)throw ie(n,`expected ${r} ${e}, found ${t}`,{expected:r,found:t})}function $s(n){const e=n.firstMalformedRow();if(e!==-1)throw Je(`malformed UTF-8 in id at index ${e}`,{index:e})}function xi(n,e){const{offset:t,size:r}=n;if(!Number.isSafeInteger(t)||r>0&&!Number.isSafeInteger(t+r-1)){const s=`offset ${t} with ${r} ids leaves the safe-integer range`;throw e==="full"?Je(s,{found:t,size:r}):ie("ids.offset",s,{found:t,size:r})}return new H(se("identity",r,{offset:et(t)}))}function Si(n,e){const{values:t,size:r}=n;if(!(t instanceof Uint32Array))throw ie("ids.values","a dense id map needs u32 values");e!=="none"&&Ut("ids.values","values",t.length,r);let s=-1;for(let i=0;i<t.length;i++)t[i]>s&&(s=t[i]);if(s>=4294967294)throw ie("ids.values",`dense id ${s} is not below MAX_COUNT`,{found:s});if(s+1>2*Math.max(r,t.length))throw ie("ids.values",`dense bound violated: max id ${s} with ${r} nodes`,{maxId:s,size:r});const o=Ns(t,s,(i,c,l)=>Je(`duplicate id ${i}`,{id:i,indices:[c,l]}));return new H(se("dense",r,{denseValues:t,denseInverse:o}))}function Ui(n,e){const{values:t,size:r}=n;if(!(t instanceof Float64Array))throw ie("ids.values","a numeric id map needs f64 values");e!=="none"&&Ut("ids.values","values",t.length,r);let s=null;if(e==="full"){for(let o=0;o<r;o++)if(!Number.isFinite(t[o]))throw Je(`non-finite id at index ${o}`,{index:o,id:t[o]});s=at(t,r,Xn)}return new H(se("numeric",r,{numbers:t,map:s}))}function Pi(n,e){const{offsets:t,utf8:r,size:s}=n;if(t===null||r===null)throw ie("ids.offsets","a string id map needs offsets and utf8");e!=="none"&&Dn(t,r,s,"ids.offsets");const o=Le.fromEncoded(t,r);let i=null;return e==="full"&&($s(o),i=at(o.decodeAll(),s,Xn)),new H(se("string",s,{strings:o,map:i}))}function Mi(n,e,t,r,s){Ut("ids.tags","tags",n.length,s),Ut("ids.numbers","numbers",e.length,s);for(let o=0;o<s;o++)if(n[o]>1)throw ie("ids.tags",`tag ${n[o]} at index ${o} is not 0 or 1`,{index:o,found:n[o]});Dn(t,r,s,"ids.offsets")}function Vi(n,e,t,r){const s=new Array(r);for(let o=0;o<r;o++)if(n[o]===0){if(!Number.isFinite(e[o]))throw Je(`non-finite id at index ${o}`,{index:o,id:e[o]});s[o]=e[o]}else s[o]=t.at(o);return s}function Ri(n,e){const{tags:t,numbers:r,offsets:s,utf8:o,size:i}=n;if(t===null||r===null||s===null||o===null)throw ie("ids.tags","a mixed id map needs tags, numbers, offsets and utf8");e!=="none"&&Mi(t,r,s,o,i);const c=Le.fromEncoded(s,o);let l=null;return e==="full"&&($s(c),l=at(Vi(t,r,c,i),i,Xn)),new H(se("mixed",i,{tags:t,numbers:r,strings:c,map:l}))}function Bi(n){const e=$i(n),{kind:t,size:r}=e;switch(t){case"identity":return{kind:t,size:r,offset:e.offset,values:null,tags:null,numbers:null,offsets:null,utf8:null};case"dense":return{kind:t,size:r,offset:0,values:e.denseValues,tags:null,numbers:null,offsets:null,utf8:null};case"numeric":{if(e.numbers===null){const s=e.decoded,o=new Float64Array(r);for(let i=0;i<r;i++){const c=s[i];if(typeof c!="number")throw new f("E_INVALID_ID",`numeric id map holds a ${typeof c} at index ${i}`,{index:i,found:typeof c});o[i]=c}e.numbers=o,M(o.buffer)}return{kind:t,size:r,offset:0,values:e.numbers,tags:null,numbers:null,offsets:null,utf8:null}}case"string":{const s=e.strings;return{kind:t,size:r,offset:0,values:null,tags:null,numbers:null,offsets:s.offsets,utf8:s.utf8}}case"mixed":{if(e.tags===null||e.numbers===null||e.strings===null){const s=e.decoded,o=new Uint8Array(r),i=new Float64Array(r);for(let u=0;u<r;u++){const a=s[u];typeof a=="number"?i[u]=a:o[u]=1}const{offsets:c,utf8:l}=wt(s,r);e.tags=o,e.numbers=i,e.strings=Le.fromEncoded(c,l);for(const u of[o.buffer,i.buffer,c.buffer,l.buffer])M(u)}return{kind:t,size:r,offset:0,values:null,tags:e.tags,numbers:e.numbers,offsets:e.strings.offsets,utf8:e.strings.utf8}}default:throw new f("E_UNSUPPORTED",`unknown id map kind ${String(t)}`,{kind:t})}}function Wi(n,e){const t=e.length,r=new Array(t);for(let s=0;s<t;s++)r[s]=n.idOf(e[s]);return Ls(r,t,{validate:!1})}const Xi=new Set(["string","integer","mixed"]),ji=new Set(["integer","double","date","dateTime"]),Fi=new Set(["interval","timestamp"]),zi=new Set(["static","dynamic","slice"]),Qt=Object.freeze({name:null,description:null,creator:null,created:null,modified:null,keywords:Object.freeze([]),sourceFormat:null,sourceVersion:null,idType:null,timeFormat:null,timeRepresentation:null,mode:null,declaredMultigraph:null,weightOrigin:null,extra:Object.freeze({})});function ze(n,e){return new f("E_COLUMN_TYPE",`meta.${n} has an unsupported value`,{field:n,found:typeof e})}function $e(n,e){if(e===null||typeof e=="string")return e;throw ze(n,e)}function Ct(n,e,t){if(e===null)return null;if(typeof e=="string"&&t.has(e))return e;throw ze(n,e)}function Gi(n){if(n===null)return null;if(typeof n!="object")throw ze("weightOrigin",n);const e=n,t=r=>{const s=e[r];if(s==null)return null;if(typeof s!="string")throw ze(`weightOrigin.${r}`,s);return s};return Object.freeze({format:t("format"),id:t("id"),title:t("title"),type:t("type"),namespace:t("namespace")})}function Yi(n,e){const t=(r,s)=>{const o=e[r];return o===void 0?n[r]:s(o)};return Object.freeze({name:t("name",r=>$e("name",r)),description:t("description",r=>$e("description",r)),creator:t("creator",r=>$e("creator",r)),created:t("created",r=>$e("created",r)),modified:t("modified",r=>$e("modified",r)),keywords:t("keywords",r=>{if(!Array.isArray(r)||r.some(s=>typeof s!="string"))throw ze("keywords",r);return Object.freeze([...r])}),sourceFormat:t("sourceFormat",r=>$e("sourceFormat",r)),sourceVersion:t("sourceVersion",r=>$e("sourceVersion",r)),idType:t("idType",r=>Ct("idType",r,Xi)),timeFormat:t("timeFormat",r=>Ct("timeFormat",r,ji)),timeRepresentation:t("timeRepresentation",r=>Ct("timeRepresentation",r,Fi)),mode:t("mode",r=>Ct("mode",r,zi)),declaredMultigraph:t("declaredMultigraph",r=>{if(r===null||typeof r=="boolean")return r;throw ze("declaredMultigraph",r)}),weightOrigin:t("weightOrigin",r=>Gi(r)),extra:t("extra",r=>B("meta","graph",{dtype:"json",extra:r}).extra)})}const Hi=4294967295;class W{constructor(e,t){this.used=0,this.ctor=e,this.resizable=t?.resizable??Tn,this.backing=this.allocate(t?.capacity??0)}get length(){return this.used}get capacity(){return this.backing.length}get array(){return this.backing}push(e){const t=this.used;return t>=this.backing.length&&(this.backing=lr(this.backing,this.ctor,t+1,this.resizable)),this.backing[t]=e,this.used=t+1,t}pushAll(e){const t=this.used,r=t+e.length;return this.ensureCapacity(r),this.backing.set(e,t),this.used=r,t}get(e){return this.backing[e]}set(e,t){this.backing[e]=t}ensureCapacity(e){e>this.backing.length&&(this.backing=lr(this.backing,this.ctor,e,this.resizable))}resize(e,t=0){e>this.used&&(this.ensureCapacity(e),this.backing.fill(t,this.used,e)),this.used=e}view(){return new this.ctor(this.backing.buffer,0,this.used)}trim(){const e=new this.ctor(new ArrayBuffer(this.used*this.ctor.BYTES_PER_ELEMENT),0,this.used);return e.set(this.view()),e}clear(){this.used=0}release(){this.used=0,this.backing=this.allocate(0)}allocate(e){const t=this.ctor.BYTES_PER_ELEMENT,r=e===0?0:ls(yt(e,gn),t);return new this.ctor(us(r,this.resizable),0,r/t)}}class de{constructor(e){this.bits=0,this.words=new W(Uint32Array,{capacity:v(e?.capacity??0),resizable:e?.resizable})}get length(){return this.bits}push(e){const t=this.bits;return t%32===0&&this.words.push(0),e&&yn(this.words.array,t,!0),this.bits=t+1,t}get(e){return k(this.words.array,e)}set(e,t){yn(this.words.array,e,t)}count(){return xe(this.words.array,this.bits)}resize(e,t=!1){const r=this.bits;this.words.resize(v(e),0),e<r?vn(this.words.array,e):t&&e>r&&this.setRange(r,e),this.bits=e}setRange(e,t){const{array:r}=this.words;let s=e;for(;s<t&&s%32!==0;)K(r,s++);const o=t-t%32;for(s<o&&(r.fill(Hi,s/32,o/32),s=o);s<t;)K(r,s++)}view(){return this.words.view()}trim(){return this.words.trim()}clear(){this.bits=0,this.words.clear()}release(){this.bits=0,this.words.release()}}const qi=Object.freeze([]),en=2**24;function mn(n){if(n>en)throw new f("E_TOO_LARGE",`node count ${n} exceeds the ${en} nodes with explicit ids one builder can hold`,{count:n,max:en})}function re(n,e,t,r){return new f("E_COLUMN_TYPE",`row ${e} of ${n.dtype} column "${n.name}": ${t}`,{column:n.name,domain:n.domain,row:e,found:r})}function pn(n){const e=Bt(n);if(e===null)throw new f("E_COLUMN_TYPE","an unset value cannot start an inferred column",{reason:"unset"});return e}function bn(n){switch(n){case"bool":return"bool";case"i32":case"u8":return"i32";case"u32":case"f32":case"f64":return"f64";case"dict":case"string":return"string";case"list":case"json":return"json";default:{const e=n;throw new f("E_COLUMN_TYPE",`unknown dtype ${e}`,{dtype:e})}}}function Ji(n,e,t){const r=n.itemDtype,s=n.itemComponents??1;switch(r){case"f32":case"f64":case"i32":case"u32":case"u8":Ki(n,e,t,r,s);return;case"bool":if(typeof t!="boolean")throw re(n,e,"list item is not a boolean",typeof t);return;case"dict":case"string":if(typeof t!="string")throw re(n,e,"list item is not a string",typeof t);Se(t,{column:n.name,row:e});return;case"json":oe(t,n.name);return;default:{const o=r;throw new f("E_COLUMN_TYPE",`unknown dtype ${o}`,{dtype:o})}}}function Ki(n,e,t,r,s){if(s===1){if(typeof t!="number"||!Pe(r,t))throw re(n,e,`list item is not a representable ${r}`,typeof t);return}if(!Array.isArray(t)||t.length!==s)throw re(n,e,`list item is not ${s} numbers`,typeof t);for(const o of t)if(typeof o!="number"||!Pe(r,o))throw re(n,e,`list item component is not a representable ${r}`,typeof o)}class jt{constructor(e,t,r,s){this.length=0,this.typed=null,this.bits=null,this.values=null,this.dictionary=null,this.validity=null,this.meta=e,this.resizable=r,t?(this.inferrer=new dr,this.inferrer.widenTo(bn(e.dtype))):this.inferrer=null,this.allocate(s)}get inferred(){return this.inferrer!==null}get inferredDtype(){return this.inferrer===null?null:this.inferrer.dtype}ensureLength(e){if(e<=this.length)return;const{meta:t}=this;if(this.typed!==null)this.typed.resize(e*t.components,this.fillNumber());else if(this.bits!==null)this.bits.resize(e,t.fill===!0);else if(this.values!==null){const r=this.fillValue();for(let s=this.length;s<e;s++)this.values.push(r)}this.validity!==null&&this.validity.resize(e,!1),this.length=e}isSet(e){return e>=this.length?!1:this.validity===null||this.validity.get(e)}write(e,t){if(this.ensureLength(e+1),t===void 0||t===null&&(this.inferrer!==null||this.meta.dtype!=="json"))return this.unset(e),null;let r=null;if(this.inferrer!==null){const s=this.meta.dtype;if(this.inferrer.observeValue(t)){const o=this.inferrer.dtype;this.widenTo(o),r={from:s,to:o}}this.storeRaw(e,t)}else this.store(e,t);return this.validity!==null&&this.validity.set(e,!0),r}checkValue(e,t){if(t===void 0||t===null&&(this.inferrer!==null||this.meta.dtype!=="json")){if(this.validity===null)throw this.unsetError(e);return}if(this.inferrer!==null){Bt(t),this.checkRaw(e,t);return}this.coerce(e,t)}unset(e){if(this.ensureLength(e+1),this.validity===null)throw this.unsetError(e);this.validity.set(e,!1),this.writeFill(e)}unsetError(e){return new f("E_COLUMN_TYPE",`row ${e} of non-nullable column "${this.meta.name}" cannot be unset`,{column:this.meta.name,row:e,field:"nullable"})}read(e){if(!this.isSet(e))return;if(this.inferrer!==null)return je(this.values[e],this.inferrer.dtype);const{meta:t}=this,{dtype:r,components:s}=t;switch(r){case"f32":case"f64":case"i32":case"u32":case"u8":{const o=this.typed;if(s===1)return o.get(e);const i=new Array(s);for(let c=0;c<s;c++)i[c]=o.get(e*s+c);return i}case"bool":return this.bits.get(e);case"dict":{const o=this.typed.get(e);return this.dictionary.values[o]}case"string":case"list":case"json":return this.values[e];default:{const o=r;throw new f("E_COLUMN_TYPE",`unknown dtype ${o}`,{dtype:o})}}}widenTo(e){const{meta:t}=this,r=B(t.name,t.domain,{dtype:e,nullable:!0,role:t.role??void 0,extra:t.extra});if(this.inferrer!==null){this.inferrer.widenTo(e),this.meta=r;return}const s=this.length,o=new Array(s),i=new de({capacity:s,resizable:this.resizable});i.resize(s,!1);for(let c=0;c<s;c++)this.isSet(c)&&(o[c]=this.read(c),i.set(c,!0));this.meta=r,this.inferrer=new dr,this.inferrer.widenTo(e),this.typed=null,this.bits=null,this.dictionary=null,this.values=o,this.validity=i}gather(e,t){const r=e===null?this.length:e.length,s=new jt(this.meta,this.inferred,this.resizable,this.dictionary??void 0);s.ensureLength(r);const{components:o}=this.meta,i=t!==null&&this.meta.refersTo!==null;for(let c=0;c<r;c++){const l=e===null?c:e[c];if(this.isSet(l)){if(s.typed!==null&&this.typed!==null)if(i){const u=mr(this.typed.get(l),t);if(u===4294967295){s.unsetDangling(c);continue}s.typed.set(c,u)}else for(let u=0;u<o;u++)s.typed.set(c*o+u,this.typed.get(l*o+u));else if(s.bits!==null&&this.bits!==null)s.bits.set(c,this.bits.get(l));else if(s.values!==null&&this.values!==null){let u=this.values[l];if(i){const a=u,d=[];for(const g of a){const h=mr(g,t);h!==4294967295&&d.push(h)}if(d.length===0&&a.length>0){s.unsetDangling(c);continue}u=d}s.values[c]=u}s.validity!==null&&s.validity.set(c,!0)}}return s}unsetDangling(e){if(this.validity!==null)return;const{meta:t}=this;this.meta=B(t.name,t.domain,{...he(t),nullable:!0});const r=new de({capacity:this.length,resizable:this.resizable});r.resize(this.length,!1);const{typed:s}=this;for(let o=0;o<e;o++)s?.get(o)!==4294967295&&r.set(o,!0);this.validity=r}toColumn(e){this.ensureLength(e);const{meta:t}=this,{dtype:r,components:s}=t;if(this.inferrer!==null){const c=this.values,l=new Array(e);for(let u=0;u<e;u++)l[u]=this.isSet(u)?c[u]:void 0;return ut(t,l)}let o=null;this.validity!==null&&this.validity.count()!==e&&(o=this.validity.trim());const i={meta:t,length:e,data:null,validity:o,nullCount:o===null?0:e-this.validity.count(),dictionary:null,offsets:null,utf8:null,strings:null,child:null,values:null};switch(r){case"f32":case"f64":case"i32":case"u32":case"u8":{const c=Is(r,e*s);return c.set(this.typed.view().subarray(0,e*s)),i.data=c,t.refersTo!==null&&this.validity===null&&Zi(i,c,e),F(i)}case"bool":return i.data=this.bits.trim(),F(i);case"dict":{const c=new Uint32Array(e);return c.set(this.typed.view().subarray(0,e)),i.data=c,i.dictionary=[...this.dictionary.values],F(i)}case"string":case"list":case"json":{const c=this.values,l=new Array(e);for(let u=0;u<e;u++){const a=this.isSet(u)?c[u]:void 0;l[u]=a===void 0?this.unsetEntry():a}return ut(t,l)}default:{const c=r;throw new f("E_COLUMN_TYPE",`unknown dtype ${c}`,{dtype:c})}}}byteLength(){let e=0;return this.typed!==null&&(e+=this.typed.array.byteLength),this.bits!==null&&(e+=v(this.bits.length)*4),this.validity!==null&&(e+=v(this.validity.length)*4),e}allocate(e){const{meta:t}=this,{dtype:r}=t,s={resizable:this.resizable};if(this.inferrer!==null){this.values=[],this.validity=new de(s);return}switch(r){case"f32":this.typed=new W(Float32Array,s);break;case"f64":this.typed=new W(Float64Array,s);break;case"i32":this.typed=new W(Int32Array,s);break;case"u32":this.typed=new W(Uint32Array,s);break;case"u8":this.typed=new W(Uint8Array,s);break;case"bool":this.bits=new de(s);break;case"dict":{this.typed=new W(Uint32Array,s),this.dictionary=e??Bn(t);break}case"string":case"list":case"json":this.values=[];break;default:{const o=r;throw new f("E_COLUMN_TYPE",`unknown dtype ${o}`,{dtype:o})}}this.validity=t.nullable?new de(s):null}fillNumber(){const{meta:e}=this;if(e.dtype==="dict"){const t=this.dictionary,r=typeof e.fill=="string"?e.fill:"";if(this.validity===null)return t.intern(r);const s=t.codeOf(r);return s===4294967295?0:s}return typeof e.fill=="number"?e.fill:0}fillValue(){if(this.inferrer===null)switch(this.meta.dtype){case"string":return typeof this.meta.fill=="string"?this.meta.fill:"";case"list":return qi;default:return}}unsetEntry(){if(!this.meta.nullable)return this.meta.dtype==="json"?null:this.fillValue()}writeFill(e){const{components:t}=this.meta;if(this.typed!==null){const r=this.fillNumber();for(let s=0;s<t;s++)this.typed.set(e*t+s,r)}else this.bits!==null?this.bits.set(e,this.meta.fill===!0):this.values!==null&&(this.values[e]=this.fillValue())}storeRaw(e,t){this.checkRaw(e,t),this.values[e]=typeof t=="string"?nt(t):t}checkRaw(e,t){const{meta:r}=this;typeof t=="string"?Se(t,{column:r.name,row:e}):typeof t=="object"&&oe(t,`${r.name}[${e}]`)}store(e,t){this.put(e,this.coerce(e,t))}coerce(e,t){const{meta:r}=this,{dtype:s,components:o}=r;switch(s){case"f32":case"f64":case"i32":case"u32":case"u8":{const i=typeof t=="boolean"?Number(t):t;if(typeof i=="number"){if(!Pe(s,i))throw re(r,e,`${i} is not representable`,i);return i}if(o===1||!ps(i,o))throw re(r,e,`not ${o} number(s)`,typeof i);for(let c=0;c<o;c++)if(!Pe(s,i[c]))throw re(r,e,`${i[c]} is not representable`,i[c]);return i}case"bool":return je(t,"bool")===!0;case"dict":case"string":{const i=je(t,"string");if(typeof i!="string")throw re(r,e,"not a string",typeof t);return Se(i,{column:r.name,row:e}),nt(i)}case"list":{if(!Array.isArray(t))throw re(r,e,"not an array",typeof t);for(const i of t)Ji(r,e,i);return t.map(i=>typeof i=="string"?nt(i):i)}case"json":return oe(t,`${r.name}[${e}]`),t;default:{const i=s;throw new f("E_COLUMN_TYPE",`unknown dtype ${i}`,{dtype:i})}}}put(e,t){const{dtype:r,components:s}=this.meta;switch(r){case"f32":case"f64":case"i32":case"u32":case"u8":{const o=this.typed;if(typeof t=="number"){if(s===1)o.set(e,t);else for(let c=0;c<s;c++)o.set(e*s+c,t);return}const i=t;for(let c=0;c<s;c++)o.set(e*s+c,i[c]);return}case"bool":this.bits.set(e,t===!0);return;case"dict":this.typed.set(e,this.dictionary.intern(t));return;case"string":case"list":case"json":this.values[e]=t;return;default:{const o=r;throw new f("E_COLUMN_TYPE",`unknown dtype ${o}`,{dtype:o})}}}}function mr(n,e){return n<e.length?e[n]:4294967295}function Zi(n,e,t){let r=null;for(let s=0;s<t;s++)e[s]===4294967295&&(r??=ye(t,!0),Z(r,s),n.nullCount++);if(r!==null){const{meta:s}=n;n.meta=B(s.name,s.domain,{...he(s),nullable:!0}),n.validity=r}}function Xe(n,e,t,r,s){return new jt(B(n,e,t),r,s)}class pr{constructor(e,t){this.lists=e,this.alive=t,this.found=[],this.list=0,this.edge=e[0][0]}step(){for(;this.edge===4294967295;){if(this.list++,this.list===this.lists.length)return!0;this.edge=this.lists[this.list][0]}const[,e,t,r]=this.lists[this.list];return this.alive.get(this.edge)&&t.get(this.edge)===r&&this.found.push(this.edge),this.edge=e.get(this.edge),!1}}class In{constructor(e){this.ids=null,this.idToIndex=null,this.weight=null,this.weightSet=null,this.weightMode="none",this.liveNodeCount=0,this.liveEdgeCount=0,this.selfLoopCount=0,this.nodeColumns=[],this.edgeColumns=[],this.extensions=[],this.options=e;const{resizable:t}=e,r=e.expectedNodes??0,s=e.expectedEdges??0;this.nodeAlive=new de({capacity:r,resizable:t}),this.firstOut=new W(Uint32Array,{capacity:r,resizable:t}),this.firstIn=new W(Uint32Array,{capacity:r,resizable:t}),this.src=new W(Uint32Array,{capacity:s,resizable:t}),this.dst=new W(Uint32Array,{capacity:s,resizable:t}),this.edgeAlive=new de({capacity:s,resizable:t}),this.nextOut=new W(Uint32Array,{capacity:s,resizable:t}),this.nextIn=new W(Uint32Array,{capacity:s,resizable:t}),e.weighted&&(this.weight=this.allocateWeights(s))}get nodeBound(){return this.nodeAlive.length}get edgeBound(){return this.edgeAlive.length}get hasTombstones(){return this.liveNodeCount<this.nodeBound||this.liveEdgeCount<this.edgeBound}reserve(e,t){e>0&&(this.firstOut.ensureCapacity(e),this.firstIn.ensureCapacity(e)),t>0&&(this.src.ensureCapacity(t),this.dst.ensureCapacity(t),this.nextOut.ensureCapacity(t),this.nextIn.ensureCapacity(t),this.weight!==null&&this.weight.ensureCapacity(t))}materialiseIds(){if(this.ids!==null&&this.idToIndex!==null)return;const e=this.nodeBound;mn(e);const t=new Array(e),r=new Map;for(let s=0;s<e;s++)t[s]=s,r.set(s,s);this.ids=t,this.idToIndex=r}pushNode(e){this.idToIndex!==null&&mn(this.idToIndex.size+1);const t=this.nodeAlive.push(!0);if(this.firstOut.push(4294967295),this.firstIn.push(4294967295),this.ids!==null&&this.idToIndex!==null){const r=e??t;this.ids.push(r),this.idToIndex.set(r,t)}return this.liveNodeCount++,t}pushAnonymousNodes(e){if(this.idToIndex!==null){for(let r=0;r<e;r++)this.pushNode(null);return}const t=this.nodeBound+e;this.nodeAlive.resize(t,!0),this.firstOut.resize(t,4294967295),this.firstIn.resize(t,4294967295),this.liveNodeCount+=e}ensureWeights(){return this.weight===null&&(this.weight=this.allocateWeights(this.edgeBound),this.weight.resize(this.edgeBound,1)),this.weight}trackWeight(e,t){if(this.weightSet!==null){e>=this.weightSet.length&&this.weightSet.resize(e+1,!1),this.weightSet.set(e,t);return}switch(this.weightMode){case"none":this.weightMode=t?"explicit":"omitted";return;case"explicit":t||this.allocateWeightSet(!0,e);return;case"omitted":t&&this.allocateWeightSet(!1,e);return;case"mixed":return;default:{const r=this.weightMode;throw new f("E_UNSUPPORTED",`unknown weight mode ${r}`,{mode:r})}}}weightExplicit(e){return this.weightSet===null?this.weightMode==="explicit":e<this.weightSet.length&&this.weightSet.get(e)}pushEdge(e,t,r){const s=this.src.push(e);return this.dst.push(t),r!==void 0?this.ensureWeights().push(r):this.weight!==null&&this.weight.push(1),this.trackWeight(s,r!==void 0),this.edgeAlive.push(!0),this.nextOut.push(this.firstOut.get(e)),this.firstOut.set(e,s),this.nextIn.push(this.firstIn.get(t)),this.firstIn.set(t,s),this.liveEdgeCount++,e===t&&this.selfLoopCount++,s}pushEdges(e,t,r){const s=e.length,o=this.edgeBound,i=o+s;return s===0||(this.src.pushAll(e),this.dst.pushAll(t),r!==null?this.ensureWeights().pushAll(r):this.weight!==null&&this.weight.resize(i,1),this.trackWeights(o,s,r!==null),this.edgeAlive.resize(i,!0),this.nextOut.resize(i),this.nextIn.resize(i),this.selfLoopCount+=ec(this.src.array,this.dst.array,o,i,{firstOut:this.firstOut.array,firstIn:this.firstIn.array,nextOut:this.nextOut.array,nextIn:this.nextIn.array}),this.liveEdgeCount+=s),o}trackWeights(e,t,r){const s=e+t;let o=this.weightSet;if(o===null)switch(this.weightMode){case"none":this.weightMode=r?"explicit":"omitted";return;case"explicit":if(r)return;o=this.allocateWeightSet(!0,e);break;case"omitted":if(!r)return;o=this.allocateWeightSet(!1,e);break;case"mixed":return;default:{const i=this.weightMode;throw new f("E_UNSUPPORTED",`unknown weight mode ${i}`,{mode:i})}}o.length<e&&o.resize(e,!1),o.resize(s,r)}killEdge(e){this.edgeAlive.set(e,!1),this.liveEdgeCount--,this.src.get(e)===this.dst.get(e)&&this.selfLoopCount--}outEdges(e){const t=[];for(let r=this.firstOut.get(e);r!==4294967295;r=this.nextOut.get(r))this.edgeAlive.get(r)&&t.push(r);return Uint32Array.from(t).sort()}inEdges(e){const t=[];for(let r=this.firstIn.get(e);r!==4294967295;r=this.nextIn.get(r))this.edgeAlive.get(r)&&t.push(r);return Uint32Array.from(t).sort()}incidentEdges(e){const t=[];for(let r=this.firstOut.get(e);r!==4294967295;r=this.nextOut.get(r))this.edgeAlive.get(r)&&t.push(r);for(let r=this.firstIn.get(e);r!==4294967295;r=this.nextIn.get(r))this.edgeAlive.get(r)&&this.src.get(r)!==e&&t.push(r);return Uint32Array.from(t).sort()}edgesBetween(e,t,r){const s=(a,d)=>[this.firstOut.get(a),this.nextOut,this.dst,d],o=(a,d)=>[this.firstIn.get(a),this.nextIn,this.src,d],i=r||e===t?[s(e,t)]:[s(e,t),o(e,t)],c=r?[o(t,e)]:[s(t,e),o(t,e)],l=new pr(i,this.edgeAlive),u=e===t?l:new pr(c,this.edgeAlive);for(;;){if(l.step())return Uint32Array.from(l.found).sort();if(u.step())return Uint32Array.from(u.found).sort()}}byteLength(){let e=this.firstOut.array.byteLength+this.firstIn.array.byteLength+this.src.array.byteLength+this.dst.array.byteLength+this.nextOut.array.byteLength+this.nextIn.array.byteLength+v(this.nodeAlive.length)*4+v(this.edgeAlive.length)*4;this.weight!==null&&(e+=this.weight.array.byteLength),this.weightSet!==null&&(e+=v(this.weightSet.length)*4);for(const t of this.nodeColumns)e+=t.byteLength();for(const t of this.edgeColumns)e+=t.byteLength();for(const t of this.extensions)for(const r of t.columns)e+=r.byteLength();return e}allocateWeights(e){const{resizable:t}=this.options;return this.options.weightDtype==="f64"?new W(Float64Array,{capacity:e,resizable:t}):new W(Float32Array,{capacity:e,resizable:t})}allocateWeightSet(e,t){const r=new de({capacity:t+1,resizable:this.options.resizable});return r.resize(t,e),r.push(!e),this.weightSet=r,this.weightMode="mixed",r}}function br(n,e){const t=new Uint32Array(n);let r=0;for(let o=0;o<n;o++)(e[o>>>5]>>>(o&31)&1)===1?t[o]=r++:t[o]=4294967295;const s=new Uint32Array(r);for(let o=0;o<n;o++){const i=t[o];i!==4294967295&&(s[i]=o)}return{remap:t,origin:s,count:r}}function Qi(n){const e=n.length,t=new Uint32Array(e);let r=0;for(let o=0;o<e;o++)n[o]===o?t[o]=r++:t[o]=4294967295;const s=new Uint32Array(r);for(let o=0;o<e;o++){const i=t[o];i!==4294967295&&(s[i]=o)}return{remap:t,origin:s,count:r}}function ec(n,e,t,r,s){const{firstOut:o,firstIn:i,nextOut:c,nextIn:l}=s;let u=0;for(let a=t;a<r;a++){const d=n[a],g=e[a];c[a]=o[d],o[d]=a,l[a]=i[g],i[g]=a,d===g&&u++}return u}function tc(n,e,t,r,s,o,i){const{firstOut:c,firstIn:l,nextOut:u,nextIn:a}=i,d=t.length;let g=0;for(let h=0;h<d;h++){const y=t[h],w=r[n[y]],m=r[e[y]];s[h]=w,o[h]=m,u[h]=c[w],c[w]=h,a[h]=l[m],l[m]=h,w===m&&g++}return g}function nc(n,e,t){const r=e.length;for(let s=0;s<r;s++)t[s]=n[e[s]]}function rc(n,e,t,r){for(let s=0;s<r;s++)k(e,s)&&(t[s]=n[s])}function Ir(n,e){const{nodes:t,edges:r}=e,s=new In({...n.options,weighted:n.weight!==null||e.mergedWeights!==null,expectedNodes:t.count,expectedEdges:r.count});if(s.nodeAlive.resize(t.count,!0),s.firstOut.resize(t.count,4294967295),s.firstIn.resize(t.count,4294967295),s.liveNodeCount=t.count,n.ids!==null){const u=new Array(t.count),a=new Map;for(let d=0;d<t.count;d++){const g=n.ids[t.origin[d]];u[d]=g,a.set(g,d)}s.ids=u,s.idToIndex=a}const{remap:o}=t,i=r.count,{origin:c}=r;if(s.weightMode=n.weightMode,(n.weightSet!==null||e.mergedWeightSet!==null)&&(s.weightSet=new de({capacity:i,resizable:n.options.resizable}),s.weightMode="mixed"),s.src.resize(i),s.dst.resize(i),s.nextOut.resize(i),s.nextIn.resize(i),s.edgeAlive.resize(i,!0),s.liveEdgeCount=i,s.selfLoopCount=tc(n.src.array,n.dst.array,c,o,s.src.array,s.dst.array,{firstOut:s.firstOut.array,firstIn:s.firstIn.array,nextOut:s.nextOut.array,nextIn:s.nextIn.array}),s.weight!==null){s.weight.resize(i);const u=s.weight.array;n.weight===null?u.fill(1,0,i):nc(n.weight.array,c,u),e.mergedWeights!==null&&e.mergedWeightStored!==null&&rc(e.mergedWeights,e.mergedWeightStored,u,i)}if(s.weightSet!==null){s.weightSet.resize(i,!1);for(let u=0;u<i;u++){let a=n.weightExplicit(c[u]);e.mergedWeightSet!==null&&k(e.mergedWeightSet,u)&&(a=!0),a&&s.weightSet.set(u,!0)}}const l={node:o,edge:e.edgeValues??r.remap};return s.nodeColumns=n.nodeColumns.map(u=>u.gather(t.origin,tn(u,l))),s.edgeColumns=n.edgeColumns.map(u=>u.gather(r.origin,tn(u,l))),s.extensions=n.extensions.map(u=>({name:u.name,rowCount:u.rowCount,columns:u.columns.map(a=>a.gather(null,tn(a,l)))})),s}function tn(n,e){switch(n.meta.refersTo){case"node":return e.node;case"edge":return e.edge;default:return null}}function jn(n){return n instanceof Uint32Array||n instanceof Int32Array||n instanceof Float32Array||n instanceof Float64Array||n instanceof Uint8Array}function sc(n){if(typeof n!="object"||n===null||Array.isArray(n)||jn(n))return!1;const e=n;return typeof e.dtype=="string"&&typeof e.meta=="object"&&typeof e.length=="number"}function oc(n){return n.mutations}function Lt(n){n.sealed=!0}function ic(n){M(n);for(const e of Rn(n))M(e)}class ce{constructor(e){this.mutations=0,this.sealed=!1;const{domain:t,rowCount:r}=e;if(!(Number.isInteger(r)&&r>=0))throw new f("E_COLUMN_LENGTH",`invalid row count ${r} for a ${t} table`,{domain:t,found:r});this.domain=t,this.rowCount=r,this.columns=new Map;for(const s of e.columns){const{name:o}=s.meta;if(this.columns.has(o))throw new f("E_COLUMN_EXISTS",`column "${o}" is declared twice`,{column:o});this.checkColumn(o,s),this.checkRole(o,s.meta.role,!1),this.columns.set(o,s),ic(s)}}names(){return[...this.columns.keys()]}has(e){return this.columns.has(e)}get(e){return this.columns.get(e)??null}require(e){const t=this.columns.get(e);if(t===void 0)throw new f("E_UNKNOWN_COLUMN",`no ${this.domain} column named "${e}"`,{column:e,domain:this.domain});return t}typed(e,t){const r=this.columns.get(e);return r?.dtype!==t?null:r}requireTyped(e,t){const r=this.require(e);if(r.dtype!==t)throw new f("E_COLUMN_TYPE",`column "${e}" is ${r.dtype}, expected ${t}`,{column:e,expected:t,found:r.dtype});return r}byRole(e){for(const t of this.columns.values())if(t.meta.role===e)return t;return null}value(e,t){return this.require(e).value(t)}isSet(e,t){return this.require(e).isSet(t)}set(e,t,r,s){this.assertWritable(e);const o=r??{};let i;if(jn(t)){const l=G("adopt",s?.adopt,["copy","strict"])??"copy";i=Ei(this.domain,this.rowCount,e,t,o,l)}else if(Array.isArray(t))i=Wn(this.domain,this.rowCount,e,t,o);else if(sc(t)){if(!hi(t))throw new f("E_COLUMN_TYPE",`column "${e}": not a Column of this package`,{column:e,reason:"foreign column"});i=this.adoptColumn(e,t,r),i!==t&&Do(t)>0&&Ee(i)}else throw new f("E_COLUMN_TYPE",`column "${e}": unsupported data (${typeof t})`,{column:e,found:typeof t});this.checkRole(e,i.meta.role,s?.replaceRole??!1);const c=this.columns.get(e);if(c!==i&&(M(i),c!==t))for(const l of Rn(i))M(l);return this.columns.set(e,i),this.mutations++,i}remove(e){this.assertWritable(e);const t=this.columns.delete(e);return t&&this.mutations++,t}rename(e,t){this.assertWritable(e);const r=this.require(e);if(e===t)return;if(this.columns.has(t))throw new f("E_COLUMN_EXISTS",`cannot rename "${e}": a column named "${t}" exists`,{column:t});const s=yr(r,B(t,this.domain,he(r.meta)));M(s),Ye(r)&&Ee(s);const o=[...this.columns.entries()];this.columns.clear();for(const[i,c]of o)i===e?this.columns.set(t,s):this.columns.set(i,c);this.mutations++}gpuView(e){return wi(this.require(e))}clone(){return new ce({domain:this.domain,rowCount:this.rowCount,columns:[...this.columns.values()]})}[Symbol.iterator](){return this.columns.values()}adoptColumn(e,t,r){this.checkColumn(e,t);const{meta:s}=t;if(r===void 0&&s.name===e&&s.domain===this.domain)return t;const i={...he(s),...r};return r?.fill===void 0&&(i.fill=s.fill),yr(t,B(e,this.domain,i))}assertWritable(e){if(this.sealed)throw new f("E_FROZEN",`the ${this.domain} table is sealed: its column set cannot change (column "${e}")`,{domain:this.domain,column:e})}checkColumn(e,t){if(t.length!==this.rowCount)throw new f("E_COLUMN_LENGTH",`column "${e}" has ${t.length} rows; the ${this.domain} table has ${this.rowCount}`,{column:e,expected:this.rowCount,found:t.length})}checkRole(e,t,r){if(t!==null){for(const[s,o]of this.columns)if(s!==e&&o.meta.role===t){if(!r)throw new f("E_DUPLICATE_ROLE",`role "${t}" is already held by column "${s}" in the ${this.domain} table`,{role:t,column:e,holder:s});this.columns.delete(s);return}}}}function Er(n,e){const t=n.clone();for(const r of Object.keys(e)){const s=e[r];jn(s)?t.set(r,s):t.set(r,s.data,s.decl)}return t}function cc(n,e){const{dtype:t}=n;switch(t){case"f32":case"f64":case"i32":case"u32":case"u8":return n.meta.components===1?n.data[e]:Array.from(n.data.subarray(e*n.meta.components,(e+1)*n.meta.components)).join(",");case"bool":return k(n.data,e);case"dict":return n.codes[e];case"string":return n.valueAt(e);case"list":return JSON.stringify(n.sliceOf(e));case"json":return JSON.stringify(n.values[e]);default:{const r=t;throw new f("E_COLUMN_TYPE",`unknown dtype ${r}`,{dtype:r})}}}function Os(n){if(!n.meta.unique)return;const e=new Map;for(let t=0;t<n.length;t++){if(!n.isSet(t))continue;const r=cc(n,t),s=e.get(r);if(s!==void 0){const o=n.meta.domain==="edge"?"E_DUPLICATE_EDGE_ID":"E_DUPLICATE_ID";throw new f(o,`column "${n.meta.name}" is unique but rows ${s} and ${t} hold the same value`,{column:n.meta.name,domain:n.meta.domain,rows:[s,t],value:n.value(t)})}e.set(r,t)}}function lc(n){for(const e of n)Os(e)}function Pt(n){return new f("E_COLUMN_TYPE",`column ${JSON.stringify(n.meta.name)} of dtype ${n.dtype} cannot hold edge ids`,{column:n.meta.name,dtype:n.dtype,reason:"edge id dtype"})}function uc(n,e){switch(n.dtype){case"string":return n.valueAt(e);case"dict":return n.dictionary[n.codes[e]];case"f32":case"f64":case"i32":case"u32":case"u8":return n.data[e*n.meta.components];case"bool":case"list":case"json":throw Pt(n);default:throw Pt(n)}}function _s(n){switch(n.dtype){case"string":case"dict":case"f32":case"f64":case"i32":case"u32":case"u8":return!0;case"bool":case"list":case"json":return!1;default:return!1}}function ac(n){if(!_s(n))throw Pt(n);const e=new Map,t=n.length;for(let r=0;r<t;r++){if(!n.isSet(r))continue;const s=uc(n,r);e.has(s)||e.set(s,r)}return e}class dc{constructor(e){if(!_s(e))throw Pt(e);this.column=e,this.map=null,this.builtVersion=-1}get built(){return this.map!==null&&this.builtVersion===this.column.version}get size(){return this.ensure().size}indexOf(e){const t=this.ensure().get(e);return t===void 0?4294967295:t}has(e){return this.ensure().has(e)}ensure(){const{version:e}=this.column;return(this.map===null||this.builtVersion!==e)&&(this.map=ac(this.column),this.builtVersion=e),this.map}}const dt=["rowPtr","colIdx","weights","arcToEdge","edgeToArc"];function fc(n){const e=n.identity?0:n.arcCount,t=n.identity?0:n.edgeCount;return[4*(n.nodeCount+1),4*n.arcCount,n.weighted?4*n.arcCount:0,4*e,4*t]}function hc(n){return{rowPtr:new Uint32Array(n.nodeCount+1),colIdx:new Uint32Array(n.arcCount),weights:n.weighted?new Float32Array(n.arcCount):null,arcToEdge:n.identity?null:new Uint32Array(n.arcCount),edgeToArc:n.identity?null:new Uint32Array(n.edgeCount),arena:null}}function Ds(n){const e=fc(n),t=jo(e,R),r=new ArrayBuffer(t.byteLength),s={rowPtr:null,colIdx:null,weights:null,arcToEdge:null,edgeToArc:null};let o=0;for(let u=0;u<dt.length;u++){const a=t.offsets[u];if(a===null)continue;const d=Object.freeze({byteOffset:a,byteLength:e[u]});s[dt[u]]=d,u<=2&&(o=a+e[u])}const i=(u,a)=>{const d=s[u];return d===null?new Uint32Array(0):new Uint32Array(r,d.byteOffset,a)};let c=null;if(n.weighted){const u=s.weights;c=u===null?new Float32Array(0):new Float32Array(r,u.byteOffset,n.arcCount)}const l=Object.freeze({buffer:r,byteOffset:0,byteLength:t.byteLength,alignment:R,segments:Object.freeze(s),hotByteLength:o});return{rowPtr:i("rowPtr",n.nodeCount+1),colIdx:i("colIdx",n.arcCount),weights:c,arcToEdge:n.identity?null:i("arcToEdge",n.arcCount),edgeToArc:n.identity?null:i("edgeToArc",n.edgeCount),arena:l}}function gc(n,e){return e?Ds(n):hc(n)}function wc(n){return{nodeCount:n.rowPtr.length-1,arcCount:n.colIdx.length,edgeCount:n.edgeToArc===null?n.colIdx.length:n.edgeToArc.length,weighted:n.weights!==null,identity:n.arcToEdge===null}}function yc(n){const e=Ds(wc(n));return e.rowPtr.set(n.rowPtr),e.colIdx.set(n.colIdx),e.weights!==null&&n.weights!==null&&e.weights.set(n.weights),e.arcToEdge!==null&&n.arcToEdge!==null&&e.arcToEdge.set(n.arcToEdge),e.edgeToArc!==null&&n.edgeToArc!==null&&e.edgeToArc.set(n.edgeToArc),e}function Fn(n,e,t,r){let s=e,o=t;for(;s<o;){const i=s+Math.floor((o-s)/2);n[i]<r?s=i+1:o=i}return s}function Ts(n,e,t,r){let s=e,o=t;for(;s<o;){const i=s+Math.floor((o-s)/2);n[i]<=r?s=i+1:o=i}return s}function mc(n,e,t,r){const s=n[t+1],o=Fn(e,n[t],s,r);return o<s&&e[o]===r?o:4294967295}function Ft(n,e,t,r){const s=n[t],o=n[t+1],i=Fn(e,s,o,r),c=Ts(e,i,o,r);return[i,c]}function ks(n,e,t,r){const s=n[t],o=n[t+1],i=Fn(e,s,o,r);return Ts(e,i,o,r)-i}function pc(n,e){let t=0,r=n.length;for(;t<r;){const s=t+Math.floor((r-t)/2);n[s]<=e?t=s+1:r=s}return t-1}function bc(n,e,t){return ks(n,e,t,t)}const vs=1024,xs=32,Ic=1;function En(n){const e=new Uint32Array(n);for(let t=0;t<n;t++)e[t]=t;return e}class ft{constructor(e,t,r,s,o){this.source=e,this.directed=e.directed,this.nodeCount=e.nodeCount,this.arcCount=e.arcCount,this.rowPtr=t,this.colIdx=r,this.weights=s,this.fwdArcCache=o,this.fwdArcIsIdentity=o===null,this.arcToEdgeCache=null,this.arcToEdgeOwned=!1}get fwdArc(){return this.fwdArcCache??=En(this.arcCount),this.fwdArcCache}get arcToEdge(){if(this.arcToEdgeCache===null)if(this.fwdArcIsIdentity)this.arcToEdgeCache=this.source.arcToEdge;else if(this.source.flags.arcToEdgeIsIdentity)this.arcToEdgeCache=this.fwdArc;else{const{fwdArc:e}=this,t=this.source.arcToEdge,r=new Uint32Array(this.arcCount);for(let s=0;s<r.length;s++)r[s]=t[e[s]];this.arcToEdgeCache=r,this.arcToEdgeOwned=!0}return this.arcToEdgeCache}get ownedByteLength(){let e=0;return this.directed&&(e+=this.rowPtr.byteLength+this.colIdx.byteLength,this.weights!==null&&(e+=this.weights.byteLength)),this.fwdArcCache!==null&&(e+=this.fwdArcCache.byteLength),this.arcToEdgeOwned&&this.arcToEdgeCache!==null&&(e+=this.arcToEdgeCache.byteLength),e}materialised(){const e={rowPtr:this.rowPtr,colIdx:this.colIdx};return this.weights!==null&&(e.weights=this.weights),this.fwdArcCache!==null&&(e.fwdArc=this.fwdArcCache),this.arcToEdgeCache!==null&&(e.arcToEdge=this.arcToEdgeCache),e}}function Ec(n){const{nodeCount:e,arcCount:t,rowPtr:r,colIdx:s,weights:o}=n;if(!n.directed)return new ft(n,r,s,o,null);const i=new Uint32Array(e+1);for(let d=0;d<t;d++)i[s[d]+1]++;for(let d=0;d<e;d++)i[d+1]+=i[d];const c=new Uint32Array(t),l=new Uint32Array(t),u=o===null?null:new Float32Array(t),a=i.slice(0,e);for(let d=0;d<e;d++){const g=r[d+1];for(let h=r[d];h<g;h++){const y=s[h],w=a[y]++;c[w]=d,l[w]=h,u!==null&&o!==null&&(u[w]=o[h])}}return new ft(n,i,c,u,l)}function Ss(n,e,t){const r=new Uint32Array(t);for(let s=0;s<e;s++){const o=n[s+1];for(let i=n[s];i<o;i++)r[i]=s}return r}function Ac(n){return Us(n,Ss(n.rowPtr,n.nodeCount,n.arcCount))}function Us(n,e){return Object.freeze({src:e,dst:n.colIdx,weights:n.weights,get arcToEdge(){return n.arcToEdge}})}function Ar(n){const{nodeCount:e,edgeCount:t,arcCount:r,rowPtr:s,colIdx:o,weights:i}=n;if(n.flags.arcToEdgeIsIdentity)return An(n,Ss(s,e,r),o,i);const{arcToEdge:c,edgeToArc:l}=n,u=new Uint32Array(t),a=new Uint32Array(t);for(let g=0;g<e;g++){const h=s[g+1];for(let y=s[g];y<h;y++){const w=c[y];l[w]===y&&(u[w]=g,a[w]=o[y])}}let d=null;if(i!==null){d=new Float32Array(t);for(let g=0;g<t;g++)d[g]=i[l[g]]}return An(n,u,a,d)}function An(n,e,t,r){return Object.freeze({src:e,dst:t,weights:r,get arc(){return n.edgeToArc}})}function Me(n,e){const t=new Uint32Array(e);for(let r=0;r<e;r++)t[r]=n[r+1]-n[r];return t}function Nc(n,e){const t=new Uint32Array(n.length);for(let r=0;r<t.length;r++)t[r]=n[r]+e[r];return t}function Nr(n,e,t){const r=new Float64Array(t);for(let s=0;s<t;s++){const o=n[s+1];let i=0;for(let c=n[s];c<o;c++)i+=e[c];r[s]=i}return r}function Nn(n){return new Float64Array(n)}function Cc(n,e){const t=new Float64Array(n.length);for(let r=0;r<t.length;r++)t[r]=n[r]+e[r];return t}function Lc(n){const{weights:e,edgeCount:t}=n;if(e===null)return t;let r=0;if(n.flags.arcToEdgeIsIdentity){for(let o=0;o<e.length;o++)r+=e[o];return r}const{edgeToArc:s}=n;for(let o=0;o<t;o++)r+=e[s[o]];return r}function $c(n){const{nodeCount:e,rowPtr:t,colIdx:r,selfLoopCount:s}=n,o=new Uint32Array(e),i=new Uint32Array(s);let c=0;for(let l=0;l<e;l++){const[u,a]=Ft(t,r,l,l);o[l]=a-u;for(let d=u;d<a&&c<s;d++)i[c++]=d}return{selfLoopArcs:i,selfLoopsPerNode:o}}function Oc(n,e){const{weights:t,nodeCount:r,rowPtr:s,colIdx:o}=n;if(t===null)return Nn(e.selfLoopsPerNode);const i=new Float64Array(r);for(let c=0;c<r;c++){if(e.selfLoopsPerNode[c]===0)continue;const[l,u]=Ft(s,o,c,c);let a=0;for(let d=l;d<u;d++)a+=t[d];i[c]=a}return i}function _c(n,e,t){return new f("E_INVALID_SNAPSHOT",`invariant I7 violated: arc ${t} in row ${n} targeting ${e} has no mate in row ${e}`,{invariant:"I7",row:n,arc:t,target:e})}function Dc(n){if(n.directed)throw new f("E_DIRECTED","mate() is defined for undirected snapshots only",{directed:!0});const{nodeCount:e,arcCount:t,rowPtr:r,colIdx:s}=n,o=new Uint32Array(t),i=r.slice(0,e);for(let c=0;c<e;c++){const l=r[c+1];let u=i[c];for(;u<l;){const a=s[u];let d=u+1;for(;d<l&&s[d]===a;)d++;const g=d-u;if(a===c)for(let h=0;h<g;h++)o[u+h]=u+h;else{const h=i[a];if(a<c||h+g>r[a+1]||s[h]!==c||s[h+g-1]!==c)throw _c(c,a,u);for(let y=0;y<g;y++)o[u+y]=h+y,o[h+y]=u+y;i[a]=h+g}u=d}i[c]=l}return o}function Cr(n,e){const t=Me(n,e);let r=0;for(let d=0;d<e;d++)t[d]>r&&(r=t[d]);const s=new Uint32Array(r+1);for(let d=0;d<e;d++)s[t[d]]++;let o=0;for(let d=r;d>=0;d--){const g=s[d];s[d]=o,o+=g}const i=new Uint32Array(e);let c=0,l=0,u=0;for(let d=0;d<e;d++){const g=t[d];i[s[g]++]=d,g>=vs?c++:g>=xs?l++:g>=Ic&&u++}const a=new Uint32Array([0,c,c+l,c+l+u,e]);return Object.freeze({perm:i,segmentOffsets:a})}function Tc(n,e){if(!n.directed)return!0;const{nodeCount:t,arcCount:r,rowPtr:s,colIdx:o,weights:i}=n;for(let a=0;a<=t;a++)if(s[a]!==e.rowPtr[a])return!1;const c=e.colIdx;for(let a=0;a<r;a++)if(o[a]!==c[a])return!1;const l=e.weights;if(i===null||l===null)return!0;if(!n.flags.multigraph){for(let a=0;a<r;a++)if(i[a]!==l[a])return!1;return!0}let u=0;for(;u<r;){let a=u+1;for(;a<r&&o[a]===o[u]&&a<s[kc(s,t,u)+1];)a++;if(a-u===1){if(i[u]!==l[u])return!1}else if(!vc(i,l,u,a))return!1;u=a}return!0}function kc(n,e,t){let r=0,s=e;for(;s-r>1;){const o=r+s>>>1;n[o]<=t?r=o:s=o}return r}function vc(n,e,t,r){const s=n.slice(t,r).sort(),o=e.slice(t,r).sort();for(let i=0;i<s.length;i++)if(s[i]!==o[i]&&!(Number.isNaN(s[i])&&Number.isNaN(o[i])))return!1;return!0}function xc(n,e,t){switch(e){case"reverse":return t instanceof ft?t.ownedByteLength:0;case"coo":return t.src.byteLength;case"edgeList":{const r=t;let s=r.src.byteLength;return r.dst!==n.colIdx&&(s+=r.dst.byteLength),r.weights!==null&&r.weights!==n.weights&&(s+=r.weights.byteLength),s}case"outDegree":case"inDegree":case"degree":case"weightedOutDegree":case"weightedInDegree":case"weightedDegree":case"selfLoopWeight":case"selfLoopArcs":case"selfLoopsPerNode":case"mate":return t.byteLength;case"degreeOrder":case"reverseDegreeOrder":{const r=t;return r.perm.byteLength+r.segmentOffsets.byteLength}case"totalWeight":case"symmetric":return 0;default:{const r=e;throw new f("E_UNSUPPORTED",`unknown view ${String(r)}`,{view:r})}}}function zn(n,e,t){switch(e){case"reverse":return t instanceof ft?t.materialised():{};case"coo":return{src:t.src};case"edgeList":{const r=t,s={src:r.src};return r.dst!==n.colIdx&&(s.dst=r.dst),r.weights!==null&&r.weights!==n.weights&&(s.weights=r.weights),s}case"outDegree":case"inDegree":case"degree":case"weightedOutDegree":case"weightedInDegree":case"weightedDegree":case"selfLoopWeight":case"selfLoopArcs":case"selfLoopsPerNode":case"mate":return{data:t};case"degreeOrder":case"reverseDegreeOrder":{const r=t;return{perm:r.perm,segmentOffsets:r.segmentOffsets}}case"totalWeight":case"symmetric":return{};default:{const r=e;throw new f("E_UNSUPPORTED",`unknown view ${String(r)}`,{view:r})}}}function Ps(n,e){return n instanceof Float64Array?new Float64Array(e):n instanceof Float32Array?new Float32Array(e):n instanceof Int32Array?new Int32Array(e):new Uint32Array(e)}function sf(n,e,t,r){const{edgeCount:s,arcCount:o}=n;if(G("reducer",t,["first","sum","max","min"]),e.length!==o)throw new f("E_COLUMN_LENGTH",`perArc has ${e.length} entries, expected ${o}`,{expected:o,found:e.length});if(n.flags.arcToEdgeIsIdentity)return e;const i=Ps(e,s),{edgeToArc:c,arcToEdge:l}=n;for(let u=0;u<s;u++)i[u]=e[c[u]];switch(t){case"first":break;case"sum":for(let u=0;u<o;u++){const a=l[u];c[a]!==u&&(i[a]+=e[u])}break;case"max":for(let u=0;u<o;u++){const a=l[u];e[u]>i[a]&&(i[a]=e[u])}break;case"min":for(let u=0;u<o;u++){const a=l[u];e[u]<i[a]&&(i[a]=e[u])}break;default:{const u=t;throw new f("E_UNSUPPORTED",`unknown reducer ${String(u)}`,{reducer:u})}}return i}function of(n,e,t){const{edgeCount:r,arcCount:s}=n;if(e.length!==r)throw new f("E_COLUMN_LENGTH",`perEdge has ${e.length} entries, expected ${r}`,{expected:r,found:e.length});if(n.flags.arcToEdgeIsIdentity)return e;const o=t??Ps(e,s),{arcToEdge:i}=n;for(let c=0;c<s;c++)o[c]=e[i[c]];return o}function E(n,e,t={}){return new f("E_INVALID_SNAPSHOT",`invariant ${n} violated: ${e}`,{invariant:n,...t})}function Sc(n,e,t){for(let r=0;r<t;r++){const s=n[r+1];for(let o=n[r]+1;o<s;o++)if(e[o]===e[o-1])return!0}return!1}function Uc(n,e,t){let r=0;for(let s=0;s<t;s++){const o=n[s+1];for(let i=n[s];i<o;i++)e[i]===s&&r++}return r}function Ke(n){for(let e=0;e<n.length;e++)if(n[e]!==e)return!1;return!0}function Ms(n){const{directed:e,nodeCount:t,rowPtr:r,colIdx:s,weights:o,arcToEdge:i}=n;let c=!0,l=!0,u=!0;if(o!==null)for(let a=0;a<o.length;a++){const d=o[a];d!==1&&(c=!1),d>=0||(l=!1),Number.isFinite(d)||(u=!1)}return{multigraph:Sc(r,s,t),hasSelfLoops:n.selfLoopCount>0,arcToEdgeIsIdentity:e&&(i===null||Ke(i)),weighted:o!==null,allWeightsOne:c,nonNegativeWeights:l,finiteWeights:u}}function Pc(n){const{rowPtr:e,colIdx:t,nodeCount:r,arcCount:s}=n;if(e.length!==r+1)throw E("I1",`rowPtr has ${e.length} entries, expected ${r+1}`,{expected:r+1,found:e.length});if(e[0]!==0)throw E("I1",`rowPtr[0] is ${e[0]}, expected 0`,{row:0,found:e[0]});for(let o=0;o<r;o++)if(e[o+1]<e[o])throw E("I1",`rowPtr decreases at row ${o}: ${e[o]} -> ${e[o+1]}`,{row:o});if(e[r]!==s||t.length!==s)throw E("I1",`rowPtr[${r}] = ${e[r]}, colIdx.length = ${t.length}, arcCount = ${s}`,{row:r,found:e[r],expected:s,colIdxLength:t.length})}function Mc(n){const{colIdx:e,nodeCount:t}=n;for(let r=0;r<e.length;r++)if(e[r]>=t)throw E("I2",`colIdx[${r}] = ${e[r]} is not below nodeCount ${t}`,{arc:r,found:e[r]})}function Vc(n){const e=[["nodeCount",n.nodeCount],["edgeCount",n.edgeCount],["arcCount",n.arcCount],["selfLoopCount",n.selfLoopCount]];for(const[t,r]of e)if(!Number.isInteger(r)||r<0||r>4294967294)throw E("I3",`${t} = ${r} is not an integer in [0, MAX_COUNT]`,{count:t,found:r});if(n.edgeCount>n.arcCount)throw E("I3",`edgeCount ${n.edgeCount} exceeds arcCount ${n.arcCount}`,{edgeCount:n.edgeCount,arcCount:n.arcCount});if(n.selfLoopCount>n.edgeCount)throw E("I3",`selfLoopCount ${n.selfLoopCount} exceeds edgeCount ${n.edgeCount}`,{selfLoopCount:n.selfLoopCount,edgeCount:n.edgeCount})}function Rc(n){const{rowPtr:e,colIdx:t,nodeCount:r}=n,o=n.flags.arcToEdgeIsIdentity?null:n.arcToEdge;for(let i=0;i<r;i++){const c=e[i+1];for(let l=e[i]+1;l<c;l++){if(t[l]<t[l-1])throw E("I4",`row ${i} is not sorted at arc ${l}`,{row:i,arc:l});if(t[l]===t[l-1]&&o!==null&&o[l]<=o[l-1])throw E("I4",`parallel arcs ${l-1} and ${l} in row ${i} are not in edge order`,{row:i,arc:l})}}}function Bc(n){const{arcCount:e,edgeCount:t}=n;if(n.flags.arcToEdgeIsIdentity){if(!n.directed||e!==t)throw E("I5","identity permutation claimed on a snapshot where it cannot hold",{directed:n.directed,arcCount:e,edgeCount:t});return}const{arcToEdge:r,edgeToArc:s}=n;if(r.length!==e)throw E("I5",`arcToEdge has ${r.length} entries, expected ${e}`,{expected:e,found:r.length});if(s.length!==t)throw E("I5",`edgeToArc has ${s.length} entries, expected ${t}`,{expected:t,found:s.length});for(let o=0;o<e;o++)if(r[o]>=t)throw E("I5",`arcToEdge[${o}] = ${r[o]} is not below edgeCount ${t}`,{arc:o,found:r[o]});for(let o=0;o<t;o++)if(s[o]>=e)throw E("I5",`edgeToArc[${o}] = ${s[o]} is not below arcCount ${e}`,{edge:o,found:s[o]})}function Wc(n){if(n.flags.arcToEdgeIsIdentity)return;const{arcToEdge:e,edgeToArc:t,edgeCount:r}=n;for(let s=0;s<r;s++)if(e[t[s]]!==s)throw E("I5",`arcToEdge[edgeToArc[${s}]] = ${e[t[s]]}, expected ${s}`,{edge:s,arc:t[s]})}function Vs(n,e){if(!n.directed)return;const{arcCount:t,edgeCount:r}=n;if(t!==r)throw E("I6",`directed snapshot has arcCount ${t} but edgeCount ${r}`,{arcCount:t,edgeCount:r});if(!e||n.flags.arcToEdgeIsIdentity)return;const{arcToEdge:s}=n,o=new Uint8Array(r);for(let i=0;i<t;i++){const c=s[i];if(c>=r||o[c]===1)throw E("I6",`edge ${c} appears more than once in arcToEdge (arc ${i})`,{arc:i,edge:c});o[c]=1}}function Xc(n){if(n.directed)return;const e=2*n.edgeCount-n.selfLoopCount;if(n.arcCount!==e)throw E("I7",`undirected snapshot has arcCount ${n.arcCount}, expected 2 * ${n.edgeCount} - ${n.selfLoopCount} = ${e}`,{arcCount:n.arcCount,expected:e})}function jc(n){if(n.directed)return;const{nodeCount:e,arcCount:t,edgeCount:r,rowPtr:s,colIdx:o,weights:i,arcToEdge:c}=n,l=new Uint8Array(r);for(let a=0;a<t;a++){const d=c[a];if(l[d]===2)throw E("I7",`edge ${d} appears more than twice in arcToEdge (arc ${a})`,{arc:a,edge:d});l[d]++}const u=s.slice(0,e);for(let a=0;a<e;a++){const d=s[a+1];let g=u[a];if(g<s[a]||g>d)throw E("I7",`row ${a} was over-consumed by mates from earlier rows`,{row:a});for(;g<d;){const h=o[g];let y=g+1;for(;y<d&&o[y]===h;)y++;const w=y-g;if(h===a){for(let m=g;m<y;m++)if(l[c[m]]!==1)throw E("I7",`self-loop edge ${c[m]} has more than one arc`,{row:a,arc:m,edge:c[m]})}else{if(h<a)throw E("I7",`arc ${g} in row ${a} targets ${h} but row ${h} holds no mate`,{row:a,arc:g,target:h});const m=u[h],A=s[h+1];for(let p=0;p<w;p++){const I=g+p,N=m+p;if(N>=A||o[N]!==a)throw E("I7",`arc ${I} in row ${a} targeting ${h} has no mate in row ${h}`,{row:a,arc:I,target:h});if(c[N]!==c[I])throw E("I7",`arcs ${I} and ${N} should share a logical edge but hold ${c[I]} and ${c[N]}`,{row:a,arc:I,mate:N});if(l[c[I]]!==2)throw E("I7",`edge ${c[I]} of arc ${I} does not have two arcs`,{row:a,arc:I,edge:c[I]});if(i!==null&&i[I]!==i[N])throw E("I7",`arcs ${I} and ${N} carry different weights ${i[I]} and ${i[N]}`,{row:a,arc:I,mate:N})}if(m+w<A&&o[m+w]===a)throw E("I7",`row ${h} holds more arcs to ${a} than row ${a} holds to ${h}`,{row:h,arc:m+w,target:a});u[h]=m+w}g=y}u[a]=d}}function Fc(n){const{weights:e,arcCount:t}=n;if(e!==null&&e.length!==t)throw E("I8",`weights has ${e.length} entries, expected ${t}`,{expected:t,found:e.length})}function zc(n){const{weights:e}=n;if(e!==null){for(let t=0;t<e.length;t++)if(Number.isNaN(e[t]))throw E("I8",`weights[${t}] is NaN`,{arc:t})}}function Gc(n){const e=Uc(n.rowPtr,n.colIdx,n.nodeCount);if(e!==n.selfLoopCount)throw E("I9",`selfLoopCount is ${n.selfLoopCount} but ${e} loop arcs exist`,{reason:"selfLoopCount",expected:e,found:n.selfLoopCount});const t=Ms({directed:n.directed,nodeCount:n.nodeCount,rowPtr:n.rowPtr,colIdx:n.colIdx,weights:n.weights,arcToEdge:n.flags.arcToEdgeIsIdentity?null:n.arcToEdge,selfLoopCount:n.selfLoopCount}),r=["multigraph","hasSelfLoops","arcToEdgeIsIdentity","weighted","allWeightsOne","nonNegativeWeights","finiteWeights"];for(const s of r)if(n.flags[s]!==t[s])throw E("I9",`flag ${s} is ${n.flags[s]} but the arrays say ${t[s]}`,{flag:s,found:n.flags[s],expected:t[s]})}function Yc(n,e,t){const r=n.segments[e];if(r===null)return;if(t===null)throw E("I10",`arena names a segment for absent core array ${e}`,{array:e});const s=r.byteOffset-n.byteOffset;if(s<0||s%R!==0||s+r.byteLength>n.byteLength)throw E("I10",`arena segment ${e} at ${r.byteOffset} is not 256-aligned inside the arena`,{array:e,byteOffset:r.byteOffset});if(t.buffer!==n.buffer||t.byteOffset!==r.byteOffset||t.byteLength!==r.byteLength)throw E("I10",`core array ${e} is not the view its arena segment describes`,{array:e,byteOffset:t.byteOffset,byteLength:t.byteLength})}function Hc(n,e){if(!Fo(e))throw E("I10",`core array ${n} is not 4-byte aligned`,{array:n,byteOffset:e.byteOffset,byteLength:e.byteLength});if(!kn(e))throw E("I10",`core array ${n} is not a view over a plain ArrayBuffer`,{array:n,reason:"buffer"})}function qc(n){const e=n.flags.arcToEdgeIsIdentity,t=[["rowPtr",n.rowPtr],["colIdx",n.colIdx],["weights",n.weights],["arcToEdge",e?null:n.arcToEdge],["edgeToArc",e?null:n.edgeToArc]];for(const[i,c]of t)c!==null&&Hc(i,c);const{arena:r}=n;if(r===null)return;const{alignment:s}=r;if(s!==R)throw E("I10",`arena alignment is ${s}, expected ${R}`,{found:s});for(const[i,c]of t)Yc(r,i,c);let o=0;for(const i of["rowPtr","colIdx","weights"]){const c=r.segments[i];c!==null&&(o=c.byteOffset+c.byteLength-r.byteOffset)}if(r.hotByteLength!==o)throw E("I10",`arena.hotByteLength is ${r.hotByteLength}, expected ${o}`,{reason:"hotByteLength",found:r.hotByteLength,expected:o})}function Jc(n){if(n.ids.size!==n.nodeCount)throw E("I11",`ids.size is ${n.ids.size}, expected nodeCount ${n.nodeCount}`,{expected:n.nodeCount,found:n.ids.size})}function Kc(n){const{ids:e,nodeCount:t}=n;for(let r=0;r<t;r++){const s=e.idOf(r);if(typeof s=="number"&&Number.isNaN(s))throw E("I11",`id of node ${r} is NaN`,{index:r});const o=e.indexOf(s);if(o!==r)throw E("I11",`ids.indexOf(ids.idOf(${r})) is ${o}`,{index:r,found:o})}}function S(n,e,t,r={}){return E("I12",`column "${e.meta.name}" of table ${n}: ${t}`,{table:n,column:e.meta.name,...r})}function Lr(n,e,t,r,s){if(t.length!==r+1)throw S(n,e,`offsets has ${t.length} entries, expected ${r+1}`,{expected:r+1,found:t.length});if(t[0]!==0)throw S(n,e,`offsets[0] is ${t[0]}`,{row:0});for(let o=0;o<r;o++)if(t[o+1]<t[o])throw S(n,e,`offsets decrease at row ${o}`,{row:o});if(t[r]!==s)throw S(n,e,`offsets[${r}] is ${t[r]}, expected ${s}`,{row:r,found:t[r],expected:s})}function $r(n,e,t,r,s,o){for(let i=0;i<t.length;i++){const c=t[i];if(c===4294967295){const l=Math.floor(i/r);if(o!==void 0&&(o===null||k(o,l)))throw S(n,e,`row ${l} is set but holds INVALID_INDEX`,{row:l});continue}if(c>=s)throw S(n,e,`value ${c} at ${i} is not below ${s}`,{row:Math.floor(i/r),found:c,expected:s})}}function Or(n,e,t){switch(e.dtype){case"u32":$r(n,e,e.data,e.meta.components,t,e.validity);return;case"list":{const{child:r}=e;if(r.dtype!=="u32")throw S(n,e,`refersTo list requires a u32 child, found ${r.dtype}`);$r(n,e,r.data,1,t,void 0);return}default:throw S(n,e,`refersTo requires dtype u32, found ${e.dtype}`)}}function Rs(n){switch(n.dtype){case"f32":case"f64":case"i32":case"u32":case"u8":case"bool":return[["data",n.data],["validity",n.validity]];case"dict":return[["codes",n.codes],["validity",n.validity]];case"string":return[["offsets",n.offsets],["utf8",n.utf8],["validity",n.validity]];case"list":return[["offsets",n.offsets],["validity",n.validity],...Rs(n.child).map(([e,t])=>[`child.${e}`,t])];case"json":return[["validity",n.validity]];default:throw E("I12",`unknown dtype ${n.dtype}`)}}function Zc(n,e,t,r){if(e.length!==t)throw S(n,e,`has ${e.length} rows, expected ${t}`,{expected:t,found:e.length});const{validity:s,meta:o}=e,i=Math.ceil(t/32);if(s!==null&&s.length!==i)throw S(n,e,`validity has ${s.length} words, expected ${i}`,{expected:i,found:s.length});const c=s===null?0:t-xe(s,t);if(e.nullCount!==c)throw S(n,e,`nullCount is ${e.nullCount}, the validity bitmap says ${c}`,{expected:c,found:e.nullCount,reason:"nullCount"});for(const[a,d]of Rs(e))if(d!==null&&!kn(d))throw S(n,e,`${a} is not a view over a plain ArrayBuffer`,{array:a,reason:"buffer"});const l=o.refersTo==="node"?r.nodeCount:r.edgeCount,{dtype:u}=e;switch(u){case"f32":case"f64":case"i32":case"u32":case"u8":{const a=t*o.components;if(e.data.length!==a)throw S(n,e,`data has ${e.data.length} values, expected ${a}`,{expected:a,found:e.data.length});o.refersTo!==null&&Or(n,e,l);break}case"bool":if(e.data.length!==i)throw S(n,e,`bool data has ${e.data.length} words, expected ${i}`,{expected:i,found:e.data.length});break;case"dict":{if(e.codes.length!==t)throw S(n,e,`codes has ${e.codes.length} entries, expected ${t}`,{expected:t,found:e.codes.length});const a=e.dictionary.length;for(let d=0;d<t;d++)if(e.codes[d]>=a&&(s===null||k(s,d)))throw S(n,e,`code ${e.codes[d]} at row ${d} is not below ${a}`,{row:d,found:e.codes[d]});break}case"string":Lr(n,e,e.offsets,t,e.utf8.length);break;case"list":{const{child:a}=e;if(Lr(n,e,e.offsets,t,a.length),a.validity!==null)throw S(n,e,"list child column has a validity bitmap");o.refersTo!==null&&Or(n,e,l);break}case"json":if(e.values.length!==t)throw S(n,e,`values has ${e.values.length} entries, expected ${t}`,{expected:t,found:e.values.length});break;default:throw S(n,e,`unknown dtype ${String(u)}`)}}function _r(n,e,t,r){for(const s of e)Zc(n,s,t,r)}function Qc(n){const e=[["nodes",n.nodes,n.nodeCount],["edges",n.edges,n.edgeCount],["graph",n.graph,1]];for(const[t,r,s]of e){if(r.rowCount!==s)throw E("I12",`table ${t} has ${r.rowCount} rows, expected ${s}`,{table:t,expected:s,found:r.rowCount});_r(t,r,s,n)}for(const[t,r]of n.extensions)_r(`extensions[${t}]`,r,r.rowCount,n)}function el(n){if(n.edges.rowCount!==n.edgeCount)throw E("I13",`edge table has ${n.edges.rowCount} rows, expected edgeCount ${n.edgeCount}`,{expected:n.edgeCount,found:n.edges.rowCount})}function Bs(n){Vc(n),Pc(n),Mc(n),Bc(n),Vs(n,!1),Xc(n),Fc(n),qc(n),Jc(n),el(n),Qc(n)}function tl(n){Bs(n),Rc(n),Wc(n),Vs(n,!0),zc(n),jc(n),Gc(n),Kc(n);const e=[["nodes",n.nodes],["edges",n.edges],["graph",n.graph],...[...n.extensions].map(([t,r])=>[`extensions[${t}]`,r])];for(const[t,r]of e)for(const s of r)nl(t,s)}function nl(n,e){try{Os(e)}catch(t){throw t instanceof f&&(t.code==="E_DUPLICATE_ID"||t.code==="E_DUPLICATE_EDGE_ID")?S(n,e,t.message,{...t.details,reason:"unique",cause:t.code}):t}}class rl{constructor(e){const{nodeCount:t,arcCount:r,rowPtr:s,colIdx:o,directed:i}=e,c=new Uint32Array(r),l=new Uint32Array(t),u=i?new Uint32Array(t):Me(s,t);for(let a=0;a<t;a++){const d=s[a+1];for(let g=s[a];g<d;g++){c[g]=a;const h=o[g];h===a&&l[a]++,i&&u[h]++}}this.arcRow=c,this.loops=l,this.inDegree=u}inDegreePrefix(){const e=this.inDegree.length,t=new Uint32Array(e+1);for(let r=0;r<e;r++)t[r+1]=t[r]+this.inDegree[r];return t}}function z(n,e,t,r){return E(r,`carried view ${n}.${e} disagrees with the core at ${t}`,{view:n,member:e,index:t,reason:"view"})}function Re(n,e,t,r,s){for(let o=0;o<r.length;o++)if(!Object.is(t[o],r[o])&&t[o]!==r[o])throw z(n,e,o,s)}function Ws(n,e,t){const r=new Uint8Array(t.length);for(let s=0;s<t.length;s++){const o=t[s];if(o>=t.length||r[o]===1)throw z(n,e,s,"I2");r[o]=1}}function sl(n,e){Re("outDegree","data",e,Me(n.rowPtr,n.nodeCount),"I2")}function ol(n,e){Re("inDegree","data",e,n.inDegree,"I2")}function il(n,e,t){const r=Me(n.rowPtr,n.nodeCount),s=n.directed?e.inDegree:e.loops;for(let o=0;o<r.length;o++)if(t[o]!==r[o]+s[o])throw z("degree","data",o,"I2")}function cl(n,e){Re("selfLoopsPerNode","data",e,n.loops,"I2")}function ll(n,e,t){const{colIdx:r,arcCount:s}=n;for(let o=0;o<t.length;o++){const i=t[o];if(i>=s||r[i]!==e.arcRow[i]||o>0&&i<=t[o-1])throw z("selfLoopArcs","data",o,"I2")}}function ul(n,e){Re("coo","src",e,n.arcRow,"I2")}function al(n,e,t,r,s){const{edgeCount:o,edgeToArc:i,colIdx:c,arcCount:l}=n,u=n.weights;for(let a=0;a<o;a++){const d=i[a];if(d>=l||t[a]!==e.arcRow[d])throw z("edgeList","src",a,"I2");if(r!==null&&r[a]!==c[d])throw z("edgeList","dst",a,"I2");if(s!==null&&u!==null&&!Object.is(s[a],u[d]))throw z("edgeList","weights",a,"I17")}}function dl(n,e,t){const{arcCount:r,arcToEdge:s,colIdx:o}=n;for(let i=0;i<r;i++){const c=t[i],l=o[i]===e.arcRow[i];if(c>=r||t[c]!==i||s[c]!==s[i]||c===i!==l)throw z("mate","data",i,"I2")}}function fl(n,e,t,r){Ws(n,"perm",t);let s=0,o=0,i=0;for(let l=0;l<t.length;l++){const u=e[t[l]];if(l>0){const a=e[t[l-1]];if(u>a||u===a&&t[l]<t[l-1])throw z(n,"perm",l,"I2")}u>=vs?s++:u>=xs?o++:u>=1&&i++}const c=[0,s,s+o,s+o+i,t.length];Re(n,"segmentOffsets",r,c,"I2")}function hl(n,e,t,r,s){const o=n[t-1],i=e[o];if(s<i||s===i&&r<=o)throw z("reverse","fwdArc",t,"I2")}function gl(n,e,t){const{nodeCount:r,arcCount:s,colIdx:o}=n,i=n.weights,{rowPtr:c,fwdArc:l}=t,u=t.colIdx,a=t.weights;if(c[0]!==0||c[r]!==s)throw z("reverse","rowPtr",0,"I2");Re("reverse","rowPtr",c,e.inDegreePrefix(),"I2"),Ws("reverse","fwdArc",l);for(let d=0;d<r;d++){const g=c[d+1];for(let h=c[d];h<g;h++){const y=l[h],w=e.arcRow[y];if(o[y]!==d||u[h]!==w)throw z("reverse","colIdx",h,"I2");if(h>c[d]&&hl(l,e.arcRow,h,y,w),a!==null&&i!==null&&!Object.is(a[h],i[y]))throw z("reverse","weights",h,"I17")}}}function wl(n,e,t){Re(n,"data",e,t,"I17")}const yl="@graphty/graph-format@8bb237cb7ec4",ml=new Set(["totalWeight","symmetric"]),pl=new TextEncoder;function bl(n=ts){if(!n)throw new f("E_UNSUPPORTED","the wire format cannot be written on a big-endian host",{reason:"big-endian host"})}const tt="$num",Dr="$esc";function Il(n){return Number.isNaN(n)?{[tt]:"NaN"}:n===1/0?{[tt]:"Infinity"}:n===-1/0?{[tt]:"-Infinity"}:Object.is(n,-0)?{[tt]:"-0"}:n}function Ae(n){if(typeof n=="number")return Il(n);if(Array.isArray(n))return n.map(e=>Ae(e));if(me(n)){const e=Object.keys(n),t={};for(const r of e)Xs(t,r,Ae(n[r]));return e.length===1&&(e[0]===tt||e[0]===Dr)?{[Dr]:t}:t}return n}function Xs(n,e,t){Object.defineProperty(n,e,{value:t,enumerable:!0,writable:!0,configurable:!0})}class Gn{constructor(e,t=!1){this.buffers=[],this.copied=[],this.segments=[],this.bufferIndex=new Map,this.placed=new Map,this.cursor=0,this.mode=e,this.transfer=t}get regionLength(){return ve(this.cursor,R)}indexOf(e){return this.bufferIndex.get(e)??null}ref(e,t,r=!1){if(r&&Ee(e.buffer),this.mode==="reference")return{buffer:this.bufferIndexOf(e.buffer),byteOffset:e.byteOffset,byteLength:e.byteLength,dtype:t,length:e.length};const s=`${this.bufferIndexOf(e.buffer)}:${e.byteOffset}:${e.byteLength}:${t}`,o=this.placed.get(s);if(o!==void 0)return o;const i=ve(this.cursor,R);this.cursor=i+e.byteLength;const c={buffer:0,byteOffset:i,byteLength:e.byteLength,dtype:t,length:e.length};return this.placed.set(s,c),this.segments.push({view:e,ref:c}),c}finalise(){if(!(this.mode!=="reference"||!this.transfer))for(let e=0;e<this.buffers.length;e++){const t=this.buffers[e];Ye(t)&&(this.buffers[e]=t.slice(0),this.copied.push(e))}}bufferIndexOf(e){const t=this.bufferIndex.get(e);if(t!==void 0)return t;const r=this.buffers.length;return this.bufferIndex.set(e,r),this.buffers.push(e),r}}function Yn(n){return n instanceof Uint32Array?"u32":n instanceof Int32Array?"i32":n instanceof Float32Array?"f32":n instanceof Float64Array?"f64":"u8"}const Tr=new WeakMap,kr=new WeakMap;function js(n,e){return n.offsets.length===e+1}function El(n){const e=Tr.get(n);if(e!==void 0&&js(e,n.length))return e;const t=wt(n,n.length);return Tr.set(n,t),t}function Al(n){const e=kr.get(n);if(e?.version===n.version&&js(e.encoded,n.length))return e.encoded;const t=new Array(n.length);for(let s=0;s<n.length;s++){const o=n.values[s];t[s]=o===void 0||!n.isSet(s)?"":JSON.stringify(Ae(o))}const r=wt(t,t.length);return kr.set(n,{version:n.version,encoded:r}),r}function vr(n,e,t){return{offsets:n.ref(e.offsets,"u32",t),utf8:n.ref(e.utf8,"utf8",t)}}function Nl(n){return{name:n.name,domain:n.domain,dtype:n.dtype,components:n.components,itemDtype:n.itemDtype,itemComponents:n.itemComponents,nullable:n.nullable,mutable:n.mutable,role:n.role,refersTo:n.refersTo,unique:n.unique,default:Ae(n.default),fill:Ae(n.fill),options:n.options===null?null:Ae(n.options),origin:n.origin===null?null:{...n.origin},dynamic:n.dynamic,extra:Ae(n.extra)}}function Fs(n,e,t){const r=t||Ye(e),s={meta:Nl(e.meta),data:null,validity:e.validity===null?null:n.ref(e.validity,"u32",r),nullCount:e.nullCount,dictionary:null,strings:null,offsets:null,child:null,jsonText:null},{dtype:o}=e;switch(o){case"f32":case"f64":case"i32":case"u32":case"u8":s.data=n.ref(e.data,o,r);break;case"bool":s.data=n.ref(e.data,"u32",r);break;case"dict":s.data=n.ref(e.codes,"u32",r),s.dictionary=vr(n,El(e.dictionary),r);break;case"string":s.strings={offsets:n.ref(e.offsets,"u32",r),utf8:n.ref(e.utf8,"utf8",r)};break;case"list":s.offsets=n.ref(e.offsets,"u32",r),s.child=Fs(n,e.child,r);break;case"json":s.jsonText=vr(n,Al(e),r);break;default:{const i=o;throw new f("E_UNSUPPORTED",`unknown dtype ${i}`,{dtype:i})}}return s}function $t(n,e){const t=[],r=Ye(e);for(const s of e)t.push(Fs(n,s,r));return t}function Cl(n,e){const{ids:t}=e;if(!(t instanceof H))throw new f("E_UNSUPPORTED","the snapshot's id map is not a NodeIdMap of this package",{reason:"foreign id map"});const r=Bi(t),s=Ye(t);return{kind:r.kind,size:r.size,offset:r.offset,values:r.values===null?null:n.ref(r.values,Yn(r.values),s),tags:r.tags===null?null:n.ref(r.tags,"u8",s),numbers:r.numbers===null?null:n.ref(r.numbers,"f64",s),offsets:r.offsets===null?null:n.ref(r.offsets,"u32",s),utf8:r.utf8===null?null:n.ref(r.utf8,"utf8",s)}}function Ll(n){return{name:n.name,description:n.description,creator:n.creator,created:n.created,modified:n.modified,keywords:[...n.keywords],sourceFormat:n.sourceFormat,sourceVersion:n.sourceVersion,idType:n.idType,timeFormat:n.timeFormat,timeRepresentation:n.timeRepresentation,mode:n.mode,declaredMultigraph:n.declaredMultigraph,weightOrigin:n.weightOrigin===null?null:{...n.weightOrigin},extra:Ae(n.extra)}}function $l(n,e,t){if(t===void 0||t.length===0)return null;const r={};let s=0;for(const o of new Set(t)){if(ml.has(o))continue;const i=Na(e,o);if(i===null)continue;const c={};let l=!1;for(const[u,a]of Object.entries(zn(e,o,i))){const d=a;c[u]=n.ref(d,Yn(d)),l=!0}l&&(r[o]=c,s++)}return s===0?null:r}function Hn(n,e,t,r=!0){bl();const s=n.flags.arcToEdgeIsIdentity,o={rowPtr:n.rowPtr,colIdx:n.colIdx,weights:n.weights,arcToEdge:s?null:n.arcToEdge,edgeToArc:s?null:n.edgeToArc},i={rowPtr:null,colIdx:null,weights:null,arcToEdge:null,edgeToArc:null},c=e.ref(n.rowPtr,"u32");i.rowPtr=c;for(const m of dt){const A=o[m];m!=="rowPtr"&&A!==null&&A.length>0&&(i[m]=e.ref(A,Yn(A)))}const l=Ol(n,e,i),u=Cl(e,n),a=r?$t(e,n.nodes):[],d=r?$t(e,n.edges):[],g=r?$t(e,n.graph):[],h=[];if(r)for(const[m,A]of n.extensions)h.push({name:m,rowCount:A.rowCount,columns:$t(e,A)});const y=$l(e,n,t);return e.finalise(),{manifest:{format:an,wire:[Ne,ns],producer:yl,formatVersion:1,directed:n.directed,counts:{nodes:n.nodeCount,edges:n.edgeCount,arcs:n.arcCount,selfLoops:n.selfLoopCount},flags:{...n.flags},core:{rowPtr:c,colIdx:i.colIdx,weights:i.weights,arcToEdge:i.arcToEdge,edgeToArc:i.edgeToArc},arena:l,ids:u,nodeColumns:a,edgeColumns:d,graphColumns:g,extensions:h,meta:Ll(n.meta),views:y,copied:e.copied,label:n.label},layout:e}}function Ol(n,e,t){if(e.mode==="container"){let o=0,i=0;for(const c of dt){const l=t[c];l!==null&&(o=l.byteOffset+l.byteLength,(c==="rowPtr"||c==="colIdx"||c==="weights")&&(i=o))}return{buffer:0,byteOffset:0,byteLength:o,hotByteLength:i}}const{arena:r}=n;if(r===null)return null;const s=e.indexOf(r.buffer);return s===null?null:{buffer:s,byteOffset:r.byteOffset,byteLength:r.byteLength,hotByteLength:r.hotByteLength}}function _l(n,e={}){const t=e.transfer===!0,r=new Gn("reference",t),{manifest:s}=Hn(n,r,e.includeViews,e.includeColumns!==!1);return t&&zs.set(n,[...r.buffers]),{manifest:s,buffers:r.buffers}}const zs=new WeakMap;function Dl(n){const e=zs.get(n);if(e!==void 0)return[...e];const t=new Gn("reference",!1);return Hn(n,t,void 0,!0),t.buffers.filter(r=>!Ye(r))}function Tl(n){return pl.encode(JSON.stringify(n))}const kl=new Set(["u32","i32","f32","f64","u8","utf8"]),vl=new Set(["f32","f64","i32","u32","u8","bool","dict","string","list","json"]),xl=new Set(["identity","dense","numeric","string","mixed"]),Sl=new Set(["string","integer","mixed"]),Ul=new Set(["integer","double","date","dateTime"]),Pl=new Set(["interval","timestamp"]),Ml=new Set(["static","dynamic","slice"]),Gs=new Set(["__proto__","constructor","prototype"]),xr="$num",Sr="$esc",Ur=256;function Ge(n){return typeof n=="string"?JSON.stringify(n.length>40?`${n.slice(0,37)}...`:n):typeof n=="number"||typeof n=="boolean"||n===null?String(n):n===void 0?"undefined":`a ${typeof n}`}const Vl="graphty.skippedColumns";function b(n,e,t={}){return new f("E_BAD_SERIALIZATION",`${n}: ${e}`,{ref:n,reason:e,...t})}function X(n,e){if(!me(n))throw b(e,"expected an object");return n}function zt(n,e){if(!Array.isArray(n))throw b(e,"expected an array");return n}function ht(n,e){if(typeof n!="string")throw b(e,"expected a string");return n}function ae(n,e){return n==null?null:ht(n,e)}function _e(n,e){if(typeof n!="boolean")throw b(e,"expected a boolean");return n}function Rl(n,e){return n==null?null:_e(n,e)}function fe(n,e){if(typeof n!="number"||!Number.isInteger(n)||n<0||n>4294967294)throw b(e,`expected an integer in [0, ${4294967294}]`,{found:n});return n===0?0:n}function Ot(n,e,t){if(n==null)return null;if(typeof n!="string"||!t.has(n))throw b(e,`unexpected value ${Ge(n)}`,{found:n});return n}function Pr(n){return typeof n=="string"&&vl.has(n)}function Ie(n,e,t=0){if(t>Ur)throw b(e,`JSON nesting deeper than ${Ur}`,{reason:"nesting"});if(Array.isArray(n))return n.map((s,o)=>Ie(s,`${e}[${o}]`,t+1));if(!me(n))return n;const r=Object.keys(n);if(r.length===1&&r[0]===xr){const s=n[xr];switch(s){case"NaN":return Number.NaN;case"Infinity":return 1/0;case"-Infinity":return-1/0;case"-0":return-0;default:throw b(e,`unknown number tag ${Ge(s)}`,{found:s})}}if(r.length===1&&r[0]===Sr){const s=n[Sr];if(!me(s))throw b(e,"an escaped object must hold a plain object",{found:typeof s});return Mr(s,e,t)}return Mr(n,e,t)}function Mr(n,e,t){const r={};for(const s of Object.keys(n)){if(Gs.has(s))throw b(e,`forbidden key "${s}"`,{key:s});Xs(r,s,Ie(n[s],`${e}.${s}`,t+1))}return r}function Bl(n){const e=[n];for(;e.length>0;){const t=e.pop();if(Array.isArray(t))for(const r of t)e.push(r);else if(typeof t=="object"&&t!==null)for(const r of Object.keys(t)){if(Gs.has(r))throw b("manifest",`forbidden key "${r}"`,{key:r});e.push(t[r])}}}function Ys(n,e){let t;try{t=JSON.parse(n)}catch(r){throw b(e,`not valid JSON (${r instanceof Error?r.message:String(r)})`)}return Bl(t),t}function Wl(n,e){return{level:e,copy:!1,unknownColumns:"error"}}function Vr(n,e,t){return{byteLength:t,locate(r){return{buffer:n,byteOffset:e+r}},read(r,s){const o=new Uint8Array(new ArrayBuffer(mt(s)),0,s);return o.set(new Uint8Array(n,e+r,s)),o}}}function Xl(n){return typeof SharedArrayBuffer<"u"&&n instanceof SharedArrayBuffer}function jl(n){switch(n){case"u32":case"i32":case"f32":return 4;case"f64":return 8;case"u8":case"utf8":return 1;default:{const e=n;throw b("dtype",`unknown wire dtype ${e}`,{dtype:e})}}}function Rr(n,e,t,r){switch(n){case"u32":return new Uint32Array(e,t,r);case"i32":return new Int32Array(e,t,r);case"f32":return new Float32Array(e,t,r);case"f64":return new Float64Array(e,t,r);case"u8":case"utf8":return new Uint8Array(e,t,r);default:{const s=n;throw b("dtype",`unknown wire dtype ${s}`,{dtype:s})}}}function Mt(n,e){const t=X(n,e),{dtype:r}=t;if(typeof r!="string"||!kl.has(r))throw b(e,`unknown wire dtype ${Ge(r)}`,{found:r});const s=["buffer","byteOffset","byteLength","length"];for(const o of s){const i=t[o];if(typeof i!="number"||!Number.isInteger(i)||i<0)throw b(`${e}.${o}`,"expected a non-negative integer",{found:i})}return{buffer:t.buffer,byteOffset:t.byteOffset,byteLength:t.byteLength,dtype:r,length:t.length}}function nn(n,e){return n instanceof f&&(n.code.startsWith("E_COLUMN")||n.code==="E_DUPLICATE_ROLE")?new f("E_BAD_SERIALIZATION",`${e}: ${n.message}`,{ref:e,reason:n.message,cause:n.code,...n.details}):n instanceof Error?n:b(e,String(n))}class Fl{constructor(e,t){this.ranges=[],this.skipped=[],this.regions=e,this.options=t}get structure(){return this.options.level!=="none"}get full(){return this.options.level==="full"}array(e,t,r,s){const o=Mt(e,t);if(o.dtype!==r)throw b(t,`expected dtype ${r}, found ${o.dtype}`,{expected:r,found:o.dtype});const i=this.regions[o.buffer];if(i===void 0)throw b(t,`buffer index ${o.buffer} is out of range (${this.regions.length} buffers)`,{found:o.buffer,buffers:this.regions.length});const c=jl(o.dtype);if(o.byteOffset%c!==0)throw b(t,`byteOffset ${o.byteOffset} is not a multiple of ${c}`,{byteOffset:o.byteOffset,elementSize:c});if(o.byteLength!==o.length*c)throw b(t,`byteLength ${o.byteLength} is not length ${o.length} * ${c}`,{byteLength:o.byteLength,length:o.length,elementSize:c});if(o.byteOffset+o.byteLength>i.byteLength)throw b(t,`range [${o.byteOffset}, ${o.byteOffset+o.byteLength}) exceeds the buffer`,{byteOffset:o.byteOffset,byteLength:o.byteLength,bufferByteLength:i.byteLength});const l=i.locate(o.byteOffset,o.byteLength);if(l!==null&&l.byteOffset%c===0)return this.ranges.push({buffer:l.buffer,start:l.byteOffset,end:l.byteOffset+o.byteLength,kind:s,path:t}),Rr(o.dtype,l.buffer,l.byteOffset,o.length);const u=i.read(o.byteOffset,o.byteLength);return Rr(o.dtype,u.buffer,0,o.length)}u32(e,t,r){return this.array(e,t,"u32",r)}utf8(e,t,r,s,o=!1){const i=X(e,t),c=this.u32(i.offsets,`${t}.offsets`,s),l=this.array(i.utf8,`${t}.utf8`,"utf8",s);if(c.length===0)throw b(`${t}.offsets`,"a Utf8 store needs at least one offset");if((this.structure||o)&&Dn(c,l,r??c.length-1,t),this.full){const u=Le.fromEncoded(c,l).firstMalformedRow();if(u!==-1)throw b(t,`malformed UTF-8 in row ${u}`,{row:u})}return{offsets:c,utf8:l}}checkOverlaps(){const e=this.ranges.filter(t=>(t.kind==="core"||t.kind==="immutable")&&t.end>t.start);for(const t of this.ranges)if(!(t.kind!=="mutable"||t.end===t.start)){for(const r of e)if(r.buffer===t.buffer&&t.start<r.end&&r.start<t.end)throw b(t.path,`mutable column overlaps ${r.path}`,{overlaps:r.path})}}column(e,t,r,s,o){const i=X(e,o),c=X(i.meta,`${o}.meta`),l=ht(c.name,`${o}.meta.name`);if(this.skipUnknownDtype(c,l,t,r,o))return null;const u=this.columnMeta(c,l,t,o),a=u.mutable?"mutable":"immutable",d=qe(u,s,i.validity===null||i.validity===void 0?null:this.u32(i.validity,`${o}.validity`,a)),g=i.nullCount;switch(u.dtype){case"f32":case"f64":case"i32":case"u32":d.data=this.array(i.data,`${o}.data`,u.dtype,a);break;case"u8":{const y=this.array(i.data,`${o}.data`,"u8",a);d.data=Rt(y)?y:Go(y);break}case"bool":d.data=this.u32(i.data,`${o}.data`,a);break;case"dict":{d.data=this.u32(i.data,`${o}.data`,a);const y=this.utf8(i.dictionary,`${o}.dictionary`,null,a,!0);d.dictionary=hn(y.utf8,y.offsets,0,y.offsets.length-1);break}case"string":{const y=this.utf8(i.strings,`${o}.strings`,s,a);d.offsets=y.offsets,d.utf8=y.utf8;break}case"list":{const y=this.u32(i.offsets,`${o}.offsets`,a);if(y.length!==s+1)throw b(`${o}.offsets`,`expected ${s+1} offsets, found ${y.length}`,{expected:s+1,found:y.length});d.offsets=y;const w=this.column(i.child,t,r,y[s],`${o}.child`);if(w===null||w.dtype==="list")throw b(`${o}.child`,"a list column needs a non-list child column");d.child=w;break}case"json":d.values=this.jsonRows(i.jsonText,s,`${o}.jsonText`,a);break;default:{const y=u.dtype;throw b(`${o}.meta.dtype`,`unknown dtype ${y}`,{dtype:y})}}let h;try{h=F(d)}catch(y){throw nn(y,o)}if(this.structure&&h.nullCount!==g)throw b(`${o}.nullCount`,`manifest says ${String(g)}, the bitmap says ${h.nullCount}`,{expected:h.nullCount,found:g});return h}skipUnknownDtype(e,t,r,s,o){const{dtype:i,itemDtype:c}=e;if(!(!Pr(i)||i==="list"&&!Pr(c)))return!1;const u=i==="list"?c:i;if(this.options.unknownColumns==="skip")return this.skipped.push({domain:r,table:s,name:t,dtype:String(u)}),!0;throw new f("E_UNSUPPORTED",`column "${t}" has unknown dtype ${String(u)}`,{dtype:u,column:t,ref:o})}columnMeta(e,t,r,s){const o=`${s}.meta`,i=(u,a)=>{const d=e[u];return d==null?void 0:a(d,`${o}.${u}`)},c=(u,a)=>{if(typeof u!="number")throw b(a,"expected a number",{found:u});return u},l={name:t,dtype:e.dtype,components:i("components",c),itemDtype:i("itemDtype",u=>u),itemComponents:i("itemComponents",c),nullable:i("nullable",_e),mutable:i("mutable",_e),role:i("role",ht),refersTo:i("refersTo",u=>u),unique:i("unique",_e),default:Ie(e.default,`${o}.default`),fill:Ie(e.fill,`${o}.fill`),options:i("options",(u,a)=>Ie(u,a)),origin:i("origin",u=>u),dynamic:i("dynamic",_e),extra:i("extra",(u,a)=>Ie(u,a))};try{return B(t,r,l)}catch(u){throw nn(u,s)}}jsonRows(e,t,r,s){const o=this.utf8(e,r,t,s,!0),i=hn(o.utf8,o.offsets,0,t),c=new Array(t);for(let l=0;l<t;l++){const u=i[l];c[l]=u===""?void 0:Ie(Ys(u,`${r}[${l}]`),`${r}[${l}]`)}return c}table(e,t,r,s,o){const i=zt(e,o),c=[],l=new Set;for(let u=0;u<i.length;u++){const a=this.column(i[u],t,r,s,`${o}[${u}]`);if(a!==null){if(l.has(a.meta.name))throw b(`${o}[${u}].meta.name`,`column "${a.meta.name}" is declared twice`,{column:a.meta.name});l.add(a.meta.name),c.push(a)}}try{return new ce({domain:t,rowCount:s,columns:c})}catch(u){throw nn(u,o)}}ids(e){const t=X(e,"ids"),r=t.kind;if(typeof r!="string"||!xl.has(r))throw new f("E_UNSUPPORTED",`unknown id map kind ${Ge(r)}`,{kind:r,ref:"ids.kind"});const s=r,o=fe(t.size,"ids.size"),i=t.offset??0;if(typeof i!="number")throw b("ids.offset","expected a number",{found:i});const l={kind:s,size:o,offset:s==="identity"?i:0,values:null,tags:null,numbers:null,offsets:null,utf8:null};switch(s){case"identity":break;case"dense":l.values=this.u32(t.values,"ids.values","immutable");break;case"numeric":l.values=this.array(t.values,"ids.values","f64","immutable");break;case"string":{l.offsets=this.u32(t.offsets,"ids.offsets","immutable"),l.utf8=this.array(t.utf8,"ids.utf8","utf8","immutable");break}case"mixed":{l.tags=this.array(t.tags,"ids.tags","u8","immutable"),l.numbers=this.array(t.numbers,"ids.numbers","f64","immutable"),l.offsets=this.u32(t.offsets,"ids.offsets","immutable"),l.utf8=this.array(t.utf8,"ids.utf8","utf8","immutable");break}default:{const u=s;throw new f("E_UNSUPPORTED",`unknown id map kind ${u}`,{kind:u})}}return vi(l,this.options.level)}views(e){const t=new Map;if(e==null)return t;const r=X(e,"views");for(const s of Object.keys(r)){const o=X(r[s],`views.${s}`),i=new Map;for(const c of Object.keys(o)){const l=`views.${s}.${c}`,u=Mt(o[c],l);i.set(c,this.array(u,l,u.dtype,"view"))}t.set(s,i)}return t}}function q(n,e,t,r,s,o){const i=`views.${e}.${t}`,c=n.get(t);if(c===void 0){if(o)throw b(i,"the carried view is missing this member");return null}if(!(c instanceof r))throw b(i,`expected ${r.name}, found ${c.constructor.name}`,{expected:r.name,found:c.constructor.name});if(c.length!==s)throw b(i,`expected ${s} entries, found ${c.length}`,{expected:s,found:c.length});return c}function Hs(n,e,t,r){return q(n,e,"data",t,r,!0)}function zl(n,e,t){let r=null;const s={snapshot:n,verify:t,facts:()=>(r??=new rl(n),r)};for(const[o,i]of e)Yl(o,n.directed)||Hl(s,o,i)}const Gl=new Set(["reverse","inDegree","weightedInDegree","reverseDegreeOrder"]);function Yl(n,e){return e?n==="mate":Gl.has(n)}function Hl(n,e,t){const{snapshot:r}=n;switch(e){case"reverse":ql(n,t);break;case"coo":Jl(n,t);break;case"edgeList":Kl(n,t);break;case"outDegree":Be(n,"outDegree",t,r.nodeCount,s=>{sl(r,s)});break;case"degree":Be(n,"degree",t,r.nodeCount,s=>{il(r,n.facts(),s)});break;case"selfLoopsPerNode":Be(n,"selfLoopsPerNode",t,r.nodeCount,s=>{cl(n.facts(),s)});break;case"inDegree":Be(n,"inDegree",t,r.nodeCount,s=>{ol(n.facts(),s)});break;case"selfLoopArcs":Be(n,"selfLoopArcs",t,r.selfLoopCount,s=>{ll(r,n.facts(),s)});break;case"mate":Be(n,"mate",t,r.arcCount,s=>{dl(r,n.facts(),s)});break;case"weightedOutDegree":case"weightedInDegree":case"weightedDegree":case"selfLoopWeight":Zl(n,e,t);break;case"degreeOrder":case"reverseDegreeOrder":Ql(n,e,t);break}}function qs(n,e,t){if(t!==null&&n.weights===null)throw b(`views.${e}.weights`,"weights carried for an unweighted snapshot")}function ql(n,e){const{snapshot:t}=n,{nodeCount:r,arcCount:s}=t,o=q(e,"reverse","rowPtr",Uint32Array,r+1,!0),i=q(e,"reverse","colIdx",Uint32Array,s,!0),c=q(e,"reverse","fwdArc",Uint32Array,s,!0),l=q(e,"reverse","weights",Float32Array,s,t.weights!==null);qs(t,"reverse",l);const u=new ft(t,o,i,l,c);n.verify&&gl(t,n.facts(),u),Ze(t,"reverse",u)}function Jl(n,e){const{snapshot:t}=n,r=q(e,"coo","src",Uint32Array,t.arcCount,!0);n.verify&&ul(n.facts(),r),Ze(t,"coo",Us(t,r))}function Kl(n,e){const{snapshot:t}=n,{edgeCount:r}=t,s=t.flags.arcToEdgeIsIdentity,o=q(e,"edgeList","src",Uint32Array,r,!0),i=q(e,"edgeList","dst",Uint32Array,r,!s),c=q(e,"edgeList","weights",Float32Array,r,t.weights!==null&&!s);qs(t,"edgeList",c),n.verify&&al(t,n.facts(),o,i,c),Ze(t,"edgeList",An(t,o,i??t.colIdx,c??t.weights))}function Be(n,e,t,r,s){const o=Hs(t,e,Uint32Array,r);n.verify&&s(o),Ze(n.snapshot,e,o)}function Zl(n,e,t){const{snapshot:r}=n,s=Hs(t,e,Float64Array,r.nodeCount);if(n.verify){wl(e,s,r[e]());return}Ze(r,e,s)}function Ql(n,e,t){const{snapshot:r}=n,{nodeCount:s}=r,o=q(t,e,"perm",Uint32Array,s,!0),i=q(t,e,"segmentOffsets",Uint32Array,5,!0);if(n.verify){const c=e==="degreeOrder"?Me(r.rowPtr,s):n.facts().inDegree;fl(e,c,o,i)}Ze(r,e,Object.freeze({perm:o,segmentOffsets:i}))}function eu(n){const e=X(n,"core"),t=r=>{const s=e[r];return s==null?null:Mt(s,`core.${r}`)};return{rowPtr:Mt(e.rowPtr,"core.rowPtr"),colIdx:t("colIdx"),weights:t("weights"),arcToEdge:t("arcToEdge"),edgeToArc:t("edgeToArc")}}function tu(n,e,t,r){const s=n.u32(e.rowPtr,"core.rowPtr","core");let o;if(e.colIdx===null){if(t.arcs!==0)throw b("core.colIdx",`null although counts.arcs is ${t.arcs}`);o=new Uint32Array(0)}else o=n.u32(e.colIdx,"core.colIdx","core");let i=null;if(e.weights!==null){if(!r.weighted)throw b("core.weights","present although flags.weighted is false");i=n.array(e.weights,"core.weights","f32","core")}else if(r.weighted){if(t.arcs!==0)throw b("core.weights",`null although flags.weighted is true and counts.arcs is ${t.arcs}`);i=new Float32Array(0)}const c=r.arcToEdgeIsIdentity,l=(u,a,d)=>{if(u!==null){if(c)throw b(`core.${a}`,"present although flags.arcToEdgeIsIdentity is true");return n.u32(u,`core.${a}`,"core")}if(c)return null;if(d!==0)throw b(`core.${a}`,`null although the permutation is not the identity and the count is ${d}`);return new Uint32Array(0)};return{rowPtr:s,colIdx:o,weights:i,arcToEdge:l(e.arcToEdge,"arcToEdge",t.arcs),edgeToArc:l(e.edgeToArc,"edgeToArc",t.edges)}}function nu(n,e,t,r,s){if(e===null||t===null||t.length===0||!(e.buffer===r.buffer&&e.byteOffset>=r.byteOffset&&e.byteOffset+e.byteLength<=r.byteOffset+r.byteLength))return null;const i=e.byteOffset-r.byteOffset;if(i%R!==0)throw b(`core.${n}`,`inside the arena at offset ${i}, not a multiple of ${R}`,{byteOffset:i});if(t.buffer!==s.buffer||t.byteOffset!==s.byteOffset+i)throw b(`core.${n}`,"the arena describes a segment the array is not a view of");return Object.freeze({byteOffset:s.byteOffset+i,byteLength:e.byteLength})}function ru(n,e,t,r,s){if(n==null)return null;const o=X(n,"arena"),i=fe(o.buffer,"arena.buffer"),c=fe(o.byteOffset,"arena.byteOffset"),l=fe(o.byteLength,"arena.byteLength"),u=e[i];if(u===void 0)throw b("arena.buffer",`buffer index ${i} is out of range`,{found:i});if(c+l>u.byteLength)throw b("arena",`range [${c}, ${c+l}) exceeds the buffer`,{byteOffset:c,byteLength:l,bufferByteLength:u.byteLength});const a=u.locate(c,l);if(a===null)return null;const d={rowPtr:null,colIdx:null,weights:null,arcToEdge:null,edgeToArc:null};let g=0;const h={buffer:i,byteOffset:c,byteLength:l},y=dt;for(const w of y){const m=nu(w,t[w],r[w],h,a);m!==null&&(d[w]=m,(w==="rowPtr"||w==="colIdx"||w==="weights")&&(g=m.byteOffset-a.byteOffset+m.byteLength))}if(s&&o.hotByteLength!==g)throw b("arena.hotByteLength",`manifest says ${String(o.hotByteLength)}, the segments say ${g}`,{expected:g,found:o.hotByteLength});return Object.freeze({buffer:a.buffer,byteOffset:a.byteOffset,byteLength:l,alignment:R,segments:Object.freeze(d),hotByteLength:g})}function su(n){const e=X(n,"flags"),t=r=>_e(e[r],`flags.${r}`);return{multigraph:t("multigraph"),hasSelfLoops:t("hasSelfLoops"),arcToEdgeIsIdentity:t("arcToEdgeIsIdentity"),weighted:t("weighted"),allWeightsOne:t("allWeightsOne"),nonNegativeWeights:t("nonNegativeWeights"),finiteWeights:t("finiteWeights")}}function ou(n,e){if(n==null)return null;const t=X(n,e),r=s=>ae(t[s],`${e}.${s}`);return{format:r("format"),id:r("id"),title:r("title"),type:r("type"),namespace:r("namespace")}}function iu(n){const e=X(n,"meta"),t=e.keywords??[],r=zt(t,"meta.keywords").map((o,i)=>ht(o,`meta.keywords[${i}]`)),s=Ie(e.extra??{},"meta.extra");if(!me(s))throw b("meta.extra","expected an object");return Object.freeze({name:ae(e.name,"meta.name"),description:ae(e.description,"meta.description"),creator:ae(e.creator,"meta.creator"),created:ae(e.created,"meta.created"),modified:ae(e.modified,"meta.modified"),keywords:Object.freeze(r),sourceFormat:ae(e.sourceFormat,"meta.sourceFormat"),sourceVersion:ae(e.sourceVersion,"meta.sourceVersion"),idType:Ot(e.idType,"meta.idType",Sl),timeFormat:Ot(e.timeFormat,"meta.timeFormat",Ul),timeRepresentation:Ot(e.timeRepresentation,"meta.timeRepresentation",Pl),mode:Ot(e.mode,"meta.mode",Ml),declaredMultigraph:Rl(e.declaredMultigraph,"meta.declaredMultigraph"),weightOrigin:ou(e.weightOrigin,"meta.weightOrigin"),extra:Object.freeze(s)})}function Js(n){if(n.format!==an)throw b("format",`expected "${an}", found ${Ge(n.format)}`,{found:n.format});const e=zt(n.wire,"wire"),t=e[0],r=e[1];if(typeof t!="number"||typeof r!="number"||!Number.isInteger(t)||!Number.isInteger(r))throw b("wire","expected [major, minor] integers",{found:n.wire});if(t!==Ne)throw new f("E_UNSUPPORTED_VERSION",`wire major ${t} is not supported (reader: ${Ne})`,{kind:"wire",found:t,supported:Ne});if(n.formatVersion!==1)throw new f("E_UNSUPPORTED_VERSION",`formatVersion ${Ge(n.formatVersion)} is not supported (reader: 1)`,{kind:"format",found:n.formatVersion,supported:1});return[t,r]}function cu(n,e,t,r){const s=X(n,"manifest");Js(s);const o=new Fl(e,t),i=_e(s.directed,"directed"),c=X(s.counts,"counts"),l={nodes:fe(c.nodes,"counts.nodes"),edges:fe(c.edges,"counts.edges"),arcs:fe(c.arcs,"counts.arcs"),selfLoops:fe(c.selfLoops,"counts.selfLoops")},u=su(s.flags);if(u.arcToEdgeIsIdentity&&(!i||l.arcs!==l.edges))throw b("flags.arcToEdgeIsIdentity","set on an undirected graph or with arcs !== edges");const a=eu(s.core),d=tu(o,a,l,u),g=ru(s.arena,e,a,d,o.structure),h=o.ids(s.ids),y=o.table(s.nodeColumns??[],"node",null,l.nodes,"nodeColumns"),w=o.table(s.edgeColumns??[],"edge",null,l.edges,"edgeColumns"),m=o.table(s.graphColumns??[],"graph",null,1,"graphColumns"),A=new Map,p=zt(s.extensions??[],"extensions");for(let O=0;O<p.length;O++){const _=`extensions[${O}]`,C=X(p[O],_),L=ht(C.name,`${_}.name`);if(A.has(L))throw b(`${_}.name`,`extension table "${L}" appears twice`,{table:L});const Y=fe(C.rowCount,`${_}.rowCount`);A.set(L,o.table(C.columns,"extension",L,Y,`${_}.columns`))}let I=iu(s.meta??{});if(o.skipped.length>0){const O=Object.freeze(o.skipped.map(_=>Object.freeze({..._})));I=Object.freeze({...I,extra:Object.freeze({...I.extra,[Vl]:O})})}const N=o.views(s.views);o.structure&&o.checkOverlaps();const T={label:ae(s.label,"label"),serial:null,directed:i,nodeCount:l.nodes,edgeCount:l.edges,arcCount:l.arcs,selfLoopCount:l.selfLoops,rowPtr:d.rowPtr,colIdx:d.colIdx,weights:d.weights,arcToEdge:d.arcToEdge,edgeToArc:d.edgeToArc,flags:u,ids:h,nodes:y,edges:w,graph:m,extensions:A,meta:I,arena:g,checksum:!1},$=fo(T);return t.level==="full"?$.validate({level:"full"}):t.level==="structure"&&$.validate({level:"structure"}),t.level!=="full"&&zl($,N,t.level==="structure"),$}const we=16,lu=new TextDecoder("utf-8",{fatal:!0});function Ks(n,e){const t=new Gn("container"),{manifest:r}=Hn(n,t,e.includeViews,!0),s=Tl(r);return{manifestBytes:s,regionStart:ve(we+s.byteLength,R),segments:t.segments,regionLength:t.regionLength}}function Zs(n,e){n.set(dn,0);const t=new DataView(n.buffer,n.byteOffset,n.byteLength);t.setUint16(4,Ne,!0),t.setUint16(6,ns,!0),new Uint32Array(n.buffer,n.byteOffset+8,1)[0]=fn,t.setUint32(12,e,!0)}function Qs(n){return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}function uu(n,e={}){const t=Ks(n,e),r=new Uint8Array(t.regionStart+t.regionLength);Zs(r,t.manifestBytes.byteLength),r.set(t.manifestBytes,we);for(const s of t.segments)r.set(Qs(s.view),t.regionStart+s.ref.byteOffset);return r}function*au(n){const e=new Uint8Array(n.regionStart);Zs(e,n.manifestBytes.byteLength),e.set(n.manifestBytes,we),yield e;for(const t of n.segments){if(t.ref.byteLength===0)continue;const r=new Uint8Array(ve(t.ref.byteLength,R));r.set(Qs(t.view)),yield r}}function du(n,e={}){return au(Ks(n,e))}function fu(n,e){if(e<we)throw b("header",`truncated: ${e} bytes, expected at least ${we}`,{byteLength:e});for(let c=0;c<dn.length;c++)if(n[c]!==dn[c])throw b("magic","not a GSNP container",{found:Array.from(n.subarray(0,4))});const t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=t.getUint16(4,!0),s=t.getUint16(6,!0);if(r!==Ne)throw new f("E_UNSUPPORTED_VERSION",`wire major ${r} is not supported (reader: ${Ne})`,{kind:"wire",found:r,supported:Ne});const o=t.getUint32(8,ts);if(o!==fn)throw b("endianness",`probe reads 0x${o.toString(16)}; the container was written on another endianness`,{found:o,expected:fn});const i=t.getUint32(12,!0);if(we+i>e)throw b("manifest",`truncated: ${i} manifest bytes declared, ${e} bytes in total`,{manifestLength:i,byteLength:e});return{major:r,minor:s,manifestLength:i}}function hu(n,e){let t;try{t=lu.decode(n)}catch{throw b("manifest","not valid UTF-8")}const r=Ys(t,"manifest");if(typeof r!="object"||r===null||Array.isArray(r))throw b("manifest","expected an object");const s=r,[o,i]=Js(s);if(o!==e.major||i!==e.minor)throw b("wire",`manifest says [${o}, ${i}], the header says [${e.major}, ${e.minor}]`,{found:[o,i],header:[e.major,e.minor]});return s}function cf(n,e){const t=Wl(e,"full"),r=n instanceof Uint8Array?n:new Uint8Array(n),s=fu(r,r.byteLength),o=hu(r.subarray(we,we+s.manifestLength),s),i=ve(we+s.manifestLength,R),c=Math.max(0,r.byteLength-i),{buffer:l}=r;let u;if(!t.copy&&!Xl(l)&&r.byteOffset%8===0)u=Vr(l,r.byteOffset+i,c);else{const a=new Uint8Array(ve(c,R));c>0&&a.set(r.subarray(i)),u=Vr(a.buffer,0,c)}return cu(o,[u],t)}function gu(n,e,t){for(let r=1;r<t;r++){const s=n[r],o=n[r-1];if(s<o||s===o&&e[r]<e[r-1])return!1}return!0}function wu(n,e){return new f("E_INVALID_WEIGHT",`edge ${n} has a NaN weight`,{edge:n,weight:e})}function yu(n,e,t){let r=1/0,s=-1/0;for(let o=0;o<e;o++){const i=Math.fround(n[o]);if(Number.isNaN(i))throw wu(o,n[o]);i<r&&(r=i,t[0]=i),i>s&&(s=i,t[1]=i)}}function mu(n,e,t,r,s){let o=0;for(let i=0;i<t;i++){const c=n[i],l=e[i];r[l+1]++,s[c+1]++,c===l&&o++}return o}function pu(n,e,t,r,s){let o=0;for(let i=0;i<t;i++){const c=n[i],l=e[i];r[l+1]++,s[c+1]++,c===l?o++:(r[c+1]++,s[l+1]++)}return o}function Br(n,e){for(let t=0;t<e;t++)n[t+1]+=n[t]}function bu(n,e,t,r){let s=!1;for(let o=0;o<t;o++){const i=e[o];r[o]=i,o>0&&n[o]===n[o-1]&&e[o-1]===i&&(s=!0)}return s}function Iu(n,e,t,r,s){for(let o=0;o<t;o++){const i=2*r[e[o]]++;s[i]=n[o],s[i+1]=o}}function Eu(n,e,t,r,s,o){for(let i=0;i<t;i++){const c=n[i],l=e[i],u=r[l]++;if(s[2*u]=c,s[2*u+1]=i,o[u>>>5]|=1<<(u&31),c!==l){const a=2*r[c]++;s[a]=l,s[a+1]=i}}}function Au(n,e,t,r,s,o){for(let i=0;i<n;i++){const c=2*e[i+1];for(let l=2*e[i];l<c;l+=2){const u=r[t[l]]++;s[u]=i,o[u]=t[l+1]}}}function Nu(n,e,t,r,s,o){const{targetStart:i,byTarget:c,declared:l}=e;for(let u=0;u<n;u++){const a=i[u+1];for(let d=i[u];d<a;d++){const g=c[2*d+1],h=t[c[2*d]]++;r[h]=u,s[h]=g,(l[d>>>5]>>>(d&31)&1)===1&&(o[g]=h)}}}function Cu(n,e){const t=n.length;for(let r=0;r<t;r++)e[n[r]]=r}function Lu(n,e,t){const r=n.length;for(let s=0;s<r;s++)t[s]=e[n[s]]}function $u(n,e,t){for(let r=0;r<t;r++){const s=n[r+1];for(let o=n[r]+1;o<s;o++)if(e[o]===e[o-1])return!0}return!1}function Cn(n,e){const{directed:t,nodeCount:r,edgeCount:s,src:o,dst:i}=n,c=n.weights;let l=!0,u=!0,a=!0;if(c!==null&&s>0){const _=new Float64Array([1/0,-1/0]);yu(c,s,_);const C=_[0],L=_[1];l=C===1&&L===1,u=C>=0,a=C>-1/0&&L<1/0}const d=new Uint32Array(r+1),g=new Uint32Array(r+1),h=t?mu(o,i,s,d,g):pu(o,i,s,d,g),y=t?s:2*s-h,w=t&&gu(o,i,s),m=gc({nodeCount:r,arcCount:y,edgeCount:s,weighted:c!==null,identity:w},e),{rowPtr:A,colIdx:p,weights:I,arcToEdge:N,edgeToArc:T}=m;Br(g,r),A.set(g);let $;if(w)$=bu(o,i,s,p),I!==null&&c!==null&&I.set(c.subarray(0,s));else if(N!==null&&T!==null){Br(d,r);const _=g;_.set(d);const C=new Uint32Array(2*y);let L=null;t?Iu(o,i,s,_,C):(L=new Uint32Array(y+31>>>5),Eu(o,i,s,_,C,L)),_.set(A),L===null?(Au(r,d,C,_,p,N),Cu(N,T)):Nu(r,{targetStart:d,byTarget:C,declared:L},_,p,N,T),I!==null&&c!==null&&Lu(N,c,I),$=$u(A,p,r)}else throw new f("E_UNSUPPORTED","unreachable: a non-identity core without permutation arrays",{directed:t,arcCount:y});const O=Object.freeze({multigraph:$,hasSelfLoops:h>0,arcToEdgeIsIdentity:w,weighted:I!==null,allWeightsOne:l,nonNegativeWeights:u,finiteWeights:a});return{core:m,arcCount:y,selfLoopCount:h,flags:O}}function Ou(n,e){return n instanceof Uint8Array?Ue(e):n instanceof Uint32Array?new Uint32Array(e):n instanceof Int32Array?new Int32Array(e):n instanceof Float32Array?new Float32Array(e):new Float64Array(e)}function _u(n,e){const t=n.validity;let r=null,s=0;for(let o=0;o<e.length;o++){const i=e[o];i!==4294967295&&(t===null||k(t,i))||(r??=ye(e.length,!0),Z(r,o),s++)}return{validity:r,nullCount:s}}function Ln(n,e){return n.nullable||e===0?n:Object.freeze({...n,nullable:!0})}function Du(n,e){for(let t=0;t<e.length;t++){const r=e[t];if(r!==4294967295&&r>=n.length)throw new f("E_INDEX_RANGE",`indexMap[${t}] = ${r} is outside the column of ${n.length} rows`,{index:t,found:r,length:n.length,column:n.meta.name})}}function Tu(n,e,t){const{length:r}=e,{components:s,fill:o}=t,i=Ou(n.data,r*s);typeof o=="number"&&o!==0&&i.fill(o);for(let c=0;c<r;c++){const l=e[c];if(l!==4294967295)for(let u=0;u<s;u++)i[c*s+u]=n.data[l*s+u]}return i}function ku(n,e,t){const{length:r}=e,s=new Uint32Array(v(r)).fill(t.fill===!0?4294967295:0);for(let o=0;o<r;o++){const i=e[o];i!==4294967295&&(k(n.data,i)?K(s,o):Z(s,o))}return s}function vu(n,e,t){const r=typeof t.fill=="string"?n.codeOf(t.fill):4294967295,s=r===4294967295?0:r,o=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const c=e[i];o[i]=c===4294967295?s:n.codes[c]}return o}function xu(n,e,t){const r=typeof t.fill=="string"?t.fill:"",s=new Array(e.length);for(let o=0;o<e.length;o++){const i=e[o];s[o]=i===4294967295?r:n.valueAt(i)}return s}function Su(n,e){const t=new Uint32Array(e.length+1);let r=0;for(let s=0;s<e.length;s++){const o=e[s];o!==4294967295&&(r+=n[o+1]-n[o]),t[s+1]=r}return t}function Uu(n,e,t){const r=new Uint32Array(t);let s=0;for(let o=0;o<e.length;o++){const i=e[o];if(i!==4294967295)for(let c=n[i];c<n[i+1];c++)r[s++]=c}return r}function Pu(n,e){const t=new Array(e.length);for(let r=0;r<e.length;r++){const s=e[r];t[r]=s===4294967295?void 0:n.values[s]}return t}function Mu(n,e,t){const{meta:r}=n,{dtype:s}=e;switch(s){case"f32":case"f64":case"i32":case"u32":case"u8":n.data=Tu(e,t,r);return;case"bool":n.data=ku(e,t,r);return;case"dict":n.data=vu(e,t,r);return;case"string":n.offsets=null,n.utf8=null,n.strings=xu(e,t,r);return;case"list":{const o=Su(e.offsets,t);n.offsets=o,n.child=gt(e.child,Uu(e.offsets,t,o[t.length]));return}case"json":n.values=Pu(e,t);return;default:{const o=s;throw new f("E_COLUMN_TYPE",`unknown dtype ${o}`,{dtype:o})}}}function gt(n,e){Du(n,e);const{validity:t,nullCount:r}=_u(n,e),s={...St(n),meta:Ln(n.meta,r),length:e.length,validity:t};return Mu(s,n,e),F(s)}function eo(n,e){if(n.meta.refersTo===null)return n;const t=r=>r===4294967295||r>=e.length?4294967295:e[r];if(n.dtype==="u32"){const{length:r}=n,s=new Uint32Array(r);let o=n.validity===null?null:n.validity.slice(),{nullCount:i}=n;for(let l=0;l<r;l++){const u=t(n.data[l]);s[l]=u,u===4294967295&&(o===null||k(o,l))&&(o??=ye(r,!0),Z(o,l),i++)}const c={...St(n),meta:Ln(n.meta,i),data:s,validity:o};return F(c)}if(n.dtype==="list"&&n.child.dtype==="u32"){const{length:r,offsets:s,child:o}=n,i=new Array(r);let c=n.validity===null?null:n.validity.slice(),{nullCount:l}=n;for(let g=0;g<r;g++){const h=[],y=s[g],w=s[g+1];for(let m=y;m<w;m++){const A=t(o.data[m]);A!==4294967295&&h.push(A)}i[g]=h,w>y&&h.length===0&&(c===null||k(c,g))&&(c??=ye(r,!0),Z(c,g),l++)}const u=Ln(n.meta,l),a=ut(Object.freeze({...u,nullable:!0}),i),d={...St(a),meta:u,validity:c};return F(d)}throw new f("E_COLUMN_TYPE",`column "${n.meta.name}" has refersTo but is not u32 or a list of u32`,{column:n.meta.name,field:"refersTo"})}function to(n,e){return n.refersTo==="node"?e.node:n.refersTo==="edge"?e.edge:null}function $n(n,e,t,r){const s=n.rowCount,o=[];for(const i of n){const c=to(i.meta,r);let l=i;c!==null&&(l=eo(i,c)),o.push(l)}return new ce({domain:n.domain,rowCount:s,columns:o})}function no(n,e,t){const r=[];for(const s of n){const o=gt(s,e),i=to(s.meta,t);r.push(i===null?o:eo(o,i))}return new ce({domain:n.domain,rowCount:e.length,columns:r})}function Vu(n,e){return ye(n,e===!0)}function Ru(n,e){return k(n,e)}function Bu(n,e,t){yn(n,e,t)}function lf(n,e){return xe(n,e)}function ro(n,e){return qo(n,e)}function Gt(n,e,t){const r=v(e);if(n.length<r)throw new f("E_MASK_LENGTH",`mask over ${t} has ${n.length} words; ${r} needed for ${e} ${t}`,{found:n.length,required:r,length:e})}const so=Object.freeze({droppedEdges:0,mergedEdges:0});function Wr(){return{parts:null,nodeOrigin:null,edgeOrigin:null,nodeRemap:null,edgeRemap:null,blockSizes:null,report:so}}function bt(n,e={}){const t=Cn(n,e.arena!==!1),{core:r}=t;return{arcCount:t.arcCount,selfLoopCount:t.selfLoopCount,rowPtr:r.rowPtr,colIdx:r.colIdx,weights:r.weights,arcToEdge:r.arcToEdge,edgeToArc:r.edgeToArc,flags:t.flags,arena:r.arena}}function It(n,e,t){return{label:n.label,serial:null,directed:t.directed,nodeCount:t.nodeCount,edgeCount:t.edgeCount,arcCount:e.arcCount,selfLoopCount:e.selfLoopCount,rowPtr:e.rowPtr,colIdx:e.colIdx,weights:e.weights,arcToEdge:e.arcToEdge,edgeToArc:e.edgeToArc,flags:e.flags,ids:t.ids,nodes:t.nodes,edges:t.edges,graph:n.graph,extensions:t.extensions,meta:n.meta,arena:e.arena,checksum:!1}}function Et(n,e,t){if(e===null&&t===null||n.extensions.size===0)return n.extensions;const r=new Map;for(const[s,o]of n.extensions)r.set(s,$n(o,null,o.rowCount,{node:e,edge:t}));return r}function Wu(n,e){const t=new Uint32Array(e).fill(4294967295);for(let r=0;r<n.length;r++){const s=n[r];s!==4294967295&&t[s]===4294967295&&(t[s]=r)}return t}function Yt(n){const e=n.length,t=new Uint32Array(e).fill(4294967295);let r=0,s=0,o=0;for(let c=0;c<e;c++)n[c]===c?t[c]=r++:n[c]===4294967295?s++:o++;if(s===0&&o===0)return{count:r,remap:null,origin:null,dropped:s,merged:o};const i=new Uint32Array(e);for(let c=0;c<e;c++){const l=n[c];i[c]=l===4294967295?4294967295:t[l]}return{count:r,remap:i,origin:Wu(i,r),dropped:s,merged:o}}function Xu(n,e){return n.length===e&&Ke(n)}function At(n,e,t){const{count:r,origin:s}=e,o=new Uint32Array(r),i=new Uint32Array(r);for(let c=0;c<r;c++){const l=s===null?c:s[c];o[c]=t===null?n.src[l]:t[n.src[l]],i[c]=t===null?n.dst[l]:t[n.dst[l]]}return{src:o,dst:i}}function On(n,e){if(e!==void 0)for(const t of Object.keys(e))G(`${n}.${t}`,e[t],Li)}function Nt(n,e,t){const{count:r,remap:s,origin:o}=e;if(n===null){if(t!=="sum")return null;const c=new Float32Array(r);if(s===null)return c.fill(1),c;for(let l=0;l<s.length;l++)s[l]!==4294967295&&c[s[l]]++;return c}if(s===null||o===null)return n;const i=new Float32Array(r);for(let c=0;c<r;c++)i[c]=n[o[c]];if(t==="first")return i;for(let c=0;c<s.length;c++){const l=s[c];if(l===4294967295||o[l]===c)continue;const u=n[c];switch(t){case"last":i[l]=u;break;case"sum":i[l]+=u;break;case"min":u<i[l]&&(i[l]=u);break;case"max":u>i[l]&&(i[l]=u);break;default:{const a=t;throw new f("E_UNSUPPORTED",`unknown weight reducer ${String(a)}`,{reducer:a})}}}return i}function Vt(n,e){const t=new Uint32Array(n);for(let r=0;r<n;r++)t[r]=e(r)?r:4294967295;return Yt(t)}function ju(n,e,t){const{count:r,remap:s}=e,{components:o}=n.meta,i=o,c=new Float64Array(r*i),l=new Uint32Array(r),u=new Uint8Array(r),a=n.data,d=s===null?n.length:s.length;for(let p=0;p<d;p++){const I=s===null?p:s[p];if(!(I===4294967295||!n.isSet(p))){l[I]++;for(let N=0;N<i;N++){const T=a[p*i+N],$=I*i+N;if(u[I]===0)c[$]=T;else switch(t){case"sum":case"mean":c[$]+=T;break;case"min":T<c[$]&&(c[$]=T);break;case"max":T>c[$]&&(c[$]=T);break;default:{const O=t;throw new f("E_UNSUPPORTED",`unknown reducer ${String(O)}`,{reducer:O})}}}u[I]=1}}if(t==="mean"){for(let p=0;p<r;p++)if(l[p]>1)for(let I=0;I<i;I++)c[p*i+I]/=l[p]}const h=t==="mean"||t==="sum"&&n.dtype!=="f32"&&n.dtype!=="f64"?"f64":n.dtype;let y;switch(h){case"f64":y=c;break;case"f32":y=new Float32Array(c);break;case"i32":y=new Int32Array(c);break;case"u32":y=new Uint32Array(c);break;case"u8":y=new Uint8Array(new ArrayBuffer(Math.ceil(r*i/4)*4),0,r*i),y.set(c);break;default:{const p=h;throw new f("E_COLUMN_TYPE",`cannot reduce a ${String(p)} column`,{dtype:p})}}let w=null,m=0;for(let p=0;p<r;p++)u[p]===0&&(w??=ye(r,!0),Z(w,p),m++);const A=B(n.meta.name,n.meta.domain,{dtype:h,components:o,nullable:n.meta.nullable||m>0,role:n.meta.role??void 0,extra:n.meta.extra});return F({...qe(A,r,w),data:y})}function Fu(n,e){const{count:t,remap:r}=e,s=new Uint32Array(t);if(r===null)s.fill(1);else for(let i=0;i<r.length;i++)r[i]!==4294967295&&s[r[i]]++;const o=B(n.meta.name,n.meta.domain,{dtype:"u32",nullable:!1,role:n.meta.role??void 0,extra:n.meta.extra});return F({...qe(o,t,null),data:s})}function qn(n,e,t){if(t==="drop"||n.meta.refersTo!==null)return null;const{count:r,remap:s,origin:o}=e;switch(t){case"first":return o===null?n:gt(n,o);case"last":{if(s===null)return n;const i=new Uint32Array(r);for(let c=0;c<s.length;c++)s[c]!==4294967295&&(i[s[c]]=c);return gt(n,i)}case"count":return Fu(n,e);case"sum":case"min":case"max":case"mean":{const{dtype:i}=n;switch(i){case"f32":case"f64":case"i32":case"u32":case"u8":return ju(n,e,t);case"bool":case"dict":case"string":case"list":case"json":throw new f("E_COLUMN_TYPE",`reducer "${t}" needs a numeric column; "${n.meta.name}" is ${i}`,{column:n.meta.name,dtype:i,reducer:t});default:{const c=i;throw new f("E_COLUMN_TYPE",`unknown dtype ${String(c)}`,{dtype:c})}}}default:{const i=t;throw new f("E_UNSUPPORTED",`unknown column reducer ${String(i)}`,{reducer:i})}}}function Ht(n,e,t,r){const s={node:r,edge:e.remap};if(t===void 0||Object.keys(t).length===0)return e.origin===null?r===null?n.edges:$n(n.edges,null,n.edgeCount,s):no(n.edges,e.origin,s);const o=[];for(const c of n.edges){const l=t[c.meta.name];if(l===void 0){const a=e.origin===null?c:gt(c,e.origin);o.push(a);continue}const u=qn(c,e,l);u!==null&&o.push(u)}const i=new ce({domain:"edge",rowCount:e.count,columns:o});return $n(i,null,e.count,s)}function oo(n,e,t){const r=Vt(n.edgeCount,t),{src:s,dst:o}=At(e,r,null),i=Nt(e.weights,r,"first"),c=bt({directed:n.directed,nodeCount:n.nodeCount,edgeCount:r.count,src:s,dst:o,weights:i}),l=Ht(n,r,void 0,null);return{parts:It(n,c,{directed:n.directed,nodeCount:n.nodeCount,edgeCount:r.count,ids:n.ids,nodes:n.nodes,edges:l,extensions:Et(n,null,r.remap)}),nodeOrigin:null,edgeOrigin:r.origin,nodeRemap:null,edgeRemap:r.remap,blockSizes:null,report:{droppedEdges:r.dropped,mergedEdges:0}}}function zu(n,e,t){return Gt(t,n.edgeCount,"edges"),oo(n,e,r=>Ru(t,r))}function Gu(n,e){return oo(n,e,t=>e.src[t]!==e.dst[t])}function Xr(n,e,t,r){return new f("E_INDEX_RANGE",`inducedSubgraph selection[${n}] = ${e} is ${r} (nodeCount ${t})`,{index:n,found:e,nodeCount:t,reason:r})}function Yu(n,e){const{nodeCount:t}=n;if(e instanceof Uint32Array){const r=new Uint8Array(t),s=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const i=e[o];if(i>=t)throw Xr(o,i,t,"out of range");if(r[i]===1)throw Xr(o,i,t,"repeated");r[i]=1,s[o]=i}return s}return Gt(e.mask,t,"nodes"),ro(e.mask,t)}function io(n,e){const t=new Uint32Array(e).fill(4294967295);for(let r=0;r<n.length;r++)t[n[r]]=r;return t}function co(n,e,t,r){const s=t===null?n.nodeCount:t.length,o=t===null?null:io(t,n.nodeCount),{src:i,dst:c}=At(e,r,o),l=Nt(e.weights,r,"first"),u=bt({directed:n.directed,nodeCount:s,edgeCount:r.count,src:i,dst:c,weights:l}),a={node:o,edge:r.remap},d=t===null?n.nodes:no(n.nodes,t,a),g=t===null?n.ids:Wi(n.ids,t),h=Ht(n,r,void 0,o);return{parts:It(n,u,{directed:n.directed,nodeCount:s,edgeCount:r.count,ids:g,nodes:d,edges:h,extensions:Et(n,o,r.remap)}),nodeOrigin:t,edgeOrigin:r.origin,nodeRemap:o,edgeRemap:r.remap,blockSizes:null,report:{droppedEdges:r.dropped,mergedEdges:r.merged}}}function Hu(n,e,t){const r=Yu(n,t),s=Xu(r,n.nodeCount),o=s?null:r,i=s?null:io(r,n.nodeCount),c=i===null?Vt(n.edgeCount,()=>!0):Vt(n.edgeCount,l=>i[e.src[l]]!==4294967295&&i[e.dst[l]]!==4294967295);return co(n,e,o,c)}function qu(n,e,t){const{nodeCount:r}=n;if(t.length!==r)throw new f("E_INVALID_PERMUTATION",`perm has ${t.length} entries, expected ${r}`,{expected:r,found:t.length});const s=new Uint8Array(r);for(let c=0;c<r;c++){const l=t[c];if(l>=r||s[l]===1)throw new f("E_INVALID_PERMUTATION",`perm[${c}] = ${l} is out of range or repeated (nodeCount ${r})`,{index:c,found:l,nodeCount:r});s[l]=1}const o=Ke(t)?null:t.slice(),i=Vt(n.edgeCount,()=>!0);return co(n,e,o,i)}function lo(n,e,t){const r=n[e];let s=e+1;for(;s<t&&n[s]===r;)s++;return s}function Ju(n,e,t,r,s){for(let o=0;o<s;o++){const i=e[t+o],c=e[r+o],l=Math.min(i,c),u=Math.max(i,c);n[l]=l,n[u]=l}}function Ku(n,e,t={}){const r=t.reciprocal===!0,s=G("weights",t.weights,Wt)??"first",{nodeCount:o,edgeCount:i,rowPtr:c,colIdx:l,arcToEdge:u}=n,a=new Uint32Array(i);for(let p=0;p<i;p++)a[p]=r&&e.src[p]!==e.dst[p]?4294967295:p;for(let p=0;p<o;p++){const I=c[p+1];let N=c[p];for(;N<I;){const T=l[N],$=lo(l,N,I);if(T>p){const[O,_]=Ft(c,l,T,p);Ju(a,u,N,O,Math.min($-N,_-O))}N=$}}const d=Yt(a),{src:g,dst:h}=At(e,d,null),y=Nt(e.weights,d,s),w=bt({directed:!1,nodeCount:o,edgeCount:d.count,src:g,dst:h,weights:y}),m=Ht(n,d,void 0,null);return{parts:It(n,w,{directed:!1,nodeCount:o,edgeCount:d.count,ids:n.ids,nodes:n.nodes,edges:m,extensions:Et(n,null,d.remap)}),nodeOrigin:null,edgeOrigin:d.origin,nodeRemap:null,edgeRemap:d.remap,blockSizes:null,report:{droppedEdges:d.dropped,mergedEdges:d.merged}}}function Zu(n,e){const{nodeCount:t,edgeCount:r,arcCount:s,selfLoopCount:o}=n,i=e.arcToEdge,c=Ke(i);let l=null,u=null;if(!c){l=i,u=new Uint32Array(r);for(let g=0;g<s;g++)u[i[g]]=g}const a=Ms({directed:!0,nodeCount:t,rowPtr:e.rowPtr,colIdx:e.colIdx,weights:e.weights,arcToEdge:l,selfLoopCount:o});return Ee(e.rowPtr.buffer),Ee(e.colIdx.buffer),e.weights!==null&&Ee(e.weights.buffer),l!==null&&Ee(l.buffer),{parts:{label:n.label,serial:null,directed:!0,nodeCount:t,edgeCount:r,arcCount:s,selfLoopCount:o,rowPtr:e.rowPtr,colIdx:e.colIdx,weights:e.weights,arcToEdge:l,edgeToArc:u,flags:a,ids:n.ids,nodes:n.nodes,edges:n.edges,graph:n.graph,extensions:n.extensions,meta:n.meta,arena:null,checksum:!1},nodeOrigin:null,edgeOrigin:null,nodeRemap:null,edgeRemap:null,blockSizes:null,report:so}}function Qu(n,e,t={}){const r=G("weights",t.weights,Wt)??"first",s=G("selfLoops",t.selfLoops,["keep","drop"])==="drop";On("edgeReducers",t.edgeReducers);const{nodeCount:o,edgeCount:i,rowPtr:c,colIdx:l,arcToEdge:u}=n,a=new Uint32Array(i).fill(4294967295);for(let p=0;p<o;p++){const I=c[p+1];let N=c[p];for(;N<I;){const T=l[N],$=lo(l,N,I);if((n.directed||T>=p)&&!(T===p&&s)){const O=u[N];for(let _=N;_<$;_++)a[u[_]]=O}N=$}}const d=Yt(a),{src:g,dst:h}=At(e,d,null),y=Nt(e.weights,d,r),w=bt({directed:n.directed,nodeCount:o,edgeCount:d.count,src:g,dst:h,weights:y}),m=Ht(n,d,t.edgeReducers,null);return{parts:It(n,w,{directed:n.directed,nodeCount:o,edgeCount:d.count,ids:n.ids,nodes:n.nodes,edges:m,extensions:Et(n,null,d.remap)}),nodeOrigin:null,edgeOrigin:d.origin,nodeRemap:null,edgeRemap:d.remap,blockSizes:null,report:{droppedEdges:d.dropped,mergedEdges:d.merged}}}function ea(n,e){const t=n.length,r=e??new Uint32Array(t);if(r.length!==t)throw new f("E_COLUMN_LENGTH",`out has ${r.length} entries, expected ${t}`,{expected:t,found:r.length});let s=0;for(let i=0;i<t;i++){const c=n[i];if(c===4294967295)throw new f("E_PARTITION",`labels[${i}] is INVALID_INDEX`,{index:i});c>s&&(s=c)}const o=s<4*t+1024?ta(n,r,s):na(n,r);return{labels:r,count:o}}function ta(n,e,t){const r=new Uint32Array(t+1).fill(4294967295);let s=0;for(let o=0;o<n.length;o++){const i=n[o];let c=r[i];c===4294967295&&(c=s++,r[i]=c),e[o]=c}return s}function na(n,e){const t=new Map;let r=0;for(let s=0;s<n.length;s++){const o=n[s];let i=t.get(o);i===void 0&&(i=r++,t.set(o,i)),e[s]=i}return r}function ra(n,e){if(n.length!==e)throw new f("E_PARTITION",`partition has ${n.length} entries, expected nodeCount ${e}`,{expected:e,found:n.length});let t=-1;for(let r=0;r<e;r++){const s=n[r];if(s===4294967295)throw new f("E_PARTITION",`partition[${r}] is INVALID_INDEX`,{index:r});s>t&&(t=s)}if(t<e){const r=new Uint8Array(t+1);let s=0;for(let o=0;o<e;o++)r[n[o]]===0&&(r[n[o]]=1,s++);if(s===t+1)return{labels:n.slice(),count:t+1}}return ea(n)}function sa(n,e,t,r,s){const o=[];if(s!==void 0){const i={count:t,remap:e,origin:r};for(const c of n.nodes){const l=s[c.meta.name];if(l===void 0)continue;const u=qn(c,i,l);u!==null&&o.push(u)}}return new ce({domain:"node",rowCount:t,columns:o})}function oa(n,e,t){const r=n.length,s=[];for(let a=0;a<r;a++)n[a]!==4294967295&&s.push(a);const o=new Uint32Array(t+1);for(const a of s)o[e[a]+1]++;for(let a=0;a<t;a++)o[a+1]+=o[a];const i=new Uint32Array(s.length);for(const a of s)i[o[e[a]]++]=a;o.fill(0);for(const a of s)o[n[a]+1]++;for(let a=0;a<t;a++)o[a+1]+=o[a];const c=new Uint32Array(s.length);for(let a=0;a<i.length;a++){const d=i[a];c[o[n[d]]++]=d}const l=new Uint32Array(r).fill(4294967295);let u=0;for(;u<c.length;){const a=c[u];let d=u+1;for(;d<c.length&&n[c[d]]===n[a]&&e[c[d]]===e[a];)d++;for(let g=u;g<d;g++)l[c[g]]=a;u=d}return l}function ia(n,e,t,r={}){const s=G("weights",r.weights,Wt)??"sum",o=G("selfLoops",r.selfLoops,["keep","drop"])==="drop",i=(G("parallel",r.parallel,["merge","keep"])??"merge")==="merge";On("nodeReducers",r.nodeReducers),On("edgeReducers",r.edgeReducers);const{nodeCount:c,edgeCount:l}=n,{labels:u,count:a}=ra(t,c),d=new Uint32Array(a),g=new Uint32Array(a).fill(4294967295);for(let C=0;C<c;C++){const L=u[C];d[L]++,g[L]===4294967295&&(g[L]=C)}const h=new Uint32Array(l),y=new Uint32Array(l);for(let C=0;C<l;C++){const L=u[e.src[C]],Y=u[e.dst[C]];L===Y&&o?(h[C]=4294967295,y[C]=4294967295):n.directed||L<=Y?(h[C]=L,y[C]=Y):(h[C]=Y,y[C]=L)}let w;if(i)w=oa(h,y,a);else{w=new Uint32Array(l);for(let C=0;C<l;C++)w[C]=h[C]===4294967295?4294967295:C}const m=Yt(w),{src:A,dst:p}=At(e,m,u),I=Nt(e.weights,m,s),N=bt({directed:n.directed,nodeCount:a,edgeCount:m.count,src:A,dst:p,weights:I}),T=sa(n,u,a,g,r.nodeReducers),$=[];if(r.edgeReducers!==void 0)for(const C of n.edges){const L=r.edgeReducers[C.meta.name];if(L===void 0)continue;const Y=qn(C,m,L);Y!==null&&$.push(Y)}const O=new ce({domain:"edge",rowCount:m.count,columns:$});return{parts:It(n,N,{directed:n.directed,nodeCount:a,edgeCount:m.count,ids:Cs(a),nodes:T,edges:O,extensions:Et(n,u,m.remap)}),nodeOrigin:g,edgeOrigin:m.origin,nodeRemap:u,edgeRemap:m.remap,blockSizes:d,report:{droppedEdges:m.dropped,mergedEdges:m.merged}}}function ca(n,e,t,r,s){return{label:n.label,serial:n.serial,directed:n.directed,nodeCount:n.nodeCount,edgeCount:n.edgeCount,arcCount:n.arcCount,selfLoopCount:n.selfLoopCount,rowPtr:n.rowPtr,colIdx:n.colIdx,weights:n.weights,arcToEdge:r,edgeToArc:s,flags:n.flags,ids:n.ids,nodes:Er(n.nodes,e??{}),edges:Er(n.edges,t??{}),graph:n.graph.clone(),extensions:n.extensions,meta:n.meta,arena:n.arena,checksum:!1}}const la=2166136261,ua=16777619,aa=3421674724,da=1540483477;class Jn{constructor(){this.laneA=la,this.laneB=aa}word(e){const t=e>>>0;this.laneA=Math.imul(this.laneA^t,ua)>>>0;const r=(t<<16|t>>>16)>>>0;return this.laneB=Math.imul(this.laneB^r,da)>>>0,this}words(e){this.word(e.length);for(let t=0;t<e.length;t++)this.word(e[t]);return this}identity(e){this.word(e);for(let t=0;t<e;t++)this.word(t);return this}bytes(e){const{byteLength:t,byteOffset:r}=e;if(this.word(t),r%4===0&&t%4===0){const i=new Uint32Array(e.buffer,r,t/4);for(let c=0;c<i.length;c++)this.word(i[c]);return this}const s=new Uint8Array(e.buffer,r,t);let o=0;for(;o+4<=t;o+=4)this.word(s[o]|s[o+1]<<8|s[o+2]<<16|s[o+3]<<24);if(o<t){let i=0;for(let c=0;o+c<t;c++)i|=s[o+c]<<8*c;this.word(i)}return this}text(e){this.word(e.length);for(let t=0;t<e.length;t++)this.word(e.charCodeAt(t));return this}digest(){return this.laneA.toString(16).padStart(8,"0")+this.laneB.toString(16).padStart(8,"0")}}function te(n){return new Jn().bytes(n).digest()}function uo(n,e){n.text(e.dtype).word(e.length).word(e.nullCount),e.validity!==null?n.words(e.validity):n.word(0);const{dtype:t}=e;switch(t){case"f32":case"f64":case"i32":case"u32":case"u8":case"bool":n.bytes(e.data);break;case"dict":n.words(e.codes).word(e.dictionary.length);for(const r of e.dictionary)n.text(r);break;case"string":n.words(e.offsets).bytes(e.utf8);break;case"list":n.words(e.offsets),uo(n,e.child);break;case"json":n.text(JSON.stringify(e.values));break;default:Yo(t)}}function ao(n){if(Vn(n))throw new f("E_DETACHED",`column "${n.meta.name}" was transferred away`,{column:n.meta.name});const e=new Jn;return uo(e,n),e.digest()}function fa(n){const e=new Jn;return e.word(n.directed?1:0).word(n.nodeCount).word(n.edgeCount).word(n.arcCount).word(n.selfLoopCount),e.words(n.rowPtr).words(n.colIdx),n.weights===null?e.word(0):e.bytes(n.weights),n.flags.arcToEdgeIsIdentity?e.identity(n.arcCount).identity(n.edgeCount):e.words(n.arcToEdge).words(n.edgeToArc),e.digest()}let ha=1;const kt=["reverse","coo","edgeList","outDegree","inDegree","degree","weightedOutDegree","weightedInDegree","weightedDegree","selfLoopWeight","totalWeight","selfLoopArcs","selfLoopsPerNode","mate","degreeOrder","reverseDegreeOrder","symmetric"],ga="__graphtyNoStructuredClone";function wa(){}const Kn=new WeakMap;function ya(){return{reverse:null,coo:null,edgeList:null,outDegree:null,inDegree:null,degree:null,weightedOutDegree:null,weightedInDegree:null,weightedDegree:null,selfLoopWeight:null,totalWeight:null,selfLoopArcs:null,selfLoopsPerNode:null,mate:null,degreeOrder:null,reverseDegreeOrder:null,symmetric:null}}function ue(n,e,t){return new f("E_INVALID_SNAPSHOT",`invariant ${n} violated: ${e}`,{invariant:n,...t})}function ma(n){const{nodeCount:e,edgeCount:t,arcCount:r,flags:s}=n;if(n.rowPtr.length!==e+1)throw ue("I1",`rowPtr has ${n.rowPtr.length} entries, expected ${e+1}`,{expected:e+1,found:n.rowPtr.length});if(n.colIdx.length!==r)throw ue("I1",`colIdx has ${n.colIdx.length} entries, expected ${r}`,{expected:r,found:n.colIdx.length});if(n.weights!==null&&n.weights.length!==r)throw ue("I8",`weights has ${n.weights.length} entries, expected ${r}`,{expected:r,found:n.weights.length});const o=s.arcToEdgeIsIdentity;if(n.arcToEdge===null!==o||n.edgeToArc===null!==o)throw ue("I9","arcToEdge / edgeToArc must be null exactly when flags.arcToEdgeIsIdentity",{flag:"arcToEdgeIsIdentity",found:o});if(o&&(!n.directed||r!==t))throw ue("I9","flags.arcToEdgeIsIdentity requires a directed snapshot with arcCount === edgeCount",{flag:"arcToEdgeIsIdentity",directed:n.directed,arcCount:r,edgeCount:t});if(n.arcToEdge!==null&&n.arcToEdge.length!==r)throw ue("I5",`arcToEdge has ${n.arcToEdge.length} entries, expected ${r}`,{expected:r,found:n.arcToEdge.length});if(n.edgeToArc!==null&&n.edgeToArc.length!==t)throw ue("I5",`edgeToArc has ${n.edgeToArc.length} entries, expected ${t}`,{expected:t,found:n.edgeToArc.length});if(n.ids.size!==e)throw ue("I11",`ids.size is ${n.ids.size}, expected ${e}`,{expected:e,found:n.ids.size});if(n.nodes.rowCount!==e||n.edges.rowCount!==t||n.graph.rowCount!==1)throw ue("I12","table row counts do not match nodeCount / edgeCount / 1",{nodes:n.nodes.rowCount,edges:n.edges.rowCount,graph:n.graph.rowCount})}function _t(n,e){for(const t of e)t.meta.mutable||n.columns.set(t,ao(t))}const pa=class _n{constructor(e){ma(e),this[es]=!0,this.serial=e.serial??ha++,this.label=e.label,this.formatVersion=1,this.directed=e.directed,this.nodeCount=e.nodeCount,this.edgeCount=e.edgeCount,this.arcCount=e.arcCount,this.selfLoopCount=e.selfLoopCount,this.rowPtr=e.rowPtr,this.colIdx=e.colIdx,this.weights=e.weights,this.flags=Object.freeze({...e.flags}),this.ids=e.ids,this.nodes=e.nodes,this.edges=e.edges,this.graph=e.graph,this.extensions=e.extensions,this.meta=e.meta,this.arena=e.arena;let t=null;if(e.checksum){t={core:new Map,columns:new WeakMap,views:new Map},t.core.set("rowPtr",te(e.rowPtr)),t.core.set("colIdx",te(e.colIdx)),e.weights!==null&&t.core.set("weights",te(e.weights)),e.arcToEdge!==null&&t.core.set("arcToEdge",te(e.arcToEdge)),e.edgeToArc!==null&&t.core.set("edgeToArc",te(e.edgeToArc)),_t(t,e.nodes),_t(t,e.edges),_t(t,e.graph);for(const s of e.extensions.values())_t(t,s)}const r={arcToEdge:e.arcToEdge,edgeToArc:e.edgeToArc,views:ya(),checksums:t,contentHash:null,edgeIds:null};Object.defineProperty(this,"state",{value:r,enumerable:!1,writable:!1,configurable:!1}),Kn.set(this,r),Ia(e),Object.defineProperty(this,ga,{value:wa,enumerable:!0,writable:!1,configurable:!1}),Object.freeze(this)}get detached(){return this.rowPtr.length===0}get arcToEdge(){this.assertAttached();const{state:e}=this;return e.arcToEdge===null&&(e.arcToEdge=En(this.arcCount),e.checksums?.core.set("arcToEdge",te(e.arcToEdge))),e.arcToEdge}get edgeToArc(){this.assertAttached();const{state:e}=this;return e.edgeToArc===null&&(e.edgeToArc=En(this.edgeCount),e.checksums?.core.set("edgeToArc",te(e.edgeToArc))),e.edgeToArc}outArcs(e){return this.assertAttached(),[this.rowPtr[e],this.rowPtr[e+1]]}outDegreeOf(e){return this.assertAttached(),this.rowPtr[e+1]-this.rowPtr[e]}findArc(e,t){return this.assertAttached(),mc(this.rowPtr,this.colIdx,e,t)}hasArc(e,t){return this.findArc(e,t)!==4294967295}arcsBetween(e,t){return this.assertAttached(),Ft(this.rowPtr,this.colIdx,e,t)}multiplicity(e,t){return this.assertAttached(),ks(this.rowPtr,this.colIdx,e,t)}arcSource(e){this.assertAttached();const{coo:t}=this.state.views;return t!==null?t.src[e]:pc(this.rowPtr,e)}edgeSource(e){this.assertAttached();const t=this.state.views.edgeList;return t!==null?t.src[e]:this.arcSource(this.edgeToArc[e])}edgeTarget(e){return this.colIdx[this.edgeToArc[e]]}edgeIndexOf(e){const{state:t}=this,r=oc(this.edges);if(t.edgeIds?.version!==r){const s=this.edges.byRole("id");t.edgeIds={version:r,column:s,index:s===null?null:new dc(s)}}return t.edgeIds.index===null?4294967295:t.edgeIds.index.indexOf(e)}reverse(){return this.cached("reverse",()=>Ec(this))}coo(){return this.cached("coo",()=>Ac(this))}edgeList(){return this.cached("edgeList",()=>Ar(this))}outDegree(){return this.cached("outDegree",()=>Me(this.rowPtr,this.nodeCount))}inDegree(){return this.cached("inDegree",()=>this.directed?Me(this.reverse().rowPtr,this.nodeCount):this.outDegree())}degree(){return this.cached("degree",()=>Nc(this.outDegree(),this.directed?this.inDegree():this.selfLoopsPerNode()))}weightedOutDegree(){return this.cached("weightedOutDegree",()=>this.weights===null?Nn(this.outDegree()):Nr(this.rowPtr,this.weights,this.nodeCount))}weightedInDegree(){return this.cached("weightedInDegree",()=>{if(!this.directed)return this.weightedOutDegree();const e=this.reverse();return e.weights===null?Nn(this.inDegree()):Nr(e.rowPtr,e.weights,this.nodeCount)})}weightedDegree(){return this.cached("weightedDegree",()=>Cc(this.weightedOutDegree(),this.directed?this.weightedInDegree():this.selfLoopWeight()))}selfLoopWeight(){return this.cached("selfLoopWeight",()=>Oc(this,{selfLoopArcs:this.selfLoopArcs(),selfLoopsPerNode:this.selfLoopsPerNode()}))}totalWeight(){return this.cached("totalWeight",()=>Lc(this))}selfLoopArcs(){return this.cached("selfLoopArcs",()=>this.materialiseSelfLoops().selfLoopArcs)}selfLoopsPerNode(){return this.cached("selfLoopsPerNode",()=>this.materialiseSelfLoops().selfLoopsPerNode)}selfLoopsAt(e){return this.assertAttached(),bc(this.rowPtr,this.colIdx,e)}mate(){return this.cached("mate",()=>Dc(this))}degreeOrder(e){if((G("of",e?.of,["forward","reverse"])??"forward")==="reverse"&&this.directed)return this.cached("reverseDegreeOrder",()=>Cr(this.reverse().rowPtr,this.nodeCount));const r=this.cached("degreeOrder",()=>Cr(this.rowPtr,this.nodeCount));return this.directed||(this.state.views.reverseDegreeOrder=r),r}isSymmetric(){return this.cached("symmetric",()=>this.directed?Tc(this,this.reverse()):!0)}prepare(e){for(const t of e)this.materialiseView(t);return this}dropCaches(){const{state:e}=this;for(const t of kt)e.views[t]=null;e.checksums?.views.clear(),this.flags.arcToEdgeIsIdentity&&(e.arcToEdge=null,e.edgeToArc=null,e.checksums?.core.delete("arcToEdge"),e.checksums?.core.delete("edgeToArc"));for(const t of[this.nodes,this.edges,this.graph,...this.extensions.values()])for(const r of t)gi(r)}cachedViews(){if(this.detached)return this.dropCaches(),[];const{views:e}=this.state;return kt.filter(t=>e[t]!==null)}toUndirected(e){return this.assertAttached(),this.directed?this.wrapDerived(Ku(this,this.edgeEndpoints(),e)):this.wrapDerived(Wr())}transpose(){return this.assertAttached(),this.directed?this.wrapDerived(Zu(this,this.reverse())):this.wrapDerived(Wr())}simplified(e){return this.assertAttached(),this.wrapDerived(Qu(this,this.edgeEndpoints(),e))}withoutSelfLoops(){return this.assertAttached(),this.wrapDerived(Gu(this,this.edgeEndpoints()))}filterEdges(e){return this.assertAttached(),this.wrapDerived(zu(this,this.edgeEndpoints(),e))}inducedSubgraph(e){return this.assertAttached(),this.wrapDerived(Hu(this,this.edgeEndpoints(),e))}contract(e,t){return this.assertAttached(),this.wrapDerived(ia(this,this.edgeEndpoints(),e,t))}relabel(e){return this.assertAttached(),this.wrapDerived(qu(this,this.edgeEndpoints(),e))}seal(){Lt(this.nodes),Lt(this.edges),Lt(this.graph);for(const e of this.extensions.values())Lt(e)}withColumns(e,t){this.assertAttached();const r=this.flags.arcToEdgeIsIdentity,s=ca(this,e,t,r?null:this.arcToEdge,r?null:this.edgeToArc);return new _n({...s,checksum:this.state.checksums!==null})}byteLength(e={}){let t=this.rowPtr.byteLength+this.colIdx.byteLength;return this.weights!==null&&(t+=this.weights.byteLength),this.flags.arcToEdgeIsIdentity||(t+=this.arcToEdge.byteLength+this.edgeToArc.byteLength),e.views===!0&&(t+=Ea(this,this.state.views)),e.columns===!0&&(t+=Aa(this)),e.ids===!0&&(t+=this.ids.byteLength()),t}contentHash(){this.assertAttached();const{state:e}=this;return e.contentHash??=fa(this),e.contentHash}transferables(){return this.assertAttached(),Dl(this)}toWire(e){return this.assertAttached(),_l(this,e)}toBytes(e){return this.assertAttached(),uu(this,e)}toByteChunks(e){return this.assertAttached(),du(this,e)}validate(e={}){this.assertAttached();const t=G("level",e.level,["structure","full"])??"full";if(typeof e.checksum!="boolean"&&e.checksum!==void 0)throw new f("E_UNSUPPORTED","validate option checksum must be a boolean",{field:"checksum",found:e.checksum,reason:"unsupported option"});if(Oi(this.ids))throw new f("E_DETACHED","the id map's storage was transferred away",{serial:this.serial});for(const r of[this.nodes,this.edges,this.graph,...this.extensions.values()])for(const s of r)if(Vn(s))throw new f("E_DETACHED",`column "${s.meta.name}" was transferred away`,{column:s.meta.name,serial:this.serial});e.checksum===!0&&this.verifyChecksums(),t==="structure"?Bs(this):tl(this)}assertAttached(){if(this.rowPtr.length===0)throw new f("E_DETACHED","the snapshot's core buffer was transferred away",{serial:this.serial})}cached(e,t){this.assertAttached();const{views:r}=this.state,s=r[e];if(s!==null)return s;const o=t();return r[e]=o,this.recordView(e,o),o}materialiseSelfLoops(){const e=$c(this),{views:t}=this.state;return t.selfLoopArcs===null&&(t.selfLoopArcs=e.selfLoopArcs,this.recordView("selfLoopArcs",e.selfLoopArcs)),t.selfLoopsPerNode===null&&(t.selfLoopsPerNode=e.selfLoopsPerNode,this.recordView("selfLoopsPerNode",e.selfLoopsPerNode)),{selfLoopArcs:t.selfLoopArcs,selfLoopsPerNode:t.selfLoopsPerNode}}recordView(e,t){ho(this,this.state,e,t)}verifyChecksums(){const e=this.state.checksums;if(e===null)throw new f("E_INVALID_SNAPSHOT","no checksums were recorded for this snapshot",{reason:"no-checksum"});const t=(i,c)=>new f("E_INVALID_SNAPSHOT",`checksum mismatch: ${i} was modified after freeze`,{reason:"checksum",...c}),{state:r}=this,s=[["rowPtr",this.rowPtr],["colIdx",this.colIdx],["weights",this.weights],["arcToEdge",r.arcToEdge],["edgeToArc",r.edgeToArc]];for(const[i,c]of s){const l=e.core.get(i);if(l!==void 0&&c!==null&&te(c)!==l)throw t(`core array ${i}`,{array:i})}const o=[["nodes",this.nodes],["edges",this.edges],["graph",this.graph],...[...this.extensions].map(([i,c])=>[`extensions[${i}]`,c])];for(const[i,c]of o)for(const l of c){const u=e.columns.get(l);if(u!==void 0&&ao(l)!==u)throw t(`column "${l.meta.name}" of ${i}`,{table:i,column:l.meta.name})}for(const i of kt){const c=r.views[i];if(c!==null)for(const[l,u]of Object.entries(zn(this,i,c))){const a=e.views.get(`${i}.${l}`);if(a!==void 0&&te(u)!==a)throw t(`view ${i}.${l}`,{view:i,member:l})}}}edgeEndpoints(){return this.state.views.edgeList??Ar(this)}wrapDerived(e){return{snapshot:e.parts===null?this:new _n({...e.parts,checksum:this.state.checksums!==null}),nodeOrigin:e.nodeOrigin,edgeOrigin:e.edgeOrigin,nodeRemap:e.nodeRemap,edgeRemap:e.edgeRemap,blockSizes:e.blockSizes,report:e.report}}materialiseView(e){switch(e){case"reverse":this.reverse();break;case"coo":this.coo();break;case"edgeList":this.edgeList();break;case"outDegree":this.outDegree();break;case"inDegree":this.inDegree();break;case"degree":this.degree();break;case"weightedOutDegree":this.weightedOutDegree();break;case"weightedInDegree":this.weightedInDegree();break;case"weightedDegree":this.weightedDegree();break;case"selfLoopWeight":this.selfLoopWeight();break;case"totalWeight":this.totalWeight();break;case"selfLoopArcs":this.selfLoopArcs();break;case"selfLoopsPerNode":this.selfLoopsPerNode();break;case"mate":this.mate();break;case"degreeOrder":this.degreeOrder();break;case"reverseDegreeOrder":this.degreeOrder({of:"reverse"});break;case"symmetric":this.isSymmetric();break;default:{const t=e;throw new f("E_UNSUPPORTED",`unknown view ${String(t)}`,{view:t})}}}};let ba=pa;function Ia(n){const e=new Set([n.rowPtr.buffer,n.colIdx.buffer]);n.weights!==null&&e.add(n.weights.buffer),n.arcToEdge!==null&&e.add(n.arcToEdge.buffer),n.edgeToArc!==null&&e.add(n.edgeToArc.buffer);for(const t of ki(n.ids))e.add(t);for(const t of e)M(t);M(n.ids),M(n.nodes),M(n.edges),M(n.graph);for(const t of n.extensions.values())M(t)}function fo(n){return new ba(n)}function uf(n){if(typeof n!="object"||n===null)return!1;const e=n;return e[es]===!0&&e.formatVersion===1}function Ea(n,e){let t=0;for(const r of kt){const s=e[r];s!==null&&!(r==="reverseDegreeOrder"&&s===e.degreeOrder)&&(t+=xc(n,r,s))}return t}function Aa(n){let e=0;for(const t of[n.nodes,n.edges,n.graph,...n.extensions.values()])for(const r of t)e+=r.byteLength;return e}function ho(n,e,t,r){const s=e.checksums;if(s!==null)for(const[o,i]of Object.entries(zn(n,t,r)))s.views.set(`${t}.${o}`,te(i))}function Ze(n,e,t){const r=Kn.get(n);return r?.views[e]!==null?!1:(r.views[e]=t,ho(n,r,e,t),!0)}function Na(n,e){const t=Kn.get(n);return t===void 0?null:t.views[e]}const Ca=new Set(["keep","error","first","last","sum","min","max"]);function go(n,e,t){if(typeof e!="string"||!Ca.has(e))throw t(n,e);return e}const La="graphty.weight";function rn(){return performance.now()}function $a(n){if(n.selfLoopCount===0)return;const e=n.edgeBound;for(let t=0;t<e;t++)if(n.edgeAlive.get(t)&&n.src.get(t)===n.dst.get(t)){const r=n.src.get(t);throw new f("E_SELF_LOOP",`edge ${t} is a self-loop at node ${r}`,{edge:t,node:r})}}function Oa(n){const e=n.edgeAlive.view().slice(),t=n.src.view(),r=n.dst.view(),s=n.edgeBound;for(let o=0;o<s;o++)t[o]===r[o]&&k(e,o)&&Z(e,o);return e}function jr(n,e){const t=n.edgeBound;return{directed:e,nodeCount:n.nodeBound,edgeCount:t,src:n.src.view(),dst:n.dst.view(),weights:n.weight===null?null:n.weight.view()}}function _a(n,e,t,r,s,o){const{rowPtr:i,colIdx:c,arcToEdge:l}=n.core,u=e.nodeBound,a=e.edgeBound,d={staging:e,weights:e.weight===null?null:e.weight.view(),policy:r,countMultiplicity:s,builderIndex:o},g=new Uint32Array(a);for(let w=0;w<a;w++)g[w]=w;const h={survivorOf:g,reduced:null,stored:null,explicit:null,merged:0},y=[];for(let w=0;w<u;w++){const m=i[w+1];let A=i[w];for(;A<m;){const p=c[A],I=Da(c,A,m);I-A>1&&(t||p>=w)&&(Ta(y,l,A,I),ka(d,h,w,p,y)),A=I}}return h.merged===0?null:{...h}}function Da(n,e,t){const r=n[e];let s=e+1;for(;s<t&&n[s]===r;)s++;return s}function Ta(n,e,t,r){n.length=0;for(let s=t;s<r;s++)n.push(e===null?s:e[s])}function ka(n,e,t,r,s){const{policy:o,staging:i,builderIndex:c}=n;if(o==="error"){const g=[c(s[0]),c(s[1])];throw new f("E_DUPLICATE_EDGE",`edges ${g[0]} and ${g[1]} both connect ${t} -> ${r}`,{source:t,target:r,edges:g})}const l=o==="last"?s[s.length-1]:s[0],u=va(n,t,r,s),a=e.survivorOf.length;u!==null&&(e.reduced??=new Float64Array(a),e.stored??=new Uint32Array(v(a)),e.reduced[l]=u,K(e.stored,l)),(u!==null||s.some(g=>i.weightExplicit(g)))&&!i.weightExplicit(l)&&(e.explicit??=new Uint32Array(v(a)),K(e.explicit,l));for(const g of s)g!==l&&(e.survivorOf[g]=l,e.merged++)}function va(n,e,t,r){const{policy:s}=n;if(s!=="sum"&&s!=="min"&&s!=="max")return null;const o=xa(n.weights,r,s,n.countMultiplicity);if(o!==null&&Number.isNaN(o)){const i=r.map(n.builderIndex);throw new f("E_INVALID_WEIGHT",`duplicateEdges "${s}" over edges ${i.join(", ")} (${e} -> ${t}) yields NaN`,{source:e,target:t,edges:i,policy:s,reason:"reducer"})}return o}function xa(n,e,t,r){if(n===null)return t==="sum"&&r?e.length:null;let s=n[e[0]];for(let o=1;o<e.length;o++){const i=n[e[o]];switch(t){case"sum":s+=i;break;case"min":s=Math.min(s,i);break;case"max":s=Math.max(s,i);break;default:{const c=t;throw new f("E_UNSUPPORTED",`unknown reducer ${c}`,{policy:c})}}}return s}function Sa(n,e,t){const{weight:r}=n;if(r===null||e===0)return null;const s=r.view(),o=t==="f64"&&Ua(s,e),i=n.weightSet!==null||n.weightMode==="omitted";if(!o&&!i)return null;const c=o?"f64":"f32",l=B(La,"edge",{dtype:c,role:"weight",nullable:i}),u=c==="f64"?new Float64Array(e):new Float32Array(e);u.set(s.subarray(0,e));const a=i?Pa(n,e):null;return F({...qe(l,e,a),data:u})}function Ua(n,e){for(let t=0;t<e;t++){const r=n[t];if(Math.fround(r)!==r)return!0}return!1}function Pa(n,e){const t=new Uint32Array(v(e));for(let r=0;r<e;r++)n.weightExplicit(r)&&K(t,r);return t}function Ma(n,e){return n.ids===null||n.idToIndex===null?Cs(e):Ls(n.ids,e,{map:n.idToIndex})}function sn(n,e,t,r=[]){const s=t.map(i=>i.toColumn(e)),o=new ce({domain:n,rowCount:e,columns:[...s,...r]});return lc(o),o}function Va(n){const e=[];for(const[t,r]of n)e.push(Wn("graph",1,t,[r.value],r.decl??{}));return new ce({domain:"graph",rowCount:1,columns:e})}function Ra(n,e,t,r){if(e===null&&t===null)return null;const s=new Uint32Array(n);for(let o=0;o<n;o++){let i=e===null?o:e.remap[o];i!==4294967295&&t!==null&&r!==null&&(i=r.remap[t.survivorOf[i]]),s[o]=i}return Ke(s)?null:s}function Ba(n){const e=new Uint32Array(n);for(let t=0;t<n;t++)e[t]=t;return{remap:e,origin:e,count:n}}function Dt(n,e){return new f("E_UNSUPPORTED",`freeze option ${n} has an unsupported value ${String(e)}`,{field:n,found:e,reason:"unsupported option"})}function Wa(n){n.duplicateEdges!==void 0&&go("duplicateEdges",n.duplicateEdges,Dt);for(const e of["arena","release","profile","checksum"]){const t=n[e];if(t!==void 0&&typeof t!="boolean")throw Dt(e,t)}if(n.label!==void 0&&typeof n.label!="string")throw Dt("label",n.label);if(n.prepare!==void 0&&!Array.isArray(n.prepare))throw Dt("prepare",n.prepare)}function Xa(n,e){const t=e.profile===!0,r={},s=t?rn():0;let o=s;const i=j=>{if(t){const P=rn();r[j]=(r[j]??0)+(P-o),o=P}},{directed:c}=n,l=n.staging;Wa(e);const u=e.arena!==!1,a=e.duplicateEdges??n.options.duplicateEdges,d=n.options.selfLoops,g=l.nodeBound,h=l.edgeBound,y=h-l.liveEdgeCount;d==="error"&&$a(l);const w=c?l.liveEdgeCount:2*l.liveEdgeCount-l.selfLoopCount;if(w>4294967294)throw new f("E_TOO_LARGE",`arc count ${w} exceeds MAX_COUNT`,{count:w,max:4294967294});let m=l,A=null,p=null,I=0;const N=d==="drop"&&l.selfLoopCount>0;if(l.hasTombstones||N){const j=br(g,l.nodeAlive.view()),P=br(h,N?Oa(l):l.edgeAlive.view());I=N?l.selfLoopCount:0,m=Ir(l,{nodes:j,edges:P,edgeValues:null,mergedWeights:null,mergedWeightStored:null,mergedWeightSet:null}),A=j,p=P}i("compact");const T=m.nodeBound;let $=Cn(jr(m,c),u&&a==="keep");i("sort");let O=null,_=null;if(a!=="keep"){const j=p;if(O=_a($,m,c,a,n.options.weighted!==!1,P=>j===null?P:j.origin[P]),O!==null){const{survivorOf:P}=O,le=Qi(P);let qt=null,Jt=null;if(O.reduced!==null&&O.stored!==null){qt=new Float64Array(le.count),Jt=new Uint32Array(v(le.count));for(let x=0;x<P.length;x++)P[x]===x&&k(O.stored,x)&&(qt[le.remap[x]]=O.reduced[x],K(Jt,le.remap[x]))}let Kt=null;if(O.explicit!==null){Kt=new Uint32Array(v(le.count));for(let x=0;x<P.length;x++)P[x]===x&&k(O.explicit,x)&&K(Kt,le.remap[x])}const or=new Uint32Array(P.length);for(let x=0;x<P.length;x++)or[x]=le.remap[P[x]];m=Ir(m,{nodes:Ba(T),edges:le,edgeValues:or,mergedWeights:qt,mergedWeightStored:Jt,mergedWeightSet:Kt}),_=le,$=Cn(jr(m,c),u)}else u&&($={...$,core:yc($.core)});i("duplicates")}const C=m.edgeBound,{core:L,arcCount:Y,selfLoopCount:Io,flags:Eo}=$,Qn=Sa(m,C,n.options.weightDtype);i("weights");const Ao=Ma(m,T);i("ids");const No=sn("node",T,m.nodeColumns),Co=sn("edge",C,m.edgeColumns,Qn===null?[]:[Qn]),Lo=Va(n.graphValues),er=new Map;for(const j of m.extensions)er.set(j.name,sn("extension",j.rowCount,j.columns));i("columns");const $o={label:e.label??null,serial:null,directed:c,nodeCount:T,edgeCount:C,arcCount:Y,selfLoopCount:Io,rowPtr:L.rowPtr,colIdx:L.colIdx,weights:L.weights,arcToEdge:L.arcToEdge,edgeToArc:L.edgeToArc,flags:Eo,ids:Ao,nodes:No,edges:Co,graph:Lo,extensions:er,meta:n.meta,arena:L.arena,checksum:e.checksum===!0},tr=fo($o);e.prepare!==void 0&&e.prepare.length>0&&tr.prepare(e.prepare),i("snapshot"),t&&(r.total=rn()-s);const nr=A!==null&&!Ke(A.remap)?A.remap:null,rr=Ra(h,p,O,_),sr=O===null?0:O.merged,Oo=Object.freeze({nodeRemap:nr,edgeRemap:rr,compacted:nr!==null||rr!==null,droppedSelfLoops:I,mergedEdges:sr,droppedEdges:y+I+sr,widened:Object.freeze(n.widened.map(j=>Object.freeze({...j}))),timings:Object.freeze({...r})});return{snapshot:tr,report:Oo,staging:m}}const ja=new Set(["keep","drop","error"]),Fa=new Set(["f32","f64"]),za="graphty.directed",Ga="graphty.pair";function pe(n,e){return new f("E_UNSUPPORTED",`builder option ${n} has an unsupported value ${String(e)}`,{field:n,found:e,reason:"unsupported option"})}function Ya(n){if(typeof n!="object"||n===null)throw pe("options",n);if(typeof n.directed!="boolean")throw pe("directed",n.directed);const e=n.weighted??"auto";if(e!=="auto"&&typeof e!="boolean")throw pe("weighted",e);const t=n.weightDtype??"f32";if(!Fa.has(t))throw pe("weightDtype",t);const r=go("duplicateEdges",n.duplicateEdges??"keep",pe),s=n.selfLoops??"keep";if(!ja.has(s))throw pe("selfLoops",s);const o=n.addMissingNodes??!0;if(typeof o!="boolean")throw pe("addMissingNodes",o);const i=c=>{const l=n[c];if(l===void 0)return null;if(!Number.isInteger(l)||l<0)throw pe(c,l);return l};return{fixed:{weighted:e,weightDtype:t,duplicateEdges:r,selfLoops:s,addMissingNodes:o,expectedNodes:i("expectedNodes"),expectedEdges:i("expectedEdges")},directed:n.directed}}function Ha(n){const e={};for(const t of Object.keys(n)){const r=n[t];r!==void 0&&(e[t]=r)}return e}function Fr(n,e){return n.dtype===e.dtype&&n.components===e.components&&n.itemDtype===e.itemDtype&&n.itemComponents===e.itemComponents}class Zn{constructor(e){this.locked=!1,this.optionsCache=null,this.nodeNames=null,this.edgeNames=null,this.graphValues=new Map,this.metaValue=Qt,this.widenings=[],this.mutations=0,this.dirtyFlag=!0,this.disposed=!1;const t=Ya(e);this.fixed=t.fixed,this.directedValue=t.directed,this.staging=this.freshStaging()}static from(e,t){const r=Ha(t??{}),s=e.edges.byRole("weight"),o=r.weightDtype??(s!==null&&s.dtype==="f64"?"f64":void 0),i=r.weighted??(e.flags.weighted?!0:void 0),c=new Zn({directed:e.directed,expectedNodes:e.nodeCount,expectedEdges:e.edgeCount,...r,...o===void 0?{}:{weightDtype:o},...i===void 0?{}:{weighted:i}});return c.addGraph(e,{onDuplicateNode:"error"}),c.setMeta(e.meta),c}get options(){return this.check(),this.optionsCache??=Object.freeze({directed:this.directedValue,...this.fixed}),this.optionsCache}get directed(){return this.check(),this.directedValue}get directedLocked(){return this.check(),this.locked}get nodeCount(){return this.check(),this.staging.liveNodeCount}get edgeCount(){return this.check(),this.staging.liveEdgeCount}get nodeBound(){return this.check(),this.staging.nodeBound}get edgeBound(){return this.check(),this.staging.edgeBound}get mutationCount(){return this.check(),this.mutations}get dirty(){return this.check(),this.dirtyFlag}setDirected(e,t){if(this.check(),e!==this.directedValue){if(this.locked)throw new f("E_DIRECTED","the builder's direction is locked",{reason:"locked",directed:this.directedValue});if(this.staging.liveEdgeCount===0){this.directedValue=e,this.optionsCache=null,this.mutated();return}if(!e)throw new f("E_DIRECTED","a builder with edges cannot become undirected",{reason:"edges present",edgeCount:this.staging.liveEdgeCount});if(t?.expand!==!0)throw new f("E_DIRECTED","an undirected builder with edges becomes directed only with { expand: true }",{reason:"expand required",edgeCount:this.staging.liveEdgeCount});this.expandToDirected()}}lockDirected(){this.check(),this.locked=!0}addNode(e){return this.check(),this.addValidatedNode(be(e))}addNodes(e,t){this.check();const s=(Array.isArray(e)?e:[...e]).map(i=>be(i));if(t!==void 0&&t.length<s.length)throw new f("E_COLUMN_LENGTH",`out has ${t.length} entries for ${s.length} ids`,{expected:s.length,found:t.length});const o=t??new Uint32Array(s.length);for(let i=0;i<s.length;i++)o[i]=this.addValidatedNode(s[i]);return o}addAnonymousNodes(e){if(this.check(),!Number.isInteger(e)||e<0)throw new f("E_INDEX_RANGE",`node count ${e} is not a non-negative integer`,{count:e});const{staging:t}=this,r=t.nodeBound;if(this.checkNodeLimit(e),t.idToIndex!==null){for(let s=r;s<r+e;s++)if(t.idToIndex.has(s))throw new f("E_DUPLICATE_ID",`node id ${s} exists; anonymous node ${s} cannot use it`,{id:s,index:t.idToIndex.get(s)})}return t.pushAnonymousNodes(e),e>0&&this.mutated(),r}hasNode(e){return this.check(),this.lookup(e)!==4294967295}indexOf(e){return this.check(),this.lookup(e)}idOf(e){this.check();const{staging:t}=this;if(!this.isLiveNode(e))throw new f("E_INDEX_RANGE",`node index ${e} is out of range or removed`,{index:e,bound:t.nodeBound});return t.ids===null?e:t.ids[e]}removeNode(e){this.check();const t=this.lookup(e);if(t===4294967295)throw new f("E_UNKNOWN_NODE",`unknown node id ${ge(e)}`,{id:e});return this.removeLiveNode(t)}removeNodeByIndex(e){if(this.check(),!this.isLiveNode(e))throw new f("E_UNKNOWN_NODE",`node index ${e} is out of range or removed`,{index:e});return this.removeLiveNode(e)}reserve(e,t){this.check();const r=(i,c)=>{if(c===void 0)return 0;if(!Number.isInteger(c)||c<0||c>4294967294)throw new f("E_TOO_LARGE",`reserve(${i}) ${c} is not an integer in [0, MAX_COUNT]`,{field:i,count:c,max:4294967294});return c},s=r("nodes",e),o=r("edges",t);mn(s),this.staging.reserve(s,o)}addEdge(e,t,r){this.check();const s=this.checkWeight(r,void 0),o=this.resolveEndpoint(be(e)),i=this.resolveEndpoint(be(t));return this.pushEdge(o,i,s)}addEdgeByIndex(e,t,r){this.check();const s=this.checkWeight(r,void 0);return this.checkLiveNode(e),this.checkLiveNode(t),this.pushEdge(e,t,s)}addEdges(e,t,r){this.check();const s=e.length;if(t.length!==s||r!==void 0&&r.length!==s)throw new f("E_COLUMN_LENGTH",`addEdges: src has ${s} entries, dst ${t.length}, weights ${r===void 0?"none":r.length}`,{src:s,dst:t.length,weights:r?.length??null});for(let l=0;l<s;l++)this.checkLiveNode(e[l]),this.checkLiveNode(t[l]);let o=null;if(r!==void 0){for(let l=0;l<s;l++)this.checkWeight(r[l],l);o=this.fixed.weighted===!1?null:r}this.checkEdgeLimit(s,this.arcsOf(e,t,s));const{staging:i}=this;i.reserve(0,i.edgeBound+s);const c=i.pushEdges(e,t,o);return s>0&&this.mutated(),c}addEdgesByIds(e,t,r){this.check();const s=e.length;if(t.length!==s||r!==void 0&&r.length!==s)throw new f("E_COLUMN_LENGTH",`addEdgesByIds: src has ${s} entries, dst ${t.length}, weights ${r===void 0?"none":r.length}`,{src:s,dst:t.length,weights:r?.length??null});const o=new Array(s),i=new Array(s),c=new Array(s);for(let u=0;u<s;u++)o[u]=be(e[u]),i[u]=be(t[u]),c[u]=this.checkWeight(r===void 0?void 0:r[u],u);if(!this.fixed.addMissingNodes)for(let u=0;u<s;u++)this.requireLive(o[u]),this.requireLive(i[u]);this.checkEdgeLimit(s,this.directedValue?s:2*s);const l=this.staging.edgeBound;for(let u=0;u<s;u++){const a=this.resolveEndpoint(o[u]),d=this.resolveEndpoint(i[u]);this.staging.pushEdge(a,d,c[u])}return s>0&&this.mutated(),l}removeEdge(e){return this.check(),this.isLiveEdge(e)?(this.staging.killEdge(e),this.mutated(),!0):!1}hasEdge(e){return this.check(),this.isLiveEdge(e)}edgeEndpoints(e){return this.check(),this.checkEdge(e),[this.staging.src.get(e),this.staging.dst.get(e)]}edgeWeight(e){this.check(),this.checkEdge(e);const{weight:t}=this.staging;return t===null?1:t.get(e)}setEdgeWeight(e,t){this.check(),this.checkEdge(e);const r=this.checkWeight(t,void 0),{staging:s}=this;r!==void 0&&(s.ensureWeights().set(e,r),s.trackWeight(e,!0)),this.mutated()}outEdgesOf(e){return this.check(),this.checkNodeIndex(e),this.directedValue?this.staging.outEdges(e):this.staging.incidentEdges(e)}inEdgesOf(e){return this.check(),this.checkNodeIndex(e),this.directedValue?this.staging.inEdges(e):this.staging.incidentEdges(e)}findEdges(e,t){return this.check(),this.checkNodeIndex(e),this.checkNodeIndex(t),this.staging.edgesBetween(e,t,this.directedValue)}declareNodeColumn(e){return this.check(),this.declare("node",e)}declareEdgeColumn(e){return this.check(),this.declare("edge",e)}nodeColumn(e){return this.check(),this.handleOf(this.staging.nodeColumns,e)}edgeColumn(e){return this.check(),this.handleOf(this.staging.edgeColumns,e)}setNodeValue(e,t,r){this.check(),this.checkNodeIndex(t),this.writeCell("node",e,t,r)}setEdgeValue(e,t,r){this.check(),this.checkEdgeIndex(t),this.writeCell("edge",e,t,r)}widenNodeColumn(e,t){this.check(),this.widenColumn("node",e,t)}widenEdgeColumn(e,t){this.check(),this.widenColumn("edge",e,t)}setNodeColumn(e,t,r){this.check(),this.setBulkColumn("node",this.staging.nodeBound,e,t,r??{})}setEdgeColumn(e,t,r){this.check(),this.setBulkColumn("edge",this.staging.edgeBound,e,t,r??{})}setGraphValue(e,t,r){this.check();const s=r??{};B(e,"graph",{dtype:"json",...s}),t!==void 0&&Ka(e,t,s),this.graphValues.set(e,{decl:s,value:t}),this.mutated()}setMeta(e){this.check(),this.metaValue=Yi(this.metaValue,e),this.mutated()}addExtensionTable(e,t){this.check();const{staging:r}=this;if(r.extensions.some(o=>o.name===e))throw new f("E_COLUMN_EXISTS",`extension table "${e}" already exists`,{table:e});const s=[];for(const o of t){const i=Xe(o.name,"extension",o,!1);if(s.some(c=>c.meta.name===i.meta.name))throw new f("E_COLUMN_EXISTS",`column "${o.name}" is declared twice in "${e}"`,{table:e,column:o.name});We(s,i.meta,e),s.push(i)}return r.extensions.push({name:e,columns:s,rowCount:0}),this.mutated(),r.extensions.length-1}addExtensionRow(e,t){this.check();const r=this.extensionOf(e);if(t.length!==r.columns.length)throw new f("E_COLUMN_LENGTH",`extension table "${r.name}" has ${r.columns.length} columns; ${t.length} values given`,{table:r.name,expected:r.columns.length,found:t.length});const s=r.rowCount,o=r.columns.map((i,c)=>{const l=this.checkReference(i.meta,t[c]);return i.checkValue(s,l),l});for(let i=0;i<o.length;i++)r.columns[i].write(s,o[i]);return r.rowCount=s+1,this.mutated(),s}addNodeRecord(e,t){this.check();const r=be(e),s=Object.keys(t);this.checkCells("node",this.prospectiveNodeIndex(r),s,t);const o=this.addValidatedNode(r);for(const i of s)this.writeCell("node",i,o,t[i]);return o}addEdgeRecord(e,t,r,s){this.check();const o=s===void 0?"weight":s;let i;if(o!==null&&Object.prototype.hasOwnProperty.call(r,o)){const u=r[o];if(u!=null){if(typeof u!="number")throw new f("E_INVALID_WEIGHT",`edge weight "${o}" is not a number`,{key:o,found:typeof u});i=u}}const c=Object.keys(r).filter(u=>u!==o);this.checkWeight(i,void 0),this.checkCells("edge",this.staging.edgeBound,c,r);const l=this.addEdge(e,t,i);for(const u of c)this.writeCell("edge",u,l,r[u]);return l}addGraph(e,t){this.check();const r=t?.onDuplicateNode??"merge";if(r!=="merge"&&r!=="error")throw new f("E_UNSUPPORTED",`addGraph option onDuplicateNode has an unsupported value ${String(r)}`,{field:"onDuplicateNode",found:r,reason:"unsupported option"});if(e.directed!==this.directedValue)throw new f("E_DIRECTED",`a ${e.directed?"directed":"undirected"} snapshot cannot be appended to a ${this.directedValue?"directed":"undirected"} builder`,{reason:"direction mismatch",directed:this.directedValue,found:e.directed});const{staging:s}=this,{nodeCount:o,edgeCount:i}=e,c=s.ids===null&&s.nodeBound===0&&e.ids.kind==="identity"&&e.ids.offset===0,l=new Uint32Array(o);let u=o;if(!c){u=0;for(let w=0;w<o;w++){const m=e.ids.idOf(w),A=this.lookup(m);if(A===4294967295)u++;else if(r==="error")throw new f("E_DUPLICATE_ID",`node id ${ge(m)} already exists`,{id:m,index:A})}}this.checkNodeLimit(u);const a=e.edgeList();this.checkEdgeLimit(i,this.arcsOf(a.src,a.dst,i));const d=e.edges.byRole("weight"),g=new Array(i);for(let w=0;w<i;w++){let m;d!==null?m=d.isSet(w)?d.value(w):void 0:a.weights!==null&&(m=a.weights[w]),g[w]=this.checkWeight(m,w)}for(const w of e.nodes)this.checkIncomingColumn("node",w);for(const w of e.edges)w!==d&&this.checkIncomingColumn("edge",w);for(const[w,m]of e.extensions)this.checkIncomingExtension(w,m);if(c){const w=this.addAnonymousNodes(o);for(let m=0;m<o;m++)l[m]=w+m}else for(let w=0;w<o;w++){const m=e.ids.idOf(w),A=this.lookup(m);l[w]=A===4294967295?this.addValidatedNode(m):A}e.flags.weighted&&this.fixed.weighted!==!1&&s.ensureWeights();const h=new Uint32Array(i);for(let w=0;w<i;w++)h[w]=this.pushEdge(l[a.src[w]],l[a.dst[w]],g[w]);const y={node:l,edge:h};for(const w of e.nodes)this.copyColumn("node",w,l,y);for(const w of e.edges)w!==d&&this.copyColumn("edge",w,h,y);for(const w of e.graph)w.isSet(0)&&this.setGraphValue(w.meta.name,w.value(0),he(w.meta));for(const[w,m]of e.extensions)this.appendExtension(w,m,y);this.mutated()}freeze(e){return this.freezeWithReport(e).snapshot}freezeWithReport(e){this.check();const t=e??{},r={staging:this.staging,directed:this.directedValue,options:this.options,graphValues:this.graphValues,meta:this.metaValue,widened:this.widenings},s=Xa(r,t);return this.staging=s.staging,this.widenings=[],this.dirtyFlag=!1,t.release===!0&&(this.staging=this.freshStaging()),{snapshot:s.snapshot,report:s.report}}clear(){this.check(),this.staging=this.freshStaging(),this.graphValues=new Map,this.metaValue=Qt,this.widenings=[],this.mutated()}dispose(){this.disposed||(this.staging=new In({weightDtype:this.fixed.weightDtype,weighted:!1,expectedNodes:null,expectedEdges:null,resizable:void 0}),this.graphValues=new Map,this.metaValue=Qt,this.widenings=[],this.disposed=!0)}byteLength(){return this.check(),this.staging.byteLength()}check(){if(this.disposed)throw new f("E_BUILDER_DISPOSED","the builder was disposed",{})}mutated(){this.mutations++,this.dirtyFlag=!0}freshStaging(){return new In({weightDtype:this.fixed.weightDtype,weighted:this.fixed.weighted===!0,expectedNodes:this.fixed.expectedNodes,expectedEdges:this.fixed.expectedEdges,resizable:void 0})}prospectiveNodeIndex(e){const{staging:t}=this;return t.idToIndex===null?typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<t.nodeBound?e:t.nodeBound:t.idToIndex.get(typeof e=="number"&&e===0?0:e)??t.nodeBound}lookup(e){const{staging:t}=this;if(t.idToIndex===null)return typeof e!="number"||!Number.isInteger(e)||e<0||e>=t.nodeBound?4294967295:t.nodeAlive.get(e)?e:4294967295;const r=t.idToIndex.get(typeof e=="number"&&e===0?0:e);return r===void 0||!t.nodeAlive.get(r)?4294967295:r}isLiveNode(e){const{staging:t}=this;return Number.isInteger(e)&&e>=0&&e<t.nodeBound&&t.nodeAlive.get(e)}isLiveEdge(e){const{staging:t}=this;return Number.isInteger(e)&&e>=0&&e<t.edgeBound&&t.edgeAlive.get(e)}checkNodeIndex(e){if(!Number.isInteger(e)||e<0||e>=this.staging.nodeBound)throw new f("E_INDEX_RANGE",`node index ${e} is out of range`,{index:e,bound:this.staging.nodeBound})}checkEdgeIndex(e){if(!Number.isInteger(e)||e<0||e>=this.staging.edgeBound)throw new f("E_INDEX_RANGE",`edge index ${e} is out of range`,{edge:e,bound:this.staging.edgeBound})}checkLiveNode(e){if(!this.isLiveNode(e))throw new f("E_UNKNOWN_NODE",`node index ${e} is out of range or removed`,{index:e})}checkEdge(e){if(!this.isLiveEdge(e))throw new f("E_INDEX_RANGE",`edge index ${e} is out of range or removed`,{edge:e,bound:this.staging.edgeBound})}checkNodeLimit(e){if(this.staging.nodeBound+e>4294967294)throw new f("E_TOO_LARGE",`node count ${this.staging.nodeBound+e} exceeds MAX_COUNT`,{count:this.staging.nodeBound+e,max:4294967294})}checkEdgeLimit(e,t){const{staging:r}=this,s=r.edgeBound+e,i=(this.directedValue?r.liveEdgeCount:2*r.liveEdgeCount-r.selfLoopCount)+t;if(s>4294967294||i>4294967294)throw new f("E_TOO_LARGE",`edge count ${s} (${i} arcs) exceeds MAX_COUNT`,{count:s,arcs:i,max:4294967294})}arcsOf(e,t,r){if(this.directedValue)return r;let s=0;for(let o=0;o<r;o++)s+=e[o]===t[o]?1:2;return s}addValidatedNode(e){const{staging:t}=this;t.materialiseIds();const s=t.idToIndex.get(e);if(s!==void 0)return t.nodeAlive.get(s)||(t.nodeAlive.set(s,!0),t.liveNodeCount++,this.mutated()),s;this.checkNodeLimit(1);const o=t.pushNode(typeof e=="string"?nt(e):e);return this.mutated(),o}resolveEndpoint(e){const t=this.lookup(e);if(t!==4294967295)return t;if(this.fixed.addMissingNodes)return this.addValidatedNode(e);throw new f("E_UNKNOWN_NODE",`unknown node id ${ge(e)}`,{id:e})}requireLive(e){if(this.lookup(e)===4294967295)throw new f("E_UNKNOWN_NODE",`unknown node id ${ge(e)}`,{id:e})}removeLiveNode(e){const{staging:t}=this,r=[];for(let s=t.firstOut.get(e);s!==4294967295;s=t.nextOut.get(s))t.edgeAlive.get(s)&&(t.killEdge(s),r.push(s));for(let s=t.firstIn.get(e);s!==4294967295;s=t.nextIn.get(s))t.edgeAlive.get(s)&&(t.killEdge(s),r.push(s));return t.nodeAlive.set(e,!1),t.liveNodeCount--,this.mutated(),Uint32Array.from(r).sort()}checkWeight(e,t){if(e!==void 0){if(typeof e!="number"||Number.isNaN(e))throw new f("E_INVALID_WEIGHT",`weight ${String(e)} is not a number`,{weight:e,...t===void 0?{}:{edge:t}});if(this.fixed.weighted===!1){if(e!==1)throw new f("E_INVALID_WEIGHT",`weight ${e} on a builder declared unweighted`,{weight:e,reason:"unweighted builder",...t===void 0?{}:{edge:t}});return}return e}}pushEdge(e,t,r){this.checkEdgeLimit(1,this.directedValue||e===t?1:2);const s=this.staging.pushEdge(e,t,r);return this.mutated(),s}expandToDirected(){const{staging:e}=this,t=e.liveEdgeCount;this.checkEdgeLimit(t,t);const r={name:za,dtype:"bool",role:"directed"},s={name:Ga,dtype:"u32",role:"pair",refersTo:"edge"};this.checkDeclaration("edge",r),this.checkDeclaration("edge",s);const o=this.declare("edge",r),i=this.declare("edge",s),c=e.edgeColumns[o],l=e.edgeColumns[i],u=e.edgeBound;for(let a=0;a<u;a++){if(!e.edgeAlive.get(a))continue;c.write(a,!1);const d=e.src.get(a),g=e.dst.get(a);if(d===g)continue;const y=e.weightExplicit(a)&&e.weight!==null?e.weight.get(a):void 0,w=e.pushEdge(g,d,y);c.write(w,!1),l.write(a,w),l.write(w,a)}this.directedValue=!0,this.optionsCache=null,this.mutated()}columnsOf(e){return e==="node"?this.staging.nodeColumns:this.staging.edgeColumns}handleOf(e,t){const r=this.columnIndex(e,t);return r<0?4294967295:r}columnIndex(e,t){let s=e===this.staging.nodeColumns?this.nodeNames:this.edgeNames;if(s?.columns!==e||s.map.size!==e.length){const o=new Map;for(let i=0;i<e.length;i++)o.set(e[i].meta.name,i);s={columns:e,map:o},e===this.staging.nodeColumns?this.nodeNames=s:e===this.staging.edgeColumns&&(this.edgeNames=s)}return s.map.get(t)??-1}pushColumn(e,t){e.push(t);const r=e===this.staging.nodeColumns?this.nodeNames:this.edgeNames;return r!==null&&r.columns===e&&r.map.size===e.length-1&&r.map.set(t.meta.name,e.length-1),e.length-1}declare(e,t){const{meta:r,existing:s}=this.checkDeclaration(e,t);if(s!==4294967295)return s;const o=this.columnsOf(e);return this.mutated(),this.pushColumn(o,new jt(r,!1))}checkDeclaration(e,t){if(typeof t.name!="string"||t.name.length===0)throw new f("E_COLUMN_TYPE","a column declaration needs a non-empty name",{field:"name",found:t.name});const r=B(t.name,e,t),s=this.columnsOf(e),o=this.columnIndex(s,r.name);if(o>=0){if(Fr(s[o].meta,r))return{meta:r,existing:o};throw new f("E_COLUMN_EXISTS",`${e} column "${r.name}" is already declared as ${s[o].meta.dtype}`,{column:r.name,domain:e,found:s[o].meta.dtype,expected:r.dtype})}return We(s,r,e),{meta:r,existing:4294967295}}resolveColumn(e,t,r){const s=this.columnsOf(e);if(typeof t=="number"){if(!Number.isInteger(t)||t<0||t>=s.length)throw new f("E_UNKNOWN_COLUMN",`no ${e} column with handle ${t}`,{domain:e,handle:t});return s[t]}const o=this.columnIndex(s,t);if(o>=0)return s[o];if(r==null)return null;const i=pn(r),c=Xe(t,e,{dtype:i,nullable:!0},!0);return this.pushColumn(s,c),c}checkCells(e,t,r,s){const o=this.columnsOf(e);for(const i of r){const c=s[i],l=this.columnIndex(o,i),u=l<0?void 0:o[l];u!==void 0?u.checkValue(t,this.checkReference(u.meta,c)):c!=null&&(pn(c),typeof c=="string"?Se(c,{column:i,row:t}):typeof c=="object"&&oe(c,`${i}[${t}]`))}}checkReference(e,t){if(e.refersTo===null||t===void 0||t===null)return t;const r=e.refersTo==="node"?this.staging.nodeBound:this.staging.edgeBound,s=o=>{if(typeof o=="number"&&o!==4294967295&&!(o>=0&&o<r))throw new f("E_INDEX_RANGE",`column "${e.name}" refers to ${String(e.refersTo)} ${o}, which is not below ${r}`,{column:e.name,refersTo:e.refersTo,found:o,bound:r})};if(Array.isArray(t)){for(const o of t)s(o);return t}return s(t),t===4294967295?void 0:t}checkIncomingColumn(e,t){const r=this.columnsOf(e);this.columnIndex(r,t.meta.name)<0&&We(r,t.meta,e)}checkIncomingExtension(e,t){const r=this.staging.extensions.find(o=>o.name===e),s=[...t];if(r===void 0){const o=[];for(const i of s){const c={...he(i.meta),name:i.meta.name},l=Xe(c.name,"extension",c,!1);if(o.some(u=>u.meta.name===l.meta.name))throw new f("E_COLUMN_EXISTS",`column "${c.name}" is declared twice in "${e}"`,{table:e,column:c.name});We(o,l.meta,e),o.push(l)}return}for(const o of s)if(!r.columns.some(i=>i.meta.name===o.meta.name))throw new f("E_UNKNOWN_COLUMN",`extension table "${e}" has no column "${o.meta.name}"`,{table:e,column:o.meta.name})}widenColumn(e,t,r){const s=this.columnsOf(e);let o;if(typeof t=="number")o=Number.isInteger(t)&&t>=0&&t<s.length?s[t]:void 0;else{const l=this.columnIndex(s,t);o=l<0?void 0:s[l]}if(o===void 0)throw new f("E_UNKNOWN_COLUMN",`no ${e} column ${String(t)}`,{domain:e,column:t});const i=o.inferredDtype;if(i===null)throw new f("E_COLUMN_TYPE",`${e} column "${o.meta.name}" is declared, not inferred`,{column:o.meta.name,domain:e});if(ke(r)<0)throw new f("E_COLUMN_TYPE",`${r} is not a dtype inference widens to`,{column:o.meta.name,dtype:r});const c=r;if(ke(c)<ke(i))throw new f("E_COLUMN_TYPE",`${e} column "${o.meta.name}" is ${i}; it cannot narrow to ${c}`,{column:o.meta.name,found:i,expected:c});c!==i&&(o.widenTo(c),this.widenings.push({column:o.meta.name,domain:e,from:i,to:c}),this.mutated())}writeCell(e,t,r,s){const o=this.resolveColumn(e,t,s);if(o===null)return;const i=o.write(r,this.checkReference(o.meta,s));i!==null&&this.widenings.push({column:o.meta.name,domain:e,from:i.from,to:i.to}),this.mutated()}setBulkColumn(e,t,r,s,o){const i=Za(e,t,r,s,o,{node:this.staging.nodeBound,edge:this.staging.edgeBound}),c=this.columnsOf(e),l=this.columnIndex(c,r);We(c.filter(u=>u.meta.name!==r),i.meta,e),l>=0?c[l]=i:this.pushColumn(c,i),this.mutated()}extensionOf(e){const{extensions:t}=this.staging;if(!Number.isInteger(e)||e<0||e>=t.length)throw new f("E_INDEX_RANGE",`no extension table with handle ${e}`,{handle:e});return t[e]}copyColumn(e,t,r,s){const o=this.columnsOf(e),{name:i}=t.meta;let c=this.columnIndex(o,i);if(c<0){const a={...he(t.meta)};We(o,t.meta,e),c=this.pushColumn(o,Xe(i,e,a,!1))}else{const a=o[c];if(!Fr(a.meta,t.meta)){const d=Ja(bn(a.meta.dtype),bn(t.meta.dtype));if(a.meta.dtype!==d){const g=a.meta.dtype;a.widenTo(d),this.widenings.push({column:i,domain:e,from:g,to:d})}}}const l=o[c],u=zr(t.meta,s);for(let a=0;a<t.length;a++){if(!t.isSet(a))continue;let d=t.value(a);u!==null&&(d=wo(d,u),d===void 0)||l.write(r[a],d)}}appendExtension(e,t,r){const{staging:s}=this,o=[...t];let i=s.extensions.find(u=>u.name===e);if(i===void 0){const u=o.map(d=>({...he(d.meta),name:d.meta.name})),a=this.addExtensionTable(e,u);i=s.extensions[a]}const c=i.columns,l=i.rowCount;for(const u of o){const a=c.find(d=>d.meta.name===u.meta.name);if(a===void 0)throw new f("E_UNKNOWN_COLUMN",`extension table "${e}" has no column "${u.meta.name}"`,{table:e,column:u.meta.name});qa(a,u,l,zr(u.meta,r))}for(const u of c)u.ensureLength(l+t.rowCount);i.rowCount=l+t.rowCount}}function qa(n,e,t,r){for(let s=0;s<e.length;s++){if(!e.isSet(s)){n.ensureLength(t+s+1);continue}let o=e.value(s);if(r!==null&&(o=wo(o,r),o===void 0)){n.ensureLength(t+s+1);continue}n.write(t+s,o)}}function We(n,e,t){if(e.role===null)return;const r=n.find(s=>s.meta.name!==e.name&&s.meta.role===e.role);if(r!==void 0)throw new f("E_DUPLICATE_ROLE",`role "${e.role}" is already held by column "${r.meta.name}" in ${t}`,{role:e.role,column:e.name,holder:r.meta.name})}function Ja(n,e){return ke(n)>=ke(e)?n:e}function zr(n,e){switch(n.refersTo){case"node":return e.node;case"edge":return e.edge;default:return null}}function wo(n,e){if(typeof n=="number")return n<e.length?e[n]:void 0;if(typeof n=="object"&&n!==null){const t=Array.from(n),r=t.filter(s=>s<e.length).map(s=>e[s]);return r.length===0&&t.length>0?void 0:r}throw new f("E_COLUMN_TYPE",`a refersTo cell holds a ${typeof n}, not an index or a list`,{found:typeof n,reason:"refersTo"})}function Ka(n,e,t){Xe(n,"graph",t.dtype===void 0?{...t,dtype:pn(e)}:t,t.dtype===void 0).write(0,e)}function Za(n,e,t,r,s,o){const i=Es(r),c=s.dtype??i;if(!(c===i||i==="u32"&&(c==="bool"||c==="dict")))throw new f("E_COLUMN_TYPE",`column "${t}": a ${i} array cannot back a ${c} column`,{column:t,field:"dtype",found:i,expected:c});const u=Xe(t,n,{nullable:!1,...s,dtype:c},!1),{components:a}=u.meta;let d;switch(c){case"bool":d=Math.ceil(e/32);break;case"dict":d=e;break;case"f32":case"f64":case"i32":case"u32":case"u8":d=e*a;break;default:throw new f("E_COLUMN_TYPE",`column "${t}": a ${String(c)} column cannot adopt a typed array`,{column:t,field:"dtype"})}if(r.length!==d)throw new f("E_COLUMN_LENGTH",`column "${t}": array length ${r.length}, expected ${d}`,{column:t,expected:d,found:r.length});switch(u.ensureLength(e),c){case"bool":{const g=r;for(let h=0;h<e;h++)u.write(h,(g[h>>>5]>>>(h&31)&1)===1);break}case"dict":{const{dictionary:g}=u;if(g===null)throw new f("E_COLUMN_TYPE",`column "${t}" has no dictionary`,{column:t});for(let h=0;h<e;h++){const y=r[h];if(y>=g.size)throw new f("E_COLUMN_TYPE",`column "${t}": code ${y} at row ${h} is outside the ${g.size} declared options`,{column:t,row:h,code:y});u.write(h,g.values[y])}break}default:{const{typed:g}=u;if(g===null)throw new f("E_COLUMN_TYPE",`column "${t}" has no typed storage`,{column:t});const{refersTo:h}=u.meta,y=h==="node"?o.node:o.edge;for(let w=0;w<r.length;w++){const m=r[w];if(h!==null&&m!==4294967295&&m>=y)throw new f("E_INDEX_RANGE",`column "${t}" refers to ${h} ${m} at row ${w}, which is not below ${y}`,{column:t,row:w,refersTo:h,found:m,bound:y});if(h!==null&&m===4294967295&&u.validity===null)throw new f("E_COLUMN_TYPE",`column "${t}": row ${w} of a non-nullable refersTo column holds INVALID_INDEX`,{column:t,row:w,field:"nullable"});g.set(w,m)}if(u.validity!==null)for(let w=0;w<e;w++)u.validity.set(w,h===null||r[w]!==4294967295);break}}return u}const Qa="id";function ed(n,e){if(e.directed!==void 0&&e.directed!==n)throw new f("E_DIRECTED",`options.directed (${String(e.directed)}) disagrees with the input's directed (${String(n)})`,{reason:"direction mismatch",directed:n,found:e.directed});return{builder:{directed:n,weighted:e.weighted,weightDtype:e.weightDtype,duplicateEdges:e.duplicateEdges,selfLoops:e.selfLoops,addMissingNodes:e.addMissingNodes,expectedNodes:e.expectedNodes,expectedEdges:e.expectedEdges},freeze:{label:e.label,prepare:e.prepare,arena:e.arena,release:e.release,profile:e.profile,checksum:e.checksum}}}function Gr(n){return ArrayBuffer.isView(n)}function on(n,e,t,r,s){const o=Gr(s)?s:s.data,i=Gr(s)?{}:s.decl;if(ArrayBuffer.isView(o)){e==="node"?n.setNodeColumn(r,o,i):n.setEdgeColumn(r,o,i);return}const c=Wn(e,t,r,o,i),l={...he(c.meta),name:r,dtype:c.dtype},u=e==="node"?n.declareNodeColumn(l):n.declareEdgeColumn(l);for(let a=0;a<t;a++){if(!c.isSet(a))continue;const d=c.value(a);e==="node"?n.setNodeValue(u,a,d):n.setEdgeValue(u,a,d)}}function vt(n,e,t){return new f("E_COLUMN_LENGTH",`${n} has ${t} entries, expected ${e}`,{field:n,expected:e,found:t})}function td(n){const{nodeCount:e,ids:t}=n;if(e!==void 0&&(!Number.isInteger(e)||e<0))throw new f("E_INDEX_RANGE",`nodeCount ${e} is not a non-negative integer`,{field:"nodeCount",found:e});if(t!==void 0){if(e!==void 0&&e!==t.length)throw vt("ids",e,t.length);return t.length}if(e===void 0)throw new f("E_INDEX_RANGE","nodeCount is required when no ids are given",{field:"nodeCount"});return e}function nd(n,e){const t=n.addNodes(e);for(let r=0;r<t.length;r++)if(t[r]!==r){const s=e[r];throw new f("E_DUPLICATE_ID",`ids[${r}] repeats the id of index ${t[r]}`,{id:s,index:t[r],position:r})}}function rd(n){const{src:e,dst:t,weights:r,edgeIds:s}=n;if(t.length!==e.length)throw vt("dst",e.length,t.length);if(r!==void 0&&r.length!==e.length)throw vt("weights",e.length,r.length);if(s!==void 0&&s.length!==e.length)throw vt("edgeIds",e.length,s.length)}function af(n,e={}){const{src:t,dst:r,weights:s}=n;rd(n);const o=td(n),i=t.length,c=ed(n.directed,e),l={...c.builder,weightDtype:e.weightDtype??(s instanceof Float64Array?"f64":void 0),expectedNodes:e.expectedNodes??o,expectedEdges:e.expectedEdges??i},u=new Zn(l);if(n.ids===void 0?u.addAnonymousNodes(o):nd(u,n.ids),u.addEdges(t,r,s),n.nodeColumns!==void 0)for(const a of Object.keys(n.nodeColumns))on(u,"node",o,a,n.nodeColumns[a]);if(n.edgeColumns!==void 0)for(const a of Object.keys(n.edgeColumns))on(u,"edge",i,a,n.edgeColumns[a]);return n.edgeIds!==void 0&&on(u,"edge",i,Qa,{data:n.edgeIds,decl:{role:"id",unique:!0}}),n.meta!==void 0&&u.setMeta(n.meta),u.freeze(c.freeze)}const V=new DataView(new ArrayBuffer(8));function J(n){return V.setFloat64(0,n,!0),V.getInt32(4,!0)}function yo(n){return V.setFloat64(0,n,!0),V.getUint32(0,!0)}const De=.6931471803691238,Te=19082149292705877e-26,sd=0x40000000000000,od=.6666666666666735,id=.3999999999940942,cd=.2857142874366239,ld=.22222198432149784,ud=.1818357216161805,ad=.15313837699209373,dd=.14798198605116586;function fd(n){let e=n,t=J(e);const r=yo(e);let s=0;if(t<1048576){if((t&2147483647|r)===0)return-1/0;if(t<0)return Number.NaN;s-=54,e*=sd,t=J(e)}if(t>=2146435072)return e+e;s+=(t>>20)-1023,t&=1048575;const o=t+614244&1048576;return V.setFloat64(0,e,!0),V.setInt32(4,t|o^1072693248,!0),e=V.getFloat64(0,!0),s+=o>>20,hd(e-1,s,t)}function hd(n,e,t){if((1048575&2+t)<3){if(n===0)return e===0?0:e*De+e*Te;const u=n*n*(.5-.3333333333333333*n);return e===0?n-u:e*De-(u-e*Te-n)}const r=n/(2+n),s=r*r,o=s*s,i=o*(id+o*(ld+o*ad)),l=s*(od+o*(cd+o*(ud+o*dd)))+i;if((t-398458|440401-t)>0){const u=.5*n*n;return e===0?n-(u-r*(u+l)):e*De-(u-(r*(u+l)+e*Te)-n)}return e===0?n-r*(n-l):e*De-(r*(n-l)-e*Te-n)}const Yr=-.16666666666666632,gd=.00833333333332249,wd=-.0001984126982985795,yd=27557313707070068e-22,md=-25050760253406863e-24,pd=158969099521155e-24,bd=.0416666666666666,Id=-.001388888888887411,Ed=2480158728947673e-20,Ad=-27557314351390663e-23,Nd=2087572321298175e-24,Cd=-11359647557788195e-27;function ct(n,e,t){if((J(n)&2147483647)<1044381696&&Math.trunc(n)===0)return n;const r=n*n,s=r*n,o=gd+r*(wd+r*(yd+r*(md+r*pd)));return t===0?n+s*(Yr+r*o):n-(r*(.5*e-s*o)-e-s*Yr)}function lt(n,e){const t=J(n)&2147483647;if(t<1044381696&&Math.trunc(n)===0)return 1;const r=n*n,s=r*(bd+r*(Id+r*(Ed+r*(Ad+r*(Nd+r*Cd)))));if(t<1070805811)return 1-(.5*r-(r*s-n*e));let o;t>1072234496?o=.28125:(V.setInt32(4,t-2097152,!0),V.setUint32(0,0,!0),o=V.getFloat64(0,!0));const i=.5*r-o;return 1-o-(i-(r*s-n*e))}const Ld=.6366197723675814,Hr=1.5707963267341256,cn=6077100506506192e-26,qr=6077100506303966e-26,ln=20222662487959506e-37,$d=20222662487111665e-37,Od=84784276603689e-45,D=new Float64Array(2);function mo(n){const e=J(n),t=e&2147483647;if(t<1073928572){const d=e>0?1:-1;let g=n-d*Hr;return t===1073291771?(g-=d*qr,D[0]=g-d*ln,D[1]=g-D[0]-d*ln):(D[0]=g-d*cn,D[1]=g-D[0]-d*cn),d}const r=Math.abs(n),s=Math.floor(r*Ld+.5);let o=r-s*Hr,i=s*cn;const c=t>>20;let l=o-i,u=c-(J(l)>>20&2047);if(u>16){let d=o;i=s*qr,o=d-i,i=s*ln-(d-o-i),l=o-i,u=c-(J(l)>>20&2047),u>49&&(d=o,i=s*$d,o=d-i,i=s*Od-(d-o-i),l=o-i)}const a=o-l-i;return e<0?(D[0]=-l,D[1]=-a,-s):(D[0]=l,D[1]=a,s)}const _d=6.283185307179586;function po(n,e){return e>1094263291?n%_d:n}function df(n){const e=J(n)&2147483647;if(e<=1072243195)return ct(n,0,0);if(e>=2146435072)return Number.NaN;switch(mo(po(n,e))&3){case 0:return ct(D[0],D[1],1);case 1:return lt(D[0],D[1]);case 2:return-ct(D[0],D[1],1);default:return-lt(D[0],D[1])}}function ff(n){const e=J(n)&2147483647;if(e<=1072243195)return lt(n,0);if(e>=2146435072)return Number.NaN;switch(mo(po(n,e))&3){case 0:return lt(D[0],D[1]);case 1:return-ct(D[0],D[1],1);case 2:return-lt(D[0],D[1]);default:return ct(D[0],D[1],1)}}const Jr=3.141592653589793,Kr=1.5707963267948966,Tt=6123233995736766e-32,Dd=.16666666666666666,Td=-.3255658186224009,kd=.20121253213486293,vd=-.04005553450067941,xd=.0007915349942898145,Sd=3479331075960212e-20,Ud=-2.403394911734414,Pd=2.0209457602335057,Md=-.6882839716054533,Vd=.07703815055590194;function un(n){const e=n*(Dd+n*(Td+n*(kd+n*(vd+n*(xd+n*Sd))))),t=1+n*(Ud+n*(Pd+n*(Md+n*Vd)));return e/t}function hf(n){const e=J(n),t=e&2147483647;if(t>=1072693248)return(t-1072693248|yo(n))===0?e>0?0:Jr+2*Tt:Number.NaN;if(t<1071644672)return t<=1012924416?Kr+Tt:Kr-(n-(Tt-n*un(n*n)));if(e<0){const l=(1+n)*.5,u=Math.sqrt(l),a=un(l)*u-Tt;return Jr-2*(u+a)}const r=(1-n)*.5,s=Math.sqrt(r);V.setFloat64(0,s,!0),V.setUint32(0,0,!0);const o=V.getFloat64(0,!0),i=(r-o*o)/(s+o),c=un(r)*s+i;return 2*(o+c)}const Rd=709.782712893384,Bd=-745.1332191019411,Wd=1.4426950408889634,Xd=9332636185032189e-317,jd=.16666666666666602,Fd=-.0027777777777015593,zd=6613756321437934e-20,Gd=-16533902205465252e-22,Yd=41381367970572385e-24;function Zr(n,e){return V.setFloat64(0,n,!0),V.setInt32(4,V.getInt32(4,!0)+(e<<20),!0),V.getFloat64(0,!0)}function Hd(n,e,t){return e>=2146435072?!t||Number.isNaN(n)?n+n:0:n>Rd?1/0:n<Bd?0:null}const Oe=new Float64Array(3);function qd(n,e,t){if(e<1072734898){Oe[0]=t?-1:1,Oe[1]=t?n+De:n-De,Oe[2]=t?-Te:Te;return}const r=Math.trunc(Wd*n+(t?-.5:.5));Oe[0]=r,Oe[1]=n-r*De,Oe[2]=r*Te}function Jd(n){const e=J(n),t=e<0,r=e&2147483647,s=r>=1082535490?Hd(n,r,t):null;if(s!==null)return s;if(r<1043333120)return 1+n;let o=0,i=0,c=0,l=n;r>1071001154&&(qd(n,r,t),[c,o,i]=Oe,l=o-i);const u=l*l,a=l-u*(jd+u*(Fd+u*(zd+u*(Gd+u*Yd))));if(c===0)return 1-(l*a/(a-2)-l);const d=1-(i-l*a/(2-a)-o);return c>=-1021?Zr(d,c):Zr(d,c+1e3)*Xd}function gf(...n){let e=0,t=!1;for(const o of n){const i=Math.abs(o);Number.isNaN(i)?t=!0:i>e&&(e=i)}if(e===1/0)return 1/0;if(t)return Number.NaN;if(e===0)return 0;let r=0,s=0;for(const o of n){const i=Math.abs(o)/e,c=i*i-s,l=r+c;s=l-r-c,r=l}return Math.sqrt(r)*e}function Kd(n,e){let t=n,r=Math.abs(e),s=1;for(;r>0;)r%2===1&&(s*=t),t*=t,r=Math.floor(r/2);return e<0?1/s:s}function Zd(n,e){return n===0?e>0?0:1/0:n===1/0?e>0?1/0:0:e===.5?Math.sqrt(n):Jd(e*fd(n))}function wf(n,e){if(e===0)return 1;if(Number.isNaN(n)||Number.isNaN(e))return Number.NaN;const t=Number.isInteger(e);if(t&&Math.abs(e)<=1024)return Kd(n,e);const r=Math.abs(n);if(!Number.isFinite(e))return r===1?Number.NaN:r>1==e>0?1/0:0;if(n<0&&!t&&r!==1/0)return Number.NaN;const s=Zd(r,e);return(n<0||Object.is(n,-0))&&t&&e%2!==0?-s:s}function bo(n){if(n.ids===void 0)throw new f("E_UNKNOWN_NODE","node ids cannot be resolved: this graph has no id map (pass a GraphSnapshot)",{reason:"no id map"});return n.ids}function yf(n,e){return typeof e=="number"?e:bo(n).requireIndex(e.id)}function Qd(n,e){return"mask"in e?(Gt(e.mask,n.nodeCount,"nodes"),ro(e.mask,n.nodeCount)):"ids"in e?bo(n).indicesOf(e.ids,"throw"):e}function mf(n,e){if("mask"in e)return Gt(e.mask,n.nodeCount,"nodes"),e.mask;const t=Qd(n,e),r=Vu(n.nodeCount);for(let s=0;s<t.length;s++){const o=t[s];if(!Number.isInteger(o)||o<0||o>=n.nodeCount)throw new f("E_INDEX_RANGE",`node index ${String(o)} is out of range for ${n.nodeCount} nodes`,{index:o,nodeCount:n.nodeCount});Bu(r,o,!0)}return r}const ef=(function(){const e=typeof document<"u"&&document.createElement("link").relList;return e&&e.supports&&e.supports("modulepreload")?"modulepreload":"preload"})(),tf=function(n,e){return new URL(n,e).href},Qr={},pf=function(e,t,r){let s=Promise.resolve();if(t&&t.length>0){let u=function(a){return Promise.all(a.map(d=>Promise.resolve(d).then(g=>({status:"fulfilled",value:g}),g=>({status:"rejected",reason:g}))))};const i=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),l=c?.nonce||c?.getAttribute("nonce");s=u(t.map(a=>{if(a=tf(a,r),a in Qr)return;Qr[a]=!0;const d=a.endsWith(".css"),g=d?'[rel="stylesheet"]':"";if(r)for(let y=i.length-1;y>=0;y--){const w=i[y];if(w.href===a&&(!d||w.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${a}"]${g}`))return;const h=document.createElement("link");if(h.rel=d?"stylesheet":ef,d||(h.as="script"),h.crossOrigin="",h.href=a,l&&h.setAttribute("nonce",l),document.head.appendChild(h),d)return new Promise((y,w)=>{h.addEventListener("load",y),h.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${a}`)))})}))}function o(i){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=i,window.dispatchEvent(c),!c.defaultPrevented)throw i}return s.then(i=>{for(const c of i||[])c.status==="rejected"&&o(c.reason);return e().catch(o)})};export{Zn as G,nf as I,rf as M,pf as _,Qd as a,Vu as b,Bu as c,ea as d,lf as e,af as f,Jd as g,fd as h,wf as i,mf as j,gf as k,uf as l,Ru as m,hf as n,ff as o,df as p,of as q,yf as r,f as s,cf as t,sf as u};