rdblue commented on code in PR #16747: URL: https://github.com/apache/iceberg/pull/16747#discussion_r3384392634
########## core/src/main/java/org/apache/iceberg/mumbling/MumblingBitmap.java: ########## @@ -0,0 +1,169 @@ +/* + * 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. + */ +package org.apache.iceberg.mumbling; + +import java.nio.ByteBuffer; +import org.apache.curator.shaded.com.google.common.base.Preconditions; + +/** + * Read-only view of a Mumbling compressed bitmap stored in a {@link ByteBuffer}. + * + * <p>The bitmap is lazy: no decoding is done at construction time. On the first call to {@link + * #isSet}, the PFOR-encoded descriptor array is decoded and used to build an offsets array that + * maps each container index to its absolute byte position in the buffer. This offsets array is the + * only derived state kept by this class. + * + * <p>Format (all integers unsigned, little-endian): + * + * <ul> + * <li>Header (6 bytes): version (1), cardinality (3), container count (2) + * <li>Descriptor array: PFOR-encoded, one byte per container + * <li>Containers: concatenated sparse (0–31 bytes) or dense (32 bytes) containers + * </ul> + */ +class MumblingBitmap { + private static final int VERSION = 1; + private static final int HEADER_SIZE = 6; + private static final int DENSE_CONTAINER_BIT = 0b0010_0000; + + private final ByteBuffer data; + private final int cardinality; + private final int containerCount; + private int[] descriptors = null; + private int[] offsets = null; + + MumblingBitmap(ByteBuffer data) { + int version = data.get(data.position()) & 0xFF; + if (version != VERSION) { + throw new UnsupportedOperationException("Unsupported Mumbling bitmap version: " + version); + } + + this.data = data; + this.cardinality = + (data.get(data.position() + 1) & 0xFF) + | ((data.get(data.position() + 2) & 0xFF) << 8) + | ((data.get(data.position() + 3) & 0xFF) << 16); Review Comment: This and other direct reads will be refactored to use utils in `ByteBuffers` after #16748 moves them out of `VariantUtil`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
