chia7712 commented on code in PR #23722:
URL: https://github.com/apache/kafka/pull/23722#discussion_r4285704398


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/uniform2/util/IntList.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.kafka.coordinator.group.assignor.uniform2.util;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+/**
+ * A growable list of primitive ints, avoiding the boxing of a {@code 
List<Integer>}.
+ *
+ * <p>It differs from a {@link java.util.List} in two ways:
+ * <ul>
+ *   <li>{@link #get(int)} does not check that its index is below the size, to 
keep the reads
+ *       cheap.</li>
+ *   <li>{@link #remove(int)} moves the last element into the place of the 
removed one, in
+ *       constant time, so it does not preserve the order of the elements.</li>
+ * </ul>
+ *
+ * <p>The methods that change the list check their arguments.
+ */
+public final class IntList {
+    private int[] elements;
+    private int size;
+
+    /**
+     * Creates an empty list.
+     *
+     * @param capacity The initial capacity.
+     * @throws IllegalArgumentException If the capacity is negative.
+     */
+    public IntList(int capacity) {
+        if (capacity < 0) {
+            throw new IllegalArgumentException("Negative capacity " + 
capacity);
+        }
+        this.elements = new int[capacity];
+    }
+
+    /**
+     * Creates a list holding a copy of elements, with a capacity of their 
number.
+     *
+     * @param elements The elements.
+     * @return The list.
+     */
+    public static IntList of(int... elements) {
+        var list = new IntList(elements.length);
+        System.arraycopy(elements, 0, list.elements, 0, elements.length);
+        list.size = elements.length;
+        return list;
+    }
+
+    /**
+     * @return The number of elements.
+     */
+    public int size() {
+        return size;
+    }
+
+    /**
+     * @return {@code true} if the list has no elements.
+     */
+    public boolean isEmpty() {
+        return size == 0;
+    }
+
+    /**
+     * Returns the element at the index. Does not check that the index is 
below the size: at an

Review Comment:
   Excuse me, why don’t we check the size here? Is this for performance, or for 
some specific use case?



-- 
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]

Reply via email to