/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{toConst as n}from"./compilerUtils.js";import t from"./RandomLCG.js";const e=1.5,r=1/e,l=.5;function u(n,t){if(!t)return n;for(const e of t)n.push(e);return n}function o(n){return n}function f(n,t=o){if(!n||0===n.length)return;let e=n[0],r=t(e);for(let l=1;l<n.length;++l){const u=n[l],o=Number(t(u));o>r&&(r=o,e=u)}return e}function i(n,t=o){return f(n,n=>-t(n))}function c(n,t){return t?n.filter((n,e,r)=>r.findIndex(t.bind(null,n))===e):Array.from(new Set(n))}function s(n,t,e,r,l,u,o){if(null==n&&null==r)return!0;t=Math.max(0,t),l=Math.max(0,l),e=Math.max(0,e<0?(n?.length??0)+e:e),u=Math.max(0,u<0?(r?.length??0)+u:u);const f=e-t;if(null==n||null==r||f!==u-l)return!1;if(o){for(let i=0;i<f;i++)if(!o(n[t+i],r[l+i]))return!1}else for(let i=0;i<f;i++)if(n[t+i]!==r[l+i])return!1;return!0}function h(n,t,e){return s(n,0,n?.length??0,t,0,t?.length??0,e)}function a(){return(n,t)=>{if(null==n&&null==t)return!0;if(null==n||null==t||n.length!==t.length)return!1;for(let e=0;e<n.length;e++)if(n[e]!==t[e])return!1;return!0}}function g(n,t){let e=n.length!==t.length;e&&(n.length=t.length);for(let r=0;r<t.length;++r)n[r]!==t[r]&&(n[r]=t[r],e=!0);return e}function d(n,t,e){let r,l;return e?(r=t.filter(t=>!n.some(n=>e(n,t))),l=n.filter(n=>!t.some(t=>e(t,n)))):(r=t.filter(t=>!n.includes(t)),l=n.filter(n=>!t.includes(n))),{added:r,removed:l}}function m(n,t,e){return n&&t?e?n.filter(n=>t.findIndex(t=>e(n,t))>-1):n.filter(n=>t.includes(n)):[]}function p(n){return n&&"number"==typeof n.length}function M(n,t){const e=n.length;if(0===e)return[];const r=[];for(let l=0;l<e;l+=t)r.push(n.slice(l,l+t));return r}function x(n,t){void 0===t&&(t=n,n=0);const e=new Array(t-n);for(let r=n;r<t;r++)e[r-n]=r;return e}function w(n,t,e){const r=n.length;let l=0,u=r-1;for(;l<u;){const e=l+Math.floor((u-l)/2);t>n[e]?l=e+1:u=e}const o=n[l];return e?t>=n[r-1]?-1:o===t?l:l-1:o===t?l:-1}class y{constructor(){this.last=0}}const A=new y;function b(n,t,e,r){r=r||A;const l=Math.max(0,r.last-10);for(let o=l;o<e;++o)if(n[o]===t)return r.last=o,o;const u=Math.min(l,e);for(let o=0;o<u;++o)if(n[o]===t)return r.last=o,o;return-1}function S(t,e,r,l){const u=r??t.length,o=b(t,n(e),u,l);if(-1!==o)return t[o]=t[u-1],null==r&&t.pop(),e}const j=new Set;function v(n,t,e=n.length,r=t.length,l,u){if(0===r||0===e)return e;j.clear();for(let f=0;f<r;++f)j.add(t[f]);l=l||A;const o=Math.max(0,l.last-10);for(let f=o;f<e;++f)if(j.has(n[f])&&(u?.push(n[f]),j.delete(n[f]),n[f]=n[e-1],--e,--f,0===j.size||0===e))return j.clear(),e;for(let f=0;f<o;++f)if(j.has(n[f])&&(u?.push(n[f]),j.delete(n[f]),n[f]=n[e-1],--e,--f,0===j.size||0===e))return j.clear(),e;return j.clear(),e}function z(n,t){let e=0;for(let r=0;r<n.length;++r){const l=n[r];t(l,r)&&(n[e]=l,e++)}return n.length=e,n}function I(n,t,e){const r=n.length;if(t>=r)return n.slice();const l=C(e),u=new Set,o=[];for(;o.length<t;){const t=Math.floor(l()*r);u.has(t)||(u.add(t),o.push(n[t]))}return o}function C(n){return n?(F.seed=n,()=>F.getFloat()):Math.random}const F=new t;function G(n,t){if(!n)return n;const e=C(t);for(let r=n.length-1;r>0;r--){const t=Math.floor(e()*(r+1)),l=n[r];n[r]=n[t],n[t]=l}return n}function L(n,t){const e=n.indexOf(t);return-1!==e?(n.splice(e,1),t):null}function N(n,t){return null!=n}function O(n,...t){for(const e of t)null!=e&&n.push(e);return n.length}function R(n,t){return n.reduce((n,e)=>t(e)?n+1:n,0)}function U(n){return Array.isArray(n)}function k(n,t,e){for(t<n.length&&(n.length=t);n.length<t;)n.push(e())}const q=[];export{y as PositionHint,u as addMany,w as binaryIndexOf,R as countIf,d as difference,q as emptyArray,h as equals,z as filterInPlace,C as getRandomNumberGenerator,b as indexOf,m as intersect,p as isArrayLike,U as isArrayWithReadonly,N as isSome,a as makeArrayEquals,f as max,i as min,I as pickRandom,O as pushIfSome,x as range,e as reallocGrowthFactor,r as reallocShrinkFactor,l as reallocShrinkThreshold,L as remove,S as removeUnordered,v as removeUnorderedMany,k as resizeFilled,G as shuffle,s as sliceEquals,M as splitIntoChunks,c as unique,g as update};
