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 concurrentLongPairSet
which is not fully accurate in sorting.ConcurrentSortedLongPairSet
creates separateConcurrentLongPairSet
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 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 boolean
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.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)
boolean
remove(long item1, long item2)
Removes composite value of item1 and item2 from set.int
removeIf(LongPairSet.LongPairPredicate filter)
Removes composite value of item1 and item2 from set if provided predicateLongPairSet.LongPairPredicate
matches.long
size()
Returns size of the set.java.lang.String
toString()
-
-
-
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: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
public int removeIf(LongPairSet.LongPairPredicate filter)
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
public java.util.Set<ConcurrentLongPairSet.LongPair> items()
- Specified by:
items
in interfaceLongPairSet
- Returns:
- a new list of all keys (makes a copy)
-
forEach
public void forEach(ConcurrentLongPairSet.LongPairConsumer processor)
Description copied from interface:LongPairSet
ExecuteConcurrentLongPairSet.LongPairConsumer
processor for each entry in the set.- Specified by:
forEach
in interfaceLongPairSet
-
items
public java.util.Set<ConcurrentLongPairSet.LongPair> items(int numberOfItems)
- Specified by:
items
in 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:
items
in interfaceLongPairSet
longPairConverter
- converts (long,long) pair toobject - Returns:
- a new list of keys with max provided numberOfItems
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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:
-
-