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
-
Constructor Summary
ConstructorDescriptionConcurrentSortedLongPairSet
(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 TypeMethodDescriptionboolean
add
(long item1, long item2) Adds composite value of item1 and item2 to set.long
capacity()
Returns capacity of the set.void
clear()
Removes all items from set.boolean
contains
(long item1, long item2) Checks if given (item1,item2) composite value exists into set.void
forEach
(ConcurrentLongPairSet.LongPairConsumer processor) ExecuteConcurrentLongPairSet.LongPairConsumer
processor for each entry in the set.boolean
isEmpty()
Check if set is empty.items()
items
(int numberOfItems) <T> Set<T>
items
(int numberOfItems, LongPairSet.LongPairFunction<T> longPairConverter) boolean
remove
(long item1, long item2) Removes composite value of item1 and item2 from set.int
Removes composite value of item1 and item2 from set if provided predicateLongPairSet.LongPairPredicate
matches.long
size()
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:LongPairSet
Adds composite value of item1 and item2 to set.- Specified by:
add
in interfaceLongPairSet
- Returns:
-
remove
public boolean remove(long item1, long item2) Description copied from interface:LongPairSet
Removes composite value of item1 and item2 from set.- Specified by:
remove
in interfaceLongPairSet
- Returns:
-
removeIf
Description copied from interface:LongPairSet
Removes composite value of item1 and item2 from set if provided predicateLongPairSet.LongPairPredicate
matches.- Specified by:
removeIf
in interfaceLongPairSet
- Returns:
-
items
- Specified by:
items
in interfaceLongPairSet
- Returns:
- a new list of all keys (makes a copy)
-
forEach
Description copied from interface:LongPairSet
ExecuteConcurrentLongPairSet.LongPairConsumer
processor for each entry in the set.- Specified by:
forEach
in interfaceLongPairSet
-
items
- Specified by:
items
in interfaceLongPairSet
- Returns:
- a new list of keys with max provided numberOfItems (makes a copy)
-
items
- Specified by:
items
in interfaceLongPairSet
longPairConverter
- converts (long,long) pair toobject - Returns:
- a new list of keys with max provided numberOfItems
-
toString
-
isEmpty
public boolean isEmpty()Description copied from interface:LongPairSet
Check if set is empty.- Specified by:
isEmpty
in interfaceLongPairSet
- Returns:
-
clear
public void clear()Description copied from interface:LongPairSet
Removes all items from set.- Specified by:
clear
in interfaceLongPairSet
-
size
public long size()Description copied from interface:LongPairSet
Returns size of the set.- Specified by:
size
in interfaceLongPairSet
- Returns:
-
capacity
public long capacity()Description copied from interface:LongPairSet
Returns capacity of the set.- Specified by:
capacity
in interfaceLongPairSet
- Returns:
-
contains
public boolean contains(long item1, long item2) Description copied from interface:LongPairSet
Checks if given (item1,item2) composite value exists into set.- Specified by:
contains
in interfaceLongPairSet
- Returns:
-