Class ConcurrentSortedLongPairSet
java.lang.Object
org.apache.pulsar.common.util.collections.ConcurrentSortedLongPairSet
- All Implemented Interfaces:
LongPairSet
Sorted concurrent
LongPairSet which is not fully accurate in sorting.
ConcurrentSortedLongPairSet creates separate ConcurrentLongPairSet for 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 ConcurrentLongPairSet objects.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.pulsar.common.util.collections.LongPairSet
LongPairSet.LongPairFunction<T>, LongPairSet.LongPairPredicate -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentSortedLongPairSet(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
Modifier and TypeMethodDescriptionbooleanadd(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.items()items(int numberOfItems) <T> Set<T>items(int numberOfItems, LongPairSet.LongPairFunction<T> longPairConverter) booleanremove(long item1, long item2) Removes composite value of item1 and item2 from set.intRemoves composite value of item1 and item2 from set if provided predicateLongPairSet.LongPairPredicatematches.longsize()Returns size of the set.toString()
-
Field Details
-
longPairSets
-
-
Constructor Details
-
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 Details
-
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
Description copied from interface:LongPairSetRemoves composite value of item1 and item2 from set if provided predicateLongPairSet.LongPairPredicatematches.- Specified by:
removeIfin interfaceLongPairSet- Returns:
-
items
- Specified by:
itemsin interfaceLongPairSet- Returns:
- a new list of all keys (makes a copy)
-
forEach
Description copied from interface:LongPairSetExecuteConcurrentLongPairSet.LongPairConsumerprocessor for each entry in the set.- Specified by:
forEachin interfaceLongPairSet
-
items
- Specified by:
itemsin interfaceLongPairSet- Returns:
- a new list of keys with max provided numberOfItems (makes a copy)
-
items
- Specified by:
itemsin interfaceLongPairSetlongPairConverter- converts (long,long) pair toobject - Returns:
- a new list of keys with max provided numberOfItems
-
toString
-
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:
-