rdhabalia commented on a change in pull request #425: Add GrowablePriorityLongPairQueue and tests URL: https://github.com/apache/incubator-pulsar/pull/425#discussion_r127040957
########## File path: pulsar-common/src/main/java/com/yahoo/pulsar/common/util/collections/GrowablePriorityLongPairQueue.java ########## @@ -0,0 +1,404 @@ +/** + * Copyright 2016 Yahoo Inc. + * + * Licensed 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 com.yahoo.pulsar.common.util.collections; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +import java.util.concurrent.locks.ReentrantLock; + +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 final ReentrantLock lock = new ReentrantLock(); + + private long[] data; + private int capacity; + private static final AtomicIntegerFieldUpdater<GrowablePriorityLongPairQueue> SIZE_UPDATER = AtomicIntegerFieldUpdater Review comment: actually, main motivation of keeping lock and AtomicInteger for Size was: 1. few methods don't need lock ie: exists(), size() and AtomicInteger would be fine there 2. keeping lock might be less expensive compare to taking mutex on each method. However, If we think keeping `Synchronized method` and `volatile member` would be better idea then I will make the change. ---------------------------------------------------------------- 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
