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AM,CAAC;QACnC,KAAK,WAAW,CAAC,CAAI,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QACtD,KAAK,cAAc,CAAC,CAAC,OAAO,MAAM,CAAC;QACnC,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;KACxB;AACL,CAAC,CAAC;AAEF,cAAc;AACd,MAAM,oBAAoB,GAAG,CAAC,IAA2B,EAAE,OAAgB,EAAE,EAAE;IAC3E,QAAQ,IAAI,EAAE;QACV,KAAK,UAAU,CAAC,CAAG,OAAO,IAAI,CAAC;QAC/B,KAAK,WAAW,CAAC,CAAE,OAAO,KAAK,CAAC;QAChC,KAAK,WAAW,CAAC,CAAE,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAClD,KAAK,WAAW,CAAC,CAAE,OAAO,KAAK,CAAC;QAChC,KAAK,WAAW,CAAC,CAAE,OAAO,KAAK,CAAC;QAChC,KAAK,YAAY,CAAC,CAAC,OAAO,MAAM,CAAC;QACjC,KAAK,YAAY,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QACpD,KAAK,YAAY,CAAC,CAAC,OAAO,MAAM,CAAC;QACjC,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;KACxB;AACL,CAAC,CAAC","file":"int.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 { Data } from '../data';\nimport { Vector } from '../vector';\nimport { Chunked } from './chunked';\nimport { BaseVector } from './base';\nimport { VectorBuilderOptions } from './index';\nimport { vectorFromValuesWithType } from './index';\nimport { VectorBuilderOptionsAsync } from './index';\nimport { BigInt64Array, BigUint64Array } from '../util/compat';\nimport { toBigInt64Array, toBigUint64Array } from '../util/buffer';\nimport { Int, Uint8, Uint16, Uint32, Uint64, Int8, Int16, Int32, Int64, IntArray } from '../type';\nimport { VectorType as V, TypedArrayConstructor, BigIntArrayConstructor, BigIntArray } from '../interfaces';\n\n/** @ignore */\ntype IntVectorConstructors =\n    typeof IntVector    |\n    typeof Int8Vector   |\n    typeof Int16Vector  |\n    typeof Int32Vector  |\n    typeof Uint8Vector  |\n    typeof Uint16Vector |\n    typeof Uint32Vector |\n    typeof Int64Vector  |\n    typeof Uint64Vector ;\n\n/** @ignore */\ntype FromInput<T extends Int, TNull = any> =\n    IntArray | BigIntArray              |\n    Iterable<T['TValue'] | TNull>       |\n    AsyncIterable<T['TValue'] | TNull>  |\n    VectorBuilderOptions<T, TNull>      |\n    VectorBuilderOptionsAsync<T, TNull> ;\n\n/** @ignore */\ntype FromArgs<T extends Int, TNull = any> = [FromInput<T, TNull>, boolean?];\n\n/** @ignore */\ntype IntArrayCtor = TypedArrayConstructor<IntArray> | BigIntArrayConstructor<BigIntArray>;\n\n/** @ignore */\nexport class IntVector<T extends Int = Int> extends BaseVector<T> {\n\n    // Guaranteed zero-copy variants\n    public static from(this: typeof IntVector, input: Int8Array): Int8Vector;\n    public static from(this: typeof IntVector, input: Int16Array): Int16Vector;\n    public static from(this: typeof IntVector, input: Int32Array): Int32Vector;\n    public static from(this: typeof IntVector, input: BigInt64Array): Int64Vector;\n    public static from(this: typeof IntVector, input: Int32Array, is64bit: true): Int64Vector;\n    public static from(this: typeof IntVector, input: Uint8Array): Uint8Vector;\n    public static from(this: typeof IntVector, input: Uint16Array): Uint16Vector;\n    public static from(this: typeof IntVector, input: Uint32Array): Uint32Vector;\n    public static from(this: typeof IntVector, input: BigUint64Array): Uint64Vector;\n    public static from(this: typeof IntVector, input: Uint32Array, is64bit: true): Uint64Vector;\n\n    // Zero-copy if input is a TypedArray of the same type as the\n    // Vector that from is called on, otherwise uses the Builders\n    public static from<TNull = any>(this: typeof Int8Vector,   input: FromInput<Int8, TNull>): Int8Vector;\n    public static from<TNull = any>(this: typeof Int16Vector,  input: FromInput<Int16, TNull>): Int16Vector;\n    public static from<TNull = any>(this: typeof Int32Vector,  input: FromInput<Int32, TNull>): Int32Vector;\n    public static from<TNull = any>(this: typeof Int64Vector,  input: FromInput<Int64, TNull>): Int64Vector;\n    public static from<TNull = any>(this: typeof Uint8Vector,  input: FromInput<Uint8, TNull>): Uint8Vector;\n    public static from<TNull = any>(this: typeof Uint16Vector, input: FromInput<Uint16, TNull>): Uint16Vector;\n    public static from<TNull = any>(this: typeof Uint32Vector, input: FromInput<Uint32, TNull>): Uint32Vector;\n    public static from<TNull = any>(this: typeof Uint64Vector, input: FromInput<Uint64, TNull>): Uint64Vector;\n\n    // Not zero-copy\n    public static from<T extends Int, TNull = any>(this: typeof IntVector, input: Iterable<T['TValue'] | TNull>): V<T>;\n    public static from<T extends Int, TNull = any>(this: typeof IntVector, input: AsyncIterable<T['TValue'] | TNull>): Promise<V<T>>;\n    public static from<T extends Int, TNull = any>(this: typeof IntVector, input: VectorBuilderOptions<T, TNull>): Chunked<T>;\n    public static from<T extends Int, TNull = any>(this: typeof IntVector, input: VectorBuilderOptionsAsync<T, TNull>): Promise<Chunked<T>>;\n    /** @nocollapse */\n    public static from<T extends Int, TNull = any>(this: IntVectorConstructors, ...args: FromArgs<T, TNull>) {\n\n        let [input, is64bit = false] = args;\n        let ArrowType = vectorTypeToDataType(this, is64bit);\n\n        if ((input instanceof ArrayBuffer) || ArrayBuffer.isView(input)) {\n            let InputType = arrayTypeToDataType(input.constructor as IntArrayCtor, is64bit) || ArrowType;\n            // Special case, infer the Arrow DataType from the input if calling the base\n            // IntVector.from with a TypedArray, e.g. `IntVector.from(new Int32Array())`\n            if (ArrowType === null) {\n                ArrowType = InputType;\n            }\n            // If the DataType inferred from the Vector constructor matches the\n            // DataType inferred from the input arguments, return zero-copy view\n            if (ArrowType && ArrowType === InputType) {\n                let type = new ArrowType();\n                let length = input.byteLength / type.ArrayType.BYTES_PER_ELEMENT;\n                // If the ArrowType is 64bit but the input type is 32bit pairs, update the logical length\n                if (convert32To64Bit(ArrowType, input.constructor)) {\n                    length *= 0.5;\n                }\n                return Vector.new(Data.Int(type, 0, length, 0, null, input as IntArray));\n            }\n        }\n\n        if (ArrowType) {\n            // If the DataType inferred from the Vector constructor is different than\n            // the DataType inferred from the input TypedArray, or if input isn't a\n            // TypedArray, use the Builders to construct the result Vector\n            return vectorFromValuesWithType(() => new ArrowType!() as T, input);\n        }\n\n        if ((input instanceof DataView) || (input instanceof ArrayBuffer)) {\n            throw new TypeError(`Cannot infer integer type from instance of ${input.constructor.name}`);\n        }\n\n        throw new TypeError('Unrecognized IntVector input');\n    }\n}\n\n/** @ignore */\nexport class Int8Vector extends IntVector<Int8> {}\n/** @ignore */\nexport class Int16Vector extends IntVector<Int16> {}\n/** @ignore */\nexport class Int32Vector extends IntVector<Int32> {}\n/** @ignore */\nexport class Int64Vector extends IntVector<Int64> {\n    public toBigInt64Array() {\n        return toBigInt64Array(this.values);\n    }\n    // @ts-ignore\n    private _values64: BigInt64Array;\n    public get values64(): BigInt64Array {\n        return this._values64 || (this._values64 = this.toBigInt64Array());\n    }\n}\n\n/** @ignore */\nexport class Uint8Vector extends IntVector<Uint8> {}\n/** @ignore */\nexport class Uint16Vector extends IntVector<Uint16> {}\n/** @ignore */\nexport class Uint32Vector extends IntVector<Uint32> {}\n/** @ignore */\nexport class Uint64Vector extends IntVector<Uint64> {\n    public toBigUint64Array() {\n        return toBigUint64Array(this.values);\n    }\n    // @ts-ignore\n    private _values64: BigUint64Array;\n    public get values64(): BigUint64Array {\n        return this._values64 || (this._values64 = this.toBigUint64Array());\n    }\n}\n\nconst convert32To64Bit = (typeCtor: any, dataCtor: any) => {\n    return (typeCtor === Int64 || typeCtor === Uint64) &&\n           (dataCtor === Int32Array || dataCtor === Uint32Array);\n};\n\n/** @ignore */\nconst arrayTypeToDataType = (ctor: IntArrayCtor, is64bit: boolean) => {\n    switch (ctor) {\n        case Int8Array:      return Int8;\n        case Int16Array:     return Int16;\n        case Int32Array:     return is64bit ? Int64 : Int32;\n        case BigInt64Array:  return Int64;\n        case Uint8Array:     return Uint8;\n        case Uint16Array:    return Uint16;\n        case Uint32Array:    return is64bit ? Uint64 : Uint32;\n        case BigUint64Array: return Uint64;\n        default: return null;\n    }\n};\n\n/** @ignore */\nconst vectorTypeToDataType = (ctor: IntVectorConstructors, is64bit: boolean) => {\n    switch (ctor) {\n        case Int8Vector:   return Int8;\n        case Int16Vector:  return Int16;\n        case Int32Vector:  return is64bit ? Int64 : Int32;\n        case Int64Vector:  return Int64;\n        case Uint8Vector:  return Uint8;\n        case Uint16Vector: return Uint16;\n        case Uint32Vector: return is64bit ? Uint64 : Uint32;\n        case Uint64Vector: return Uint64;\n        default: return null;\n    }\n};\n"]}