CopyOnWriteMultiset
@UnstableApi
class CopyOnWriteMultiset<E : Any?> : Iterable
An unordered collection of elements that allows duplicates, but also allows access to a set of unique elements.
This class is thread-safe using the same method as java.util.concurrent.CopyOnWriteArrayList. Mutation methods cause the underlying data to be copied. elementSet and iterator return snapshots that are unaffected by subsequent mutations.
Iterating directly on this class reveals duplicate elements. Unique elements can be accessed via elementSet. Iteration order for both of these is not defined.
| Parameters | |
|---|---|
<E : Any?> |
The type of element being stored. |
Summary
Public constructors |
|---|
Public functions |
|
|---|---|
Unit |
add(element: E!)Adds |
Int |
count(element: E!)Returns the number of occurrences of an element in this multiset. |
(Mutable)Set<E!>! |
Returns a snapshot of the unique elements currently in this multiset. |
(Mutable)Iterator<E!>! |
iterator()Returns an iterator over a snapshot of all the elements currently in this multiset (including duplicates). |
Unit |
remove(element: E!)Removes |
Inherited functions |
||||
|---|---|---|---|---|
|
Public constructors
Public functions
add
fun add(element: E!): Unit
Adds element to the multiset.
| Parameters | |
|---|---|
element: E! |
The element to be added. |
elementSet
fun elementSet(): (Mutable)Set<E!>!
Returns a snapshot of the unique elements currently in this multiset.
Changes to the underlying multiset are not reflected in the returned value.