pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [pulsar] merlimat commented on a change in pull request #3818: [pulsar-common] add open Concurrent LongPair RangeSet
Date Fri, 17 May 2019 18:07:40 GMT
merlimat commented on a change in pull request #3818: [pulsar-common] add open Concurrent LongPair
RangeSet
URL: https://github.com/apache/pulsar/pull/3818#discussion_r285229922
 
 

 ##########
 File path: pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSet.java
 ##########
 @@ -0,0 +1,474 @@
+/**
+ * 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.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.StampedLock;
+
+import org.apache.pulsar.common.util.collections.LongPairRangeSet.LongPairConsumer;
+import org.apache.pulsar.common.util.collections.LongPairRangeSet.RangeProcessor;
+
+import com.google.common.collect.BoundType;
+import com.google.common.collect.Range;
+
+/**
+ * A Concurrent set comprising zero or more ranges of type {@link LongPair}. This can be
alternative of
+ * {@link com.google.common.collect.RangeSet} and can be used if {@code range} type is {@link
LongPair} </br>
+ * 
+ * <pre>
+ *  
+ * Usage:
+ * a. This can be used if one doesn't want to create object for every new inserted {@code
range}
+ * b. It creates {@link BitSet} for every unique first-key of the range. 
+ * So, this rangeSet is not suitable for large number of unique keys.
+ * </pre>
+ * 
+ *
+ */
+public class ConcurrentOpenLongPairRangeSet<T extends Comparable<T>> implements
LongPairRangeSet<T> {
+
+    protected final NavigableMap<Long, BitSet> rangeBitSetMap = new ConcurrentSkipListMap<>();
+    private boolean threadSafe = true;
+    private final int bitSetSize;
+    private final LongPairConsumer<T> consumer;
+
+    // caching place-holder for cpu-optimization to avoid calculating ranges again
+    private volatile int cachedSize = 0;
+    private volatile String cachedToString = "[]";
+    private volatile boolean updatedAfterCached = true;
+
+    public ConcurrentOpenLongPairRangeSet(LongPairConsumer<T> consumer) {
 
 Review comment:
   Can you clarify what is the purpose of the "consumer"? Since it's not typical to have a
consumer on a set.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message