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 ofSet
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 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 theList
andDeque
interfaces. 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 void
add(int index, E element)
Inserts the element, ignoring indexboolean
add(E e)
boolean
addAll(int index, java.util.Collection<? extends E> c)
Inserts all elements from the given collection, ignoring indexvoid
addFirst(E e)
Inserts the element, not necessarily firstvoid
addLast(E e)
Inserts the element, not necessarily lastvoid
clear()
boolean
contains(java.lang.Object o)
java.util.Iterator<E>
descendingIterator()
E
element()
E
get(int index)
E
getFirst()
E
getLast()
int
indexOf(java.lang.Object o)
boolean
isEmpty()
java.util.Iterator<E>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<E>
listIterator()
java.util.ListIterator<E>
listIterator(int index)
boolean
offer(E e)
boolean
offerFirst(E e)
Inserts the element, not necessarily firstboolean
offerLast(E e)
Inserts the element, not necessarily lastE
peek()
E
peekFirst()
E
peekLast()
E
poll()
E
pollFirst()
E
pollLast()
E
pop()
void
push(E e)
E
remove()
E
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
E
removeFirst()
boolean
removeFirstOccurrence(java.lang.Object o)
E
removeLast()
boolean
removeLastOccurrence(java.lang.Object o)
boolean
retainAll(java.util.Collection<?> c)
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
.int
size()
java.util.Spliterator<E>
spliterator()
java.util.List<E>
subList(int fromIndex, int toIndex)
This operation is not supportedboolean
update(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:
add
in interfacejava.util.Collection<E>
- Specified by:
add
in interfacejava.util.Deque<E>
- Specified by:
add
in interfacejava.util.List<E>
- Specified by:
add
in interfacejava.util.Queue<E>
- Specified by:
add
in interfacejava.util.Set<E>
- Overrides:
add
in classjava.util.AbstractCollection<E>
-
add
public void add(int index, E element)
Inserts the element, ignoring index- Specified by:
add
in 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:
addAll
in 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:
addFirst
in interfacejava.util.Deque<E>
-
addLast
public void addLast(E e)
Inserts the element, not necessarily last- Specified by:
addLast
in 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:
descendingIterator
in interfacejava.util.Deque<E>
-
element
public E element()
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOf
in interfacejava.util.List<E>
-
isEmpty
public boolean isEmpty()
-
iterator
public java.util.Iterator<E> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<E>
- Specified by:
iterator
in interfacejava.util.Deque<E>
- Specified by:
iterator
in interfacejava.lang.Iterable<E>
- Specified by:
iterator
in interfacejava.util.List<E>
- Specified by:
iterator
in interfacejava.util.Set<E>
- Specified by:
iterator
in classjava.util.AbstractCollection<E>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<E>
-
offer
public boolean offer(E e)
-
offerFirst
public boolean offerFirst(E e)
Inserts the element, not necessarily first- Specified by:
offerFirst
in interfacejava.util.Deque<E>
-
offerLast
public boolean offerLast(E e)
Inserts the element, not necessarily last- Specified by:
offerLast
in 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:
removeFirstOccurrence
in interfacejava.util.Deque<E>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object o)
- Specified by:
removeLastOccurrence
in 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:
set
in 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:
subList
in 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
-
-