// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. import { Visitor } from '../visitor.mjs'; import { Type, Precision } from '../enum.mjs'; import { Float, Int, Time, } from '../type.mjs'; import { ChunkedIterator } from '../util/chunk.mjs'; /** @ignore */ export class IteratorVisitor extends Visitor { } /** @ignore */ function vectorIterator(vector) { const { type } = vector; // Fast case, defer to native iterators if possible if (vector.nullCount === 0 && vector.stride === 1 && ((type.typeId === Type.Timestamp) || (type instanceof Int && type.bitWidth !== 64) || (type instanceof Time && type.bitWidth !== 64) || (type instanceof Float && type.precision !== Precision.HALF))) { return new ChunkedIterator(vector.data.length, (chunkIndex) => { const data = vector.data[chunkIndex]; return data.values.subarray(0, data.length)[Symbol.iterator](); }); } // Otherwise, iterate manually let offset = 0; return new ChunkedIterator(vector.data.length, (chunkIndex) => { const data = vector.data[chunkIndex]; const length = data.length; const inner = vector.slice(offset, offset + length); offset += length; return new VectorIterator(inner); }); } /** @ignore */ class VectorIterator { constructor(vector) { this.vector = vector; this.index = 0; } next() { if (this.index < this.vector.length) { return { value: this.vector.get(this.index++) }; } return { done: true, value: null }; } [Symbol.iterator]() { return this; } } IteratorVisitor.prototype.visitNull = vectorIterator; IteratorVisitor.prototype.visitBool = vectorIterator; IteratorVisitor.prototype.visitInt = vectorIterator; IteratorVisitor.prototype.visitInt8 = vectorIterator; IteratorVisitor.prototype.visitInt16 = vectorIterator; IteratorVisitor.prototype.visitInt32 = vectorIterator; IteratorVisitor.prototype.visitInt64 = vectorIterator; IteratorVisitor.prototype.visitUint8 = vectorIterator; IteratorVisitor.prototype.visitUint16 = vectorIterator; IteratorVisitor.prototype.visitUint32 = vectorIterator; IteratorVisitor.prototype.visitUint64 = vectorIterator; IteratorVisitor.prototype.visitFloat = vectorIterator; IteratorVisitor.prototype.visitFloat16 = vectorIterator; IteratorVisitor.prototype.visitFloat32 = vectorIterator; IteratorVisitor.prototype.visitFloat64 = vectorIterator; IteratorVisitor.prototype.visitUtf8 = vectorIterator; IteratorVisitor.prototype.visitBinary = vectorIterator; IteratorVisitor.prototype.visitFixedSizeBinary = vectorIterator; IteratorVisitor.prototype.visitDate = vectorIterator; IteratorVisitor.prototype.visitDateDay = vectorIterator; IteratorVisitor.prototype.visitDateMillisecond = vectorIterator; IteratorVisitor.prototype.visitTimestamp = vectorIterator; IteratorVisitor.prototype.visitTimestampSecond = vectorIterator; IteratorVisitor.prototype.visitTimestampMillisecond = vectorIterator; IteratorVisitor.prototype.visitTimestampMicrosecond = vectorIterator; IteratorVisitor.prototype.visitTimestampNanosecond = vectorIterator; IteratorVisitor.prototype.visitTime = vectorIterator; IteratorVisitor.prototype.visitTimeSecond = vectorIterator; IteratorVisitor.prototype.visitTimeMillisecond = vectorIterator; IteratorVisitor.prototype.visitTimeMicrosecond = vectorIterator; IteratorVisitor.prototype.visitTimeNanosecond = vectorIterator; IteratorVisitor.prototype.visitDecimal = vectorIterator; IteratorVisitor.prototype.visitList = vectorIterator; IteratorVisitor.prototype.visitStruct = vectorIterator; IteratorVisitor.prototype.visitUnion = vectorIterator; IteratorVisitor.prototype.visitDenseUnion = vectorIterator; IteratorVisitor.prototype.visitSparseUnion = vectorIterator; IteratorVisitor.prototype.visitDictionary = vectorIterator; IteratorVisitor.prototype.visitInterval = vectorIterator; IteratorVisitor.prototype.visitIntervalDayTime = vectorIterator; IteratorVisitor.prototype.visitIntervalYearMonth = vectorIterator; IteratorVisitor.prototype.visitFixedSizeList = vectorIterator; IteratorVisitor.prototype.visitMap = vectorIterator; /** @ignore */ export const instance = new IteratorVisitor(); //# sourceMappingURL=iterator.mjs.map