aokolnychyi commented on code in PR #11372:
URL: https://github.com/apache/iceberg/pull/11372#discussion_r1819516956


##########
core/src/main/java/org/apache/iceberg/deletes/RoaringPositionBitmap.java:
##########
@@ -0,0 +1,318 @@
+/*
+ * 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.deletes;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.List;
+import java.util.function.LongConsumer;
+import 
org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.roaringbitmap.RoaringBitmap;
+
+/**
+ * A bitmap that supports positive 64-bit positions (the most significant bit 
must be 0), but is
+ * optimized for cases where most positions fit in 32 bits by using an array 
of 32-bit Roaring
+ * bitmaps. The internal bitmap array is grown as needed to accommodate the 
largest position.
+ *
+ * <p>Incoming 64-bit positions are divided into a 32-bit "key" using the most 
significant 4 bytes
+ * and a 32-bit position using the least significant 4 bytes. For each key in 
the set of positions,
+ * a 32-bit Roaring bitmap is maintained to store a set of 32-bit positions 
for that key.
+ *
+ * <p>To test whether a certain position is set, its most significant 4 bytes 
(the key) are used to
+ * find a 32-bit bitmap and the least significant 4 bytes are tested for 
inclusion in the bitmap. If
+ * a bitmap is not found for the key, then the position is not set.
+ *
+ * <p>Positions must range from 0 (inclusive) to {@link #MAX_POSITION} 
(inclusive). This class
+ * cannot handle positions with the key equal to Integer.MAX_VALUE because the 
length of the
+ * internal bitmap array is a signed 32-bit integer, which must be greater 
than or equal to 0.
+ * Supporting Integer.MAX_VALUE as a key would require allocating a bitmap 
array with size
+ * Integer.MAX_VALUE + 1, triggering an integer overflow.
+ */
+class RoaringPositionBitmap {
+
+  static final long MAX_POSITION = toPosition(Integer.MAX_VALUE - 1, 
Integer.MIN_VALUE);
+  private static final RoaringBitmap[] EMPTY_BITMAP_ARRAY = new 
RoaringBitmap[0];
+  private static final long BITMAP_COUNT_SIZE_BYTES = 8L;
+  private static final long BITMAP_KEY_SIZE_BYTES = 4L;
+
+  private RoaringBitmap[] bitmaps;
+
+  RoaringPositionBitmap() {
+    this.bitmaps = EMPTY_BITMAP_ARRAY;
+  }
+
+  private RoaringPositionBitmap(RoaringBitmap[] bitmaps) {
+    this.bitmaps = bitmaps;
+  }
+
+  /**
+   * Sets a position in the bitmap.
+   *
+   * @param pos the position
+   */
+  public void set(long pos) {

Review Comment:
   @RussellSpitzer, I switched to `set` instead of `add`. It matches `BitSet` 
in Java. 



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to