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