/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{nativeArrayMaxSize as r,isTypedArray as n}from"../../core/typedArrayUtil.js";function t(r){return e(r,!0)}function e(t,e){if(Array.isArray(t)){if(t.length<r)return t}else if(t.length<r)return Array.from(t);let i=!0,u=!0;return t.some((r,n)=>(i=i&&0===r,u=u&&r===n,!i&&!u)),i?w(t.length):u?h(t.length):n(t)&&t.BYTES_PER_ELEMENT===Uint16Array.BYTES_PER_ELEMENT?t:f(t,!e)}function i(n,t){return n.length<r?Array.from(n):t<256?Uint8Array.from(n):t<65536?Uint16Array.from(n):Uint32Array.from(n)}function f(r,t){for(const e of r){if(e>=65536)return n(r)?r:new Uint32Array(r);e>=256&&(t=!1)}return t?new Uint8Array(r):new Uint16Array(r)}function u(n,t=n){return n<=r?new Array(n):t<=65536?new Uint16Array(n):new Uint32Array(n)}function a(n){return n<=r?new Array(n):new Uint32Array(n)}function l(r,n,t){if(0===n.length)return r.slice();if(0===r.length)return n.slice();const e=u(r.length+n.length,t);for(let i=0;i<r.length;++i)e[i]=r[i];for(let i=0;i<n.length;++i)e[r.length+i]=n[i];return e}let o=c(131072);const y=[0],A=(()=>{const r=new Uint16Array(65536);for(let n=0;n<r.length;++n)r[n]=n;return r})();function h(n){return 1===n?y:n<r?Array.from(new Uint16Array(A.buffer,0,n)):n<A.length?new Uint16Array(A.buffer,0,n):(n>o.length&&(o=c(Math.max(2*o.length,n))),new Uint32Array(o.buffer,0,n))}function g(n){return 1===n?[0]:n<r?Array.from(new Uint16Array(A.buffer,0,n)):n<A.length?new Uint16Array(A.buffer,0,n).slice():(n>o.length&&(o=c(Math.max(2*o.length,n))),new Uint32Array(o.buffer,0,n).slice())}function c(r){const n=new Uint32Array(r);for(let t=0;t<n.length;t++)n[t]=t;return n}let U=new Uint8Array(65536);function w(n){if(1===n)return y;if(n<r)return new Array(n).fill(0);if(n>U.length){const r=Math.max(2*U.length,n);U=new Uint8Array(r)}return new Uint8Array(U.buffer,0,n)}function s(){o=c(131072),U=new Uint8Array(65536)}function m(r){return"byteLength"in r?r.byteLength:8*r.length}export{e as compactIndices,t as compactMeshIndices,l as concatIndexArrays,h as getContinuousIndexArray,w as getZeroIndexArray,m as indexArrayByteSize,i as indexArrayFrom,g as newContinuousIndexArray,u as newIndexArray,a as newIntArray,s as pruneIndexArrays};
