Class ConcurrentSortedLongPairSet
- java.lang.Object
-
- org.apache.pulsar.common.util.collections.ConcurrentSortedLongPairSet
-
- All Implemented Interfaces:
LongPairSet
public class ConcurrentSortedLongPairSet extends java.lang.Object implements LongPairSet
Sorted concurrentLongPairSetwhich is not fully accurate in sorting.ConcurrentSortedLongPairSetcreates separateConcurrentLongPairSetfor unique first-key of inserted item. So, it can iterate over all items by sorting on item's first key. However, item's second key will not be sorted. eg:insert: (1,2), (1,4), (2,1), (1,5), (2,6) while iterating set will first read all the entries for items whose first-key=1 and then first-key=2. output: (1,4), (1,5), (1,2), (2,6), (2,1)
This map can be expensive and not recommended if set has to store large number of unique item.first's key because set has to create that many
ConcurrentLongPairSetobjects.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pulsar.common.util.collections.LongPairSet
LongPairSet.LongPairFunction<T>, LongPairSet.LongPairPredicate
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.NavigableMap<java.lang.Long,ConcurrentLongPairSet>longPairSets
-
Constructor Summary
Constructors Constructor Description ConcurrentSortedLongPairSet()ConcurrentSortedLongPairSet(int expectedItems)ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel)ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel, boolean autoShrink)ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel, int maxAllowedSetOnRemove)ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel, int maxAllowedSetOnRemove, boolean autoShrink)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(long item1, long item2)Adds composite value of item1 and item2 to set.longcapacity()Returns capacity of the set.voidclear()Removes all items from set.booleancontains(long item1, long item2)Checks if given (item1,item2) composite value exists into set.voidforEach(ConcurrentLongPairSet.LongPairConsumer processor)ExecuteConcurrentLongPairSet.LongPairConsumerprocessor for each entry in the set.booleanisEmpty()Check if set is empty.java.util.Set<ConcurrentLongPairSet.LongPair>items()java.util.Set<ConcurrentLongPairSet.LongPair>items(int numberOfItems)<T> java.util.Set<T>items(int numberOfItems, LongPairSet.LongPairFunction<T> longPairConverter)booleanremove(long item1, long item2)Removes composite value of item1 and item2 from set.intremoveIf(LongPairSet.LongPairPredicate filter)Removes composite value of item1 and item2 from set if provided predicateLongPairSet.LongPairPredicatematches.longsize()Returns size of the set.java.lang.StringtoString()
-
-
-
Field Detail
-
longPairSets
protected final java.util.NavigableMap<java.lang.Long,ConcurrentLongPairSet> longPairSets
-
-
Constructor Detail
-
ConcurrentSortedLongPairSet
public ConcurrentSortedLongPairSet()
-
ConcurrentSortedLongPairSet
public ConcurrentSortedLongPairSet(int expectedItems)
-
ConcurrentSortedLongPairSet
public ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel)
-
ConcurrentSortedLongPairSet
public ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel, boolean autoShrink)
-
ConcurrentSortedLongPairSet
public ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel, int maxAllowedSetOnRemove)
-
ConcurrentSortedLongPairSet
public ConcurrentSortedLongPairSet(int expectedItems, int concurrencyLevel, int maxAllowedSetOnRemove, boolean autoShrink)
-
-
Method Detail
-
add
public boolean add(long item1, long item2)Description copied from interface:LongPairSetAdds composite value of item1 and item2 to set.- Specified by:
addin interfaceLongPairSet- Returns:
-
remove
public boolean remove(long item1, long item2)Description copied from interface:LongPairSetRemoves composite value of item1 and item2 from set.- Specified by:
removein interfaceLongPairSet- Returns:
-
removeIf
public int removeIf(LongPairSet.LongPairPredicate filter)
Description copied from interface:LongPairSetRemoves composite value of item1 and item2 from set if provided predicateLongPairSet.LongPairPredicatematches.- Specified by:
removeIfin interfaceLongPairSet- Returns:
-
items
public java.util.Set<ConcurrentLongPairSet.LongPair> items()
- Specified by:
itemsin interfaceLongPairSet- Returns:
- a new list of all keys (makes a copy)
-
forEach
public void forEach(ConcurrentLongPairSet.LongPairConsumer processor)
Description copied from interface:LongPairSetExecuteConcurrentLongPairSet.LongPairConsumerprocessor for each entry in the set.- Specified by:
forEachin interfaceLongPairSet
-
items
public java.util.Set<ConcurrentLongPairSet.LongPair> items(int numberOfItems)
- Specified by:
itemsin interfaceLongPairSet- Returns:
- a new list of keys with max provided numberOfItems (makes a copy)
-
items
public <T> java.util.Set<T> items(int numberOfItems, LongPairSet.LongPairFunction<T> longPairConverter)- Specified by:
itemsin interfaceLongPairSetlongPairConverter- converts (long,long) pair toobject - Returns:
- a new list of keys with max provided numberOfItems
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isEmpty
public boolean isEmpty()
Description copied from interface:LongPairSetCheck if set is empty.- Specified by:
isEmptyin interfaceLongPairSet- Returns:
-
clear
public void clear()
Description copied from interface:LongPairSetRemoves all items from set.- Specified by:
clearin interfaceLongPairSet
-
size
public long size()
Description copied from interface:LongPairSetReturns size of the set.- Specified by:
sizein interfaceLongPairSet- Returns:
-
capacity
public long capacity()
Description copied from interface:LongPairSetReturns capacity of the set.- Specified by:
capacityin interfaceLongPairSet- Returns:
-
contains
public boolean contains(long item1, long item2)Description copied from interface:LongPairSetChecks if given (item1,item2) composite value exists into set.- Specified by:
containsin interfaceLongPairSet- Returns:
-
-