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AAED,cAAc;AACd,MAAM,UAAU,aAAa,CAAC,MAAc;IACxC,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IACnB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IACjC,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IAChD,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;AAChE,CAAC","file":"bit.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\n/** @ignore */\nexport function getBool(_data: any, _index: number, byte: number, bit: number) {\n return (byte & 1 << bit) !== 0;\n}\n\n/** @ignore */\nexport function getBit(_data: any, _index: number, byte: number, bit: number): 0 | 1 {\n return (byte & 1 << bit) >> bit as (0 | 1);\n}\n\n/** @ignore */\nexport function setBool(bytes: Uint8Array, index: number, value: any) {\n return value ?\n !!(bytes[index >> 3] |= (1 << (index % 8))) || true :\n !(bytes[index >> 3] &= ~(1 << (index % 8))) && false ;\n}\n\n/** @ignore */\nexport function truncateBitmap(offset: number, length: number, bitmap: Uint8Array) {\n const alignedSize = (bitmap.byteLength + 7) & ~7;\n if (offset > 0 || bitmap.byteLength < alignedSize) {\n const bytes = new Uint8Array(alignedSize);\n // If the offset is a multiple of 8 bits, it's safe to slice the bitmap\n bytes.set(offset % 8 === 0 ? bitmap.subarray(offset >> 3) :\n // Otherwise iterate each bit from the offset and return a new one\n packBools(iterateBits(bitmap, offset, length, null, getBool)).subarray(0, alignedSize));\n return bytes;\n }\n return bitmap;\n}\n\n/** @ignore */\nexport function packBools(values: Iterable) {\n let xs: number[] = [];\n let i = 0, bit = 0, byte = 0;\n for (const value of values) {\n value && (byte |= 1 << bit);\n if (++bit === 8) {\n xs[i++] = byte;\n byte = bit = 0;\n }\n }\n if (i === 0 || bit > 0) { xs[i++] = byte; }\n let b = new Uint8Array((xs.length + 7) & ~7);\n b.set(xs);\n return b;\n}\n\n/** @ignore */\nexport function* iterateBits(bytes: Uint8Array, begin: number, length: number, context: any,\n get: (context: any, index: number, byte: number, bit: number) => T) {\n let bit = begin % 8;\n let byteIndex = begin >> 3;\n let index = 0, remaining = length;\n for (; remaining > 0; bit = 0) {\n let byte = bytes[byteIndex++];\n do {\n yield get(context, index++, byte, bit);\n } while (--remaining > 0 && ++bit < 8);\n }\n}\n\n/**\n * Compute the population count (the number of bits set to 1) for a range of bits in a Uint8Array.\n * @param vector The Uint8Array of bits for which to compute the population count.\n * @param lhs The range's left-hand side (or start) bit\n * @param rhs The range's right-hand side (or end) bit\n */\n/** @ignore */\nexport function popcnt_bit_range(data: Uint8Array, lhs: number, rhs: number): number {\n if (rhs - lhs <= 0) { return 0; }\n // If the bit range is less than one byte, sum the 1 bits in the bit range\n if (rhs - lhs < 8) {\n let sum = 0;\n for (const bit of iterateBits(data, lhs, rhs - lhs, data, getBit)) {\n sum += bit;\n }\n return sum;\n }\n // Get the next lowest multiple of 8 from the right hand side\n const rhsInside = rhs >> 3 << 3;\n // Get the next highest multiple of 8 from the left hand side\n const lhsInside = lhs + (lhs % 8 === 0 ? 0 : 8 - lhs % 8);\n return (\n // Get the popcnt of bits between the left hand side, and the next highest multiple of 8\n popcnt_bit_range(data, lhs, lhsInside) +\n // Get the popcnt of bits between the right hand side, and the next lowest multiple of 8\n popcnt_bit_range(data, rhsInside, rhs) +\n // Get the popcnt of all bits between the left and right hand sides' multiples of 8\n popcnt_array(data, lhsInside >> 3, (rhsInside - lhsInside) >> 3)\n );\n}\n\n/** @ignore */\nexport function popcnt_array(arr: ArrayBufferView, byteOffset?: number, byteLength?: number) {\n let cnt = 0, pos = byteOffset! | 0;\n const view = new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n const len = byteLength === void 0 ? arr.byteLength : pos + byteLength;\n while (len - pos >= 4) {\n cnt += popcnt_uint32(view.getUint32(pos));\n pos += 4;\n }\n while (len - pos >= 2) {\n cnt += popcnt_uint32(view.getUint16(pos));\n pos += 2;\n }\n while (len - pos >= 1) {\n cnt += popcnt_uint32(view.getUint8(pos));\n pos += 1;\n }\n return cnt;\n}\n\n/** @ignore */\nexport function popcnt_uint32(uint32: number): number {\n let i = uint32 | 0;\n i = i - ((i >>> 1) & 0x55555555);\n i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);\n return (((i + (i >>> 4)) & 0x0F0F0F0F) * 0x01010101) >>> 24;\n}\n"]}