/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
class t{constructor(t){this._totalCount=t,this._componentCountCache=-1,this._indexRanges=[0,t]}allVisible(){return this.componentCount===this._totalCount}allInvisible(){return 0===this._indexRanges.length}isVisible(t){if(t<0||t>=this._totalCount)return!1;if(this.allVisible())return!0;const n=this._indexRanges;let e=0,o=n.length/2;if(t<n[2*e]||t>n[2*o]+n[2*o+1])return!1;for(;o-e>0;){const s=Math.floor(.5*(e+o)),i=n[2*s];if(t<i){if(o-e===1)return!1;o=s;continue}if(t<i+n[2*s+1])return!0;if(o-e===1)return!1;e=s+1}return!1}get componentCount(){if(-1===this._componentCountCache){const t=this._indexRanges;let n=0;for(let e=0;e<t.length;e+=2)n+=t[e+1];this._componentCountCache=n}return this._componentCountCache}reset(t){"all"===t||t.length===this._totalCount?this._indexRanges=[0,this._totalCount]:this._indexRanges=n(t),this._componentCountCache=-1}forEachComponent(t){const n=this._indexRanges;for(let e=0;e<n.length;e+=2){const o=n[e],s=o+n[e+1];for(let n=o;n<s;n++)if(!t(n))return!1}return!0}forEachComponentRange(t){const n=this._indexRanges;for(let e=0;e<n.length;e+=2){const o=n[e];if(!t(o,o+n[e+1]))return!1}return!0}computeOffsetRanges(t){const n=new Array(this._indexRanges.length),e=this._indexRanges;for(let o=0;o<e.length;o+=2){const s=e[o],i=s+e[o+1],r=t[s],h=t[i];n[o]=r,n[o+1]=h-r}return n}}function n(t){const n=new Array;if(0===t.length)return n;let e=t[0],o=1;for(let s=1;s<t.length;s++){const i=t[s];e+o===i?o+=1:(n.push(e),n.push(o),e=i,o=1)}return n.push(e),n.push(o),n}export{t as ComponentRange};
