Find bitwidth faster for large arrays

This commit is contained in:
Kenny Daniel 2025-04-15 23:45:29 -07:00
parent c38151e32f
commit c15bcbe2b8
No known key found for this signature in database
GPG Key ID: 90AB653A8CAD7E45

@ -10,7 +10,11 @@ import { ByteWriter } from './bytewriter.js'
export function writeRleBitPackedHybrid(writer, values) {
const offsetStart = writer.offset
// find max bitwidth
const bitWidth = Math.ceil(Math.log2(Math.max(...values) + 1))
let max = 0
for (const v of values) {
if (v > max) max = v
}
const bitWidth = Math.ceil(Math.log2(max + 1))
// try both RLE and bit-packed and choose the best
const rle = new ByteWriter()