merlimat commented on a change in pull request #425: Add 
GrowablePriorityLongPairQueue and tests
URL: https://github.com/apache/incubator-pulsar/pull/425#discussion_r127357453
 
 

 ##########
 File path: 
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/GrowablePriorityLongPairQueue.java
 ##########
 @@ -0,0 +1,360 @@
+/**
+ * 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.pulsar.common.util.collections;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import io.netty.util.internal.MathUtil;
+
+/**
+ * An unbounded priority queue based on a min heap where values are composed 
of pairs of longs.
+ *
+ * When the capacity is reached, data will be moved to a bigger array.
+ * 
+ * <b>It also act as a set and doesn't store duplicate values if {@link 
#allowedDuplicate} flag is passed false</b>
+ * 
+ ** <p>
+ * (long,long)
+ * <p>
+ *
+ */
+public class GrowablePriorityLongPairQueue {
+
+    private long[] data;
+    private int capacity;
+    private volatile int size = 0;
+    private static final long EmptyItem = -1L;
+
+    public GrowablePriorityLongPairQueue() {
+        this(64);
+    }
+
+    public GrowablePriorityLongPairQueue(int initialCapacity) {
+        checkArgument(initialCapacity > 0);
+        this.capacity = MathUtil.findNextPositivePowerOfTwo(initialCapacity);
+        data = new long[2 * capacity];
+        fillEmptyValue(data, 0, data.length);
 
 Review comment:
   Instead of custom methods, we could use: 
   
   ```java
   Arrays.fill(data, 0, data.length, EmptyItem);
   ```
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to