Class DynamicSortedTreeSet<E>
- Type Parameters:
E- the type of the elements
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
This is an implementation of Set where elements may be sorted by an alternative
comparator (usually by "cost"), rather than by the natural ordering. It may seem odd, but the
natural ordering is still used to determine the uniqueness of keys. That is, two elements that
are unequal -- but are considered equal by the alternative comparator -- may co-exist in the set.
(Note: in such cases, the two elements are ordered first-in first-out). Additionally, if the
elements are mutable, then their ordering may change over time. This mode of operation is enabled
by the update(Object) method, which must be called to notify the set of any change to an
element that may affect its order. This set also implements the List and Deque
interfaces. Since the set is ordered, it makes sense to treat it as a list. It provides fairly
efficient implementations of get(int) and indexOf(Object). Sequential access is
best performed via iterator(), since this will use a linked list.
The underlying implementation is backed by TreeValueSortedMap. Currently, it is not
thread safe.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a dynamic sorted tree set using the elements' natural orderingDynamicSortedTreeSet(Comparator<E> comparator) Construct a dynamic sorted tree set using a custom comparator to order the elements -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidclear()booleanget(int index) intbooleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()booleanNotify the queue of a change to an element's cost.Methods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.util.AbstractCollection
addAll, containsAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, toArray, toArray
-
Constructor Details
-
DynamicSortedTreeSet
public DynamicSortedTreeSet()Construct a dynamic sorted tree set using the elements' natural orderingOther than, perhaps, a more convenient interface, this offers few if any benefits over the stock
Set. -
DynamicSortedTreeSet
Construct a dynamic sorted tree set using a custom comparator to order the elements- Parameters:
comparator- the comparator, providing a total ordering of the values
-
-
Method Details
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
get
-
indexOf
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
iterator
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractSet<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
spliterator
-
update
Notify the queue of a change to an element's cost.This may cause the element's index to change.
- Parameters:
e- the element whose cost may have changed- Returns:
- true if the index changed
-