Package ghidra.util

Class 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 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 DynamicValueSortedTreeMap. 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 stock Set.
      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 index
      boolean add​(E e)  
      boolean addAll​(int index, java.util.Collection<? extends E> c)
      Inserts all elements from the given collection, ignoring index
      void addFirst​(E e)
      Inserts the element, not necessarily first
      void addLast​(E e)
      Inserts the element, not necessarily last
      void 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 first
      boolean offerLast​(E e)
      Inserts the element, not necessarily last
      E 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 as index.
      int size()  
      java.util.Spliterator<E> spliterator()  
      java.util.List<E> subList​(int fromIndex, int toIndex)
      This operation is not supported
      boolean update​(E e)
      Notify the queue of a change to an elements cost.
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode
      • 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
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.util.Deque

        addAll
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, containsAll, equals, hashCode, replaceAll, sort, toArray, toArray
      • Methods inherited from interface java.util.Set

        addAll, containsAll, toArray, toArray
    • 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 stock Set.
      • 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 interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Deque<E>
        Specified by:
        add in interface java.util.List<E>
        Specified by:
        add in interface java.util.Queue<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
      • add

        public void add​(int index,
                        E element)
        Inserts the element, ignoring index
        Specified by:
        add in interface java.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 interface java.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 interface java.util.Deque<E>
      • addLast

        public void addLast​(E e)
        Inserts the element, not necessarily last
        Specified by:
        addLast in interface java.util.Deque<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
        Specified by:
        clear in interface java.util.Set<E>
        Overrides:
        clear in class java.util.AbstractCollection<E>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Deque<E>
        Specified by:
        contains in interface java.util.List<E>
        Specified by:
        contains in interface java.util.Set<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
      • descendingIterator

        public java.util.Iterator<E> descendingIterator()
        Specified by:
        descendingIterator in interface java.util.Deque<E>
      • element

        public E element()
        Specified by:
        element in interface java.util.Deque<E>
        Specified by:
        element in interface java.util.Queue<E>
      • get

        public E get​(int index)
        Specified by:
        get in interface java.util.List<E>
      • getFirst

        public E getFirst()
        Specified by:
        getFirst in interface java.util.Deque<E>
      • getLast

        public E getLast()
        Specified by:
        getLast in interface java.util.Deque<E>
      • indexOf

        public int indexOf​(java.lang.Object o)
        Specified by:
        indexOf in interface java.util.List<E>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.List<E>
        Specified by:
        isEmpty in interface java.util.Set<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.util.Deque<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object o)
        Specified by:
        lastIndexOf in interface java.util.List<E>
      • listIterator

        public java.util.ListIterator<E> listIterator()
        Specified by:
        listIterator in interface java.util.List<E>
      • listIterator

        public java.util.ListIterator<E> listIterator​(int index)
        Specified by:
        listIterator in interface java.util.List<E>
      • offer

        public boolean offer​(E e)
        Specified by:
        offer in interface java.util.Deque<E>
        Specified by:
        offer in interface java.util.Queue<E>
      • offerFirst

        public boolean offerFirst​(E e)
        Inserts the element, not necessarily first
        Specified by:
        offerFirst in interface java.util.Deque<E>
      • offerLast

        public boolean offerLast​(E e)
        Inserts the element, not necessarily last
        Specified by:
        offerLast in interface java.util.Deque<E>
      • peek

        public E peek()
        Specified by:
        peek in interface java.util.Deque<E>
        Specified by:
        peek in interface java.util.Queue<E>
      • peekFirst

        public E peekFirst()
        Specified by:
        peekFirst in interface java.util.Deque<E>
      • peekLast

        public E peekLast()
        Specified by:
        peekLast in interface java.util.Deque<E>
      • poll

        public E poll()
        Specified by:
        poll in interface java.util.Deque<E>
        Specified by:
        poll in interface java.util.Queue<E>
      • pollFirst

        public E pollFirst()
        Specified by:
        pollFirst in interface java.util.Deque<E>
      • pollLast

        public E pollLast()
        Specified by:
        pollLast in interface java.util.Deque<E>
      • pop

        public E pop()
        Specified by:
        pop in interface java.util.Deque<E>
      • push

        public void push​(E e)
        Specified by:
        push in interface java.util.Deque<E>
      • remove

        public E remove()
        Specified by:
        remove in interface java.util.Deque<E>
        Specified by:
        remove in interface java.util.Queue<E>
      • remove

        public E remove​(int index)
        Specified by:
        remove in interface java.util.List<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Deque<E>
        Specified by:
        remove in interface java.util.List<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.List<E>
        Specified by:
        removeAll in interface java.util.Set<E>
        Overrides:
        removeAll in class java.util.AbstractSet<E>
      • removeFirst

        public E removeFirst()
        Specified by:
        removeFirst in interface java.util.Deque<E>
      • removeFirstOccurrence

        public boolean removeFirstOccurrence​(java.lang.Object o)
        Specified by:
        removeFirstOccurrence in interface java.util.Deque<E>
      • removeLast

        public E removeLast()
        Specified by:
        removeLast in interface java.util.Deque<E>
      • removeLastOccurrence

        public boolean removeLastOccurrence​(java.lang.Object o)
        Specified by:
        removeLastOccurrence in interface java.util.Deque<E>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.List<E>
        Specified by:
        retainAll in interface java.util.Set<E>
        Overrides:
        retainAll in class java.util.AbstractCollection<E>
      • 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 as index. 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 interface java.util.List<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Deque<E>
        Specified by:
        size in interface java.util.List<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • spliterator

        public java.util.Spliterator<E> spliterator()
        Specified by:
        spliterator in interface java.util.Collection<E>
        Specified by:
        spliterator in interface java.lang.Iterable<E>
        Specified by:
        spliterator in interface java.util.List<E>
        Specified by:
        spliterator in interface java.util.Set<E>
      • subList

        public java.util.List<E> subList​(int fromIndex,
                                         int toIndex)
        This operation is not supported
        Specified by:
        subList in interface java.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