Spaces:
Running
Running
File size: 4,904 Bytes
78c921d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
// 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.
/** @ignore */
export class ChunkedIterator {
constructor(numChunks = 0, getChunkIterator) {
this.numChunks = numChunks;
this.getChunkIterator = getChunkIterator;
this.chunkIndex = 0;
this.chunkIterator = this.getChunkIterator(0);
}
next() {
while (this.chunkIndex < this.numChunks) {
const next = this.chunkIterator.next();
if (!next.done) {
return next;
}
if (++this.chunkIndex < this.numChunks) {
this.chunkIterator = this.getChunkIterator(this.chunkIndex);
}
}
return { done: true, value: null };
}
[Symbol.iterator]() {
return this;
}
}
/** @ignore */
export function computeChunkNullCounts(chunks) {
return chunks.reduce((nullCount, chunk) => nullCount + chunk.nullCount, 0);
}
/** @ignore */
export function computeChunkOffsets(chunks) {
return chunks.reduce((offsets, chunk, index) => {
offsets[index + 1] = offsets[index] + chunk.length;
return offsets;
}, new Uint32Array(chunks.length + 1));
}
/** @ignore */
export function sliceChunks(chunks, offsets, begin, end) {
const slices = [];
for (let i = -1, n = chunks.length; ++i < n;) {
const chunk = chunks[i];
const offset = offsets[i];
const { length } = chunk;
// Stop if the child is to the right of the slice boundary
if (offset >= end) {
break;
}
// Exclude children to the left of of the slice boundary
if (begin >= offset + length) {
continue;
}
// Include entire child if between both left and right boundaries
if (offset >= begin && (offset + length) <= end) {
slices.push(chunk);
continue;
}
// Include the child slice that overlaps one of the slice boundaries
const from = Math.max(0, begin - offset);
const to = Math.min(end - offset, length);
slices.push(chunk.slice(from, to - from));
}
if (slices.length === 0) {
slices.push(chunks[0].slice(0, 0));
}
return slices;
}
/** @ignore */
export function binarySearch(chunks, offsets, idx, fn) {
let lhs = 0, mid = 0, rhs = offsets.length - 1;
do {
if (lhs >= rhs - 1) {
return (idx < offsets[rhs]) ? fn(chunks, lhs, idx - offsets[lhs]) : null;
}
mid = lhs + (Math.trunc((rhs - lhs) * .5));
idx < offsets[mid] ? (rhs = mid) : (lhs = mid);
} while (lhs < rhs);
}
/** @ignore */
export function isChunkedValid(data, index) {
return data.getValid(index);
}
/** @ignore */
export function wrapChunkedCall1(fn) {
function chunkedFn(chunks, i, j) { return fn(chunks[i], j); }
return function (index) {
const data = this.data;
return binarySearch(data, this._offsets, index, chunkedFn);
};
}
/** @ignore */
export function wrapChunkedCall2(fn) {
let _2;
function chunkedFn(chunks, i, j) { return fn(chunks[i], j, _2); }
return function (index, value) {
const data = this.data;
_2 = value;
const result = binarySearch(data, this._offsets, index, chunkedFn);
_2 = undefined;
return result;
};
}
/** @ignore */
export function wrapChunkedIndexOf(indexOf) {
let _1;
function chunkedIndexOf(data, chunkIndex, fromIndex) {
let begin = fromIndex, index = 0, total = 0;
for (let i = chunkIndex - 1, n = data.length; ++i < n;) {
const chunk = data[i];
if (~(index = indexOf(chunk, _1, begin))) {
return total + index;
}
begin = 0;
total += chunk.length;
}
return -1;
}
return function (element, offset) {
_1 = element;
const data = this.data;
const result = typeof offset !== 'number'
? chunkedIndexOf(data, 0, 0)
: binarySearch(data, this._offsets, offset, chunkedIndexOf);
_1 = undefined;
return result;
};
}
//# sourceMappingURL=chunk.mjs.map
|