ConcurrentSkipListSet

public class ConcurrentSkipListSet extends AbstractSet<E>
implements NavigableSet<E> Cloneable Serializable

A scalable concurrent NavigableSet implementation based on a ConcurrentSkipListMap. The elements of the set are kept sorted according to their {@linkplain Comparable natural ordering}, or by a Comparator provided at set creation time, depending on which constructor is used.

This implementation provides expected average log(n) time cost for the contains, add, and remove operations and their variants. Insertion, removal, and access operations safely execute concurrently by multiple threads.

Iterators and spliterators are weakly consistent.

Ascending ordered views and their iterators are faster than descending ones.

Beware that, unlike in most collections, the size method is not a constant-time operation. Because of the asynchronous nature of these sets, determining the current number of elements requires a traversal of the elements, and so may report inaccurate results if this collection is modified during traversal. Additionally, the bulk operations addAll, removeAll, retainAll, containsAll, equals, and toArray are not guaranteed to be performed atomically. For example, an iterator operating concurrently with an addAll operation might view only some of the added elements.

This class and its iterators implement all of the optional methods of the Set and Iterator interfaces. Like most other concurrent collection implementations, this class does not permit the use of null elements, because null arguments and return values cannot be reliably distinguished from the absence of elements.

Public Constructor Summary

ConcurrentSkipListSet()
Constructs a new, empty set that orders its elements according to their {@linkplain Comparable natural ordering}.
ConcurrentSkipListSet(Comparator<? super E> comparator)
Constructs a new, empty set that orders its elements according to the specified comparator.
ConcurrentSkipListSet(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection, that orders its elements according to their {@linkplain Comparable natural ordering}.
ConcurrentSkipListSet(SortedSet<E> s)
Constructs a new set containing the same elements and using the same ordering as the specified sorted set.

Public Method Summary

boolean
add(E e)
Adds the specified element to this set if it is not already present.
E
ceiling(E e)
Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
void
clear()
Removes all of the elements from this set.
ConcurrentSkipListSet<E>
clone()
Returns a shallow copy of this ConcurrentSkipListSet instance.
Comparator<? super E>
comparator()
Returns the comparator used to order the elements in this set, or null if this set uses the {@linkplain Comparable natural ordering} of its elements.
boolean
contains(Object o)
Returns true if this set contains the specified element.
Iterator<E>
descendingIterator()
Returns an iterator over the elements in this set in descending order.
NavigableSet<E>
descendingSet()
Returns a reverse order view of the elements contained in this set.
boolean
equals(Object o)
Compares the specified object with this set for equality.
E
first()
Returns the first (lowest) element currently in this set.
E
floor(E e)
Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.
NavigableSet<E>
headSet(E toElement, boolean inclusive)
Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.
NavigableSet<E>
headSet(E toElement)
Returns a view of the portion of this set whose elements are strictly less than toElement.

Equivalent to headSet(toElement, false).

E
higher(E e)
Returns the least element in this set strictly greater than the given element, or null if there is no such element.
boolean
isEmpty()
Returns true if this set contains no elements.
Iterator<E>
iterator()
Returns an iterator over the elements in this set in ascending order.
E
last()
Returns the last (highest) element currently in this set.
E
lower(E e)
Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
E
pollFirst()
Retrieves and removes the first (lowest) element, or returns null if this set is empty.
E
pollLast()
Retrieves and removes the last (highest) element, or returns null if this set is empty.
boolean
remove(Object o)
Removes the specified element from this set if it is present.
boolean
removeAll(Collection<?> c)
Removes from this set all of its elements that are contained in the specified collection.
int
size()
Returns the number of elements in this set.
Spliterator<E>
spliterator()
Returns a Spliterator over the elements in this set.
NavigableSet<E>
subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
Returns a view of the portion of this set whose elements range from fromElement to toElement.
NavigableSet<E>
subSet(E fromElement, E toElement)
Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.

Equivalent to subSet(fromElement, true, toElement, false).

NavigableSet<E>
tailSet(E fromElement, boolean inclusive)
Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.
NavigableSet<E>
tailSet(E fromElement)
Returns a view of the portion of this set whose elements are greater than or equal to fromElement.

Equivalent to tailSet(fromElement, true).

Inherited Method Summary