Package ghidra.util
Class DynamicSortedTreeSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- ghidra.util.DynamicSortedTreeSet<E>
-
- Type Parameters:
E- the type of the elements
- All Implemented Interfaces:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.Deque<E>,java.util.List<E>,java.util.Queue<E>,java.util.Set<E>
public class DynamicSortedTreeSet<E> extends java.util.AbstractSet<E> implements java.util.List<E>, java.util.Deque<E>A set where the ordering of elements may change over time, based on an alternative comparator This is an implementation ofSetwhere 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 theupdate(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 theListandDequeinterfaces. Since the set is ordered, it makes sense to treat it as a list. It provides fairly efficient implementations ofget(int)andindexOf(Object). Sequential access is best performed viaiterator(), since this will use a linked list. The underlying implementation is backed byDynamicValueSortedTreeMap. Currently, it is not thread safe.
-
-
Constructor Summary
Constructors Constructor Description DynamicSortedTreeSet()Construct a dynamic sorted tree set using the elements' natural ordering Other than, perhaps, a more convenient interface, this offers few if any benefits over the stockSet.DynamicSortedTreeSet(java.util.Comparator<E> comparator)Construct a dynamic sorted tree set using a custom comparator to order the elements
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)Inserts the element, ignoring indexbooleanadd(E e)booleanaddAll(int index, java.util.Collection<? extends E> c)Inserts all elements from the given collection, ignoring indexvoidaddFirst(E e)Inserts the element, not necessarily firstvoidaddLast(E e)Inserts the element, not necessarily lastvoidclear()booleancontains(java.lang.Object o)java.util.Iterator<E>descendingIterator()Eelement()Eget(int index)EgetFirst()EgetLast()intindexOf(java.lang.Object o)booleanisEmpty()java.util.Iterator<E>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<E>listIterator()java.util.ListIterator<E>listIterator(int index)booleanoffer(E e)booleanofferFirst(E e)Inserts the element, not necessarily firstbooleanofferLast(E e)Inserts the element, not necessarily lastEpeek()EpeekFirst()EpeekLast()Epoll()EpollFirst()EpollLast()Epop()voidpush(E e)Eremove()Eremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)EremoveFirst()booleanremoveFirstOccurrence(java.lang.Object o)EremoveLast()booleanremoveLastOccurrence(java.lang.Object o)booleanretainAll(java.util.Collection<?> c)Eset(int index, E element)Replace the element at the given index with the given element Because the set is sorted, the index of the given element may not be the same asindex.intsize()java.util.Spliterator<E>spliterator()java.util.List<E>subList(int fromIndex, int toIndex)This operation is not supportedbooleanupdate(E e)Notify the queue of a change to an elements cost.-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
DynamicSortedTreeSet
public DynamicSortedTreeSet()
Construct a dynamic sorted tree set using the elements' natural ordering Other than, perhaps, a more convenient interface, this offers few if any benefits over the stockSet.
-
DynamicSortedTreeSet
public DynamicSortedTreeSet(java.util.Comparator<E> comparator)
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 Detail
-
add
public boolean add(E e)
- Specified by:
addin interfacejava.util.Collection<E>- Specified by:
addin interfacejava.util.Deque<E>- Specified by:
addin interfacejava.util.List<E>- Specified by:
addin interfacejava.util.Queue<E>- Specified by:
addin interfacejava.util.Set<E>- Overrides:
addin classjava.util.AbstractCollection<E>
-
add
public void add(int index, E element)Inserts the element, ignoring index- Specified by:
addin interfacejava.util.List<E>- Parameters:
index- ignore since the set is sorted
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)Inserts all elements from the given collection, ignoring index- Specified by:
addAllin interfacejava.util.List<E>- Parameters:
index- ignore since the set is sorted
-
addFirst
public void addFirst(E e)
Inserts the element, not necessarily first- Specified by:
addFirstin interfacejava.util.Deque<E>
-
addLast
public void addLast(E e)
Inserts the element, not necessarily last- Specified by:
addLastin interfacejava.util.Deque<E>
-
clear
public void clear()
-
contains
public boolean contains(java.lang.Object o)
-
descendingIterator
public java.util.Iterator<E> descendingIterator()
- Specified by:
descendingIteratorin interfacejava.util.Deque<E>
-
element
public E element()
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfacejava.util.List<E>
-
isEmpty
public boolean isEmpty()
-
iterator
public java.util.Iterator<E> iterator()
- Specified by:
iteratorin interfacejava.util.Collection<E>- Specified by:
iteratorin interfacejava.util.Deque<E>- Specified by:
iteratorin interfacejava.lang.Iterable<E>- Specified by:
iteratorin interfacejava.util.List<E>- Specified by:
iteratorin interfacejava.util.Set<E>- Specified by:
iteratorin classjava.util.AbstractCollection<E>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<E>
-
offer
public boolean offer(E e)
-
offerFirst
public boolean offerFirst(E e)
Inserts the element, not necessarily first- Specified by:
offerFirstin interfacejava.util.Deque<E>
-
offerLast
public boolean offerLast(E e)
Inserts the element, not necessarily last- Specified by:
offerLastin interfacejava.util.Deque<E>
-
peek
public E peek()
-
poll
public E poll()
-
remove
public E remove()
-
remove
public boolean remove(java.lang.Object o)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
removeFirstOccurrence
public boolean removeFirstOccurrence(java.lang.Object o)
- Specified by:
removeFirstOccurrencein interfacejava.util.Deque<E>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object o)
- Specified by:
removeLastOccurrencein interfacejava.util.Deque<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
set
public E set(int index, E element)
Replace the element at the given index with the given element Because the set is sorted, the index of the given element may not be the same asindex. In fact, this is equivalent to removing the element at the given index, and then inserting the given element at its sorted position.- Specified by:
setin interfacejava.util.List<E>
-
size
public int size()
-
spliterator
public java.util.Spliterator<E> spliterator()
-
subList
public java.util.List<E> subList(int fromIndex, int toIndex)
This operation is not supported- Specified by:
subListin interfacejava.util.List<E>
-
update
public boolean update(E e)
Notify the queue of a change to an elements 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
-
-