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AC,MAAM,GAAG,CAAC,CAAC,CAAC;QACtC,QAAQ,OAAO,KAAK,EAAE;YAClB,KAAK,QAAQ;gBAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;gBAAC,MAAM;YACnD,KAAK,QAAQ;gBAAE,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;gBAAC,MAAM;YAC/D,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAmB,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;SACtE;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IACS,OAAO,CAAC,SAAiB;QAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QACxE,IAAI,wBAAe,EAAE;YACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;SAC9E;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAzBD,8CAyBC","file":"buffer.js","sourcesContent":["// Licensed to the Apache Software Foundation (ASF) under one\n// or more contributor license agreements.  See the NOTICE file\n// distributed with this work for additional information\n// regarding copyright ownership.  The ASF licenses this file\n// to you under the Apache License, Version 2.0 (the\n// \"License\"); you may not use this file except in compliance\n// with the License.  You may obtain a copy of the License at\n//\n//   http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing,\n// software distributed under the License is distributed on an\n// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied.  See the License for the\n// specific language governing permissions and limitations\n// under the License.\n\nimport { memcpy } from '../util/buffer';\nimport { BigIntAvailable, BigInt64Array, BigUint64Array } from '../util/compat';\nimport {\n    TypedArray, TypedArrayConstructor,\n    BigIntArray, BigIntArrayConstructor\n} from '../interfaces';\n\n/** @ignore */ type DataValue<T> = T extends TypedArray ? number : T extends BigIntArray ? WideValue<T> : T;\n/** @ignore */ type WideValue<T extends BigIntArray> = T extends BigIntArray ? bigint | Int32Array | Uint32Array : never;\n/** @ignore */ type ArrayCtor<T extends TypedArray | BigIntArray> =\n    T extends TypedArray  ? TypedArrayConstructor<T>  :\n    T extends BigIntArray ? BigIntArrayConstructor<T> :\n    any;\n\n/** @ignore */\nconst roundLengthUpToNearest64Bytes = (len: number, BPE: number) => ((((len * BPE) + 63) & ~63) || 64) / BPE;\n/** @ignore */\nconst sliceOrExtendArray = <T extends TypedArray | BigIntArray>(arr: T, len = 0) => (\n    arr.length >= len ? arr.subarray(0, len) : memcpy(new (arr.constructor as any)(len), arr, 0)\n) as T;\n\n/** @ignore */\nexport interface BufferBuilder<T extends TypedArray | BigIntArray = any, TValue = DataValue<T>> {\n    readonly offset: number;\n}\n\n/** @ignore */\nexport class BufferBuilder<T extends TypedArray | BigIntArray = any, TValue = DataValue<T>> {\n\n    constructor(buffer: T, stride = 1) {\n        this.buffer = buffer;\n        this.stride = stride;\n        this.BYTES_PER_ELEMENT = buffer.BYTES_PER_ELEMENT;\n        this.ArrayType = buffer.constructor as ArrayCtor<T>;\n        this._resize(this.length = buffer.length / stride | 0);\n    }\n\n    public buffer: T;\n    public length: number;\n    public readonly stride: number;\n    public readonly ArrayType: ArrayCtor<T>;\n    public readonly BYTES_PER_ELEMENT: number;\n\n    public get byteLength() { return this.length * this.stride * this.BYTES_PER_ELEMENT | 0; }\n    public get reservedLength() { return this.buffer.length / this.stride; }\n    public get reservedByteLength() { return this.buffer.byteLength; }\n\n    // @ts-ignore\n    public set(index: number, value: TValue) { return this; }\n    public append(value: TValue) { return this.set(this.length, value); }\n    public reserve(extra: number) {\n        if (extra > 0) {\n            this.length += extra;\n            const stride = this.stride;\n            const length = this.length * stride;\n            const reserved = this.buffer.length;\n            if (length >= reserved) {\n                this._resize(reserved === 0\n                    ? roundLengthUpToNearest64Bytes(length * 1, this.BYTES_PER_ELEMENT)\n                    : roundLengthUpToNearest64Bytes(length * 2, this.BYTES_PER_ELEMENT)\n                );\n            }\n        }\n        return this;\n    }\n    public flush(length = this.length) {\n        length = roundLengthUpToNearest64Bytes(length * this.stride, this.BYTES_PER_ELEMENT);\n        const array = sliceOrExtendArray<T>(this.buffer, length);\n        this.clear();\n        return array;\n    }\n    public clear() {\n        this.length = 0;\n        this._resize(0);\n        return this;\n    }\n    protected _resize(newLength: number) {\n        return this.buffer = <T> memcpy(new this.ArrayType(newLength), this.buffer);\n    }\n}\n\n(BufferBuilder.prototype as any).offset = 0;\n\n/** @ignore */\nexport class DataBufferBuilder<T extends TypedArray> extends BufferBuilder<T, number> {\n    public last() { return this.get(this.length - 1); }\n    public get(index: number) { return this.buffer[index]; }\n    public set(index: number, value: number) {\n        this.reserve(index - this.length + 1);\n        this.buffer[index * this.stride] = value;\n        return this;\n    }\n}\n\n/** @ignore */\nexport class BitmapBufferBuilder extends DataBufferBuilder<Uint8Array> {\n\n    constructor(data = new Uint8Array(0)) { super(data, 1 / 8); }\n\n    public numValid = 0;\n    public get numInvalid() { return this.length - this.numValid; }\n    public get(idx: number) { return this.buffer[idx >> 3] >> idx % 8 & 1; }\n    public set(idx: number, val: number) {\n        const { buffer } = this.reserve(idx - this.length + 1);\n        const byte = idx >> 3, bit = idx % 8, cur = buffer[byte] >> bit & 1;\n        // If `val` is truthy and the current bit is 0, flip it to 1 and increment `numValid`.\n        // If `val` is falsey and the current bit is 1, flip it to 0 and decrement `numValid`.\n        val ? cur === 0 && ((buffer[byte] |=  (1 << bit)), ++this.numValid)\n            : cur === 1 && ((buffer[byte] &= ~(1 << bit)), --this.numValid);\n        return this;\n    }\n    public clear() {\n        this.numValid = 0;\n        return super.clear();\n    }\n}\n\n/** @ignore */\nexport class OffsetsBufferBuilder extends DataBufferBuilder<Int32Array> {\n    constructor(data = new Int32Array(1)) { super(data, 1); }\n    public append(value: number) {\n        return this.set(this.length - 1, value);\n    }\n    public set(index: number, value: number) {\n        const offset = this.length - 1;\n        const buffer = this.reserve(index - offset + 1).buffer;\n        if (offset < index++) {\n            buffer.fill(buffer[offset], offset, index);\n        }\n        buffer[index] = buffer[index - 1] + value;\n        return this;\n    }\n    public flush(length = this.length - 1) {\n        if (length > this.length) {\n            this.set(length - 1, 0);\n        }\n        return super.flush(length + 1);\n    }\n}\n\n/** @ignore */\nexport class WideBufferBuilder<T extends TypedArray, R extends BigIntArray> extends BufferBuilder<T, DataValue<T>> {\n    // @ts-ignore\n    public buffer64: R;\n    // @ts-ignore\n    protected _ArrayType64: BigIntArrayConstructor<R>;\n    public get ArrayType64() {\n        return this._ArrayType64 || (this._ArrayType64 = <BigIntArrayConstructor<R>> (this.buffer instanceof Int32Array ? BigInt64Array : BigUint64Array));\n    }\n    public set(index: number, value: DataValue<T>) {\n        this.reserve(index - this.length + 1);\n        switch (typeof value) {\n            case 'bigint': this.buffer64[index] = value; break;\n            case 'number': this.buffer[index * this.stride] = value; break;\n            default: this.buffer.set(value as TypedArray, index * this.stride);\n        }\n        return this;\n    }\n    protected _resize(newLength: number) {\n        const data = super._resize(newLength);\n        const length = data.byteLength / (this.BYTES_PER_ELEMENT * this.stride);\n        if (BigIntAvailable) {\n            this.buffer64 = new this.ArrayType64(data.buffer, data.byteOffset, length);\n        }\n        return data;\n    }\n}\n"]}