Package ghidra.generic.util.datastruct
Class DynamicValueSortedTreeMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- ghidra.generic.util.datastruct.DynamicValueSortedTreeMap<K,V>
-
- Type Parameters:
K
- the type of the keysV
- the type of the values
- All Implemented Interfaces:
java.util.Map<K,V>
public class DynamicValueSortedTreeMap<K,V> extends java.util.AbstractMap<K,V>
A map that is sorted by value. This is an implementation ofMap
where entries are sorted by value, rather than by key. Such a tree may be useful as a priority queue where the cost of an entry may change over time. As such, the collections returned byentrySet()
,keySet()
, andvalues()
all implementDeque
. The order of the entries will be updated on any call to {@link #put(Object, Object))}, or a call toCollection.add(Object)
on the entry set. Additionally, if the values are mutable objects, whose costs may change, there is anupdate(Object)
method, which notifies the map that the given key may need to be repositioned. The associated collections also implement theList
interface, providing fairly efficient implementations ofList.get(int)
andList.indexOf(Object)
. Sequential access is best performed viaCollection.iterator()
, since this will use a linked list. The underlying implementation is currently an unbalanced binary tree whose nodes also comprise a doubly-linked list. Currently, it is not thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DynamicValueSortedTreeMap.EntryListIterator
An iterator of the entriesprotected class
DynamicValueSortedTreeMap.KeyListIterator
An iterator of the keysprotected class
DynamicValueSortedTreeMap.Node
An entry in the map.protected class
DynamicValueSortedTreeMap.ValueListIterator
An iterator of the valuesclass
DynamicValueSortedTreeMap.ValueSortedTreeMapEntrySet
A public view of the map as a set of entries In addition toSet
, this view implementsList
andDeque
, since an ordered set ought to behave like a list, and since this implementation is meant to be used as a dynamic-cost priority queue.class
DynamicValueSortedTreeMap.ValueSortedTreeMapKeySet
A public view of the map as a set of keys In addition toSet
, this view implementsList
andDeque
, since an ordered set ought to behave like a list, and since this implementation is meant to be used as a dynamic-cost priority queue.class
DynamicValueSortedTreeMap.ValueSortedTreeMapValues
A public view of the map as a list of values This view implementsList
andDeque
, since an ordered collection ought to behave like a list, and since this implementation is meant to be used as a dynamic-cost priority queue.
-
Constructor Summary
Constructors Constructor Description DynamicValueSortedTreeMap()
Construct a dynamic value-sorted tree map using the values' natural ordering If the values do not have a natural ordering, you will eventually encounter aClassCastException
.DynamicValueSortedTreeMap(java.util.Comparator<V> comparator)
Construct a dynamic value-sorted tree map using a custom comparator to order the values
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
DynamicValueSortedTreeMap.ValueSortedTreeMapEntrySet
entrySet()
protected static boolean
eq(java.lang.Object o1, java.lang.Object o2)
A convenience for null-safe comparisonV
get(java.lang.Object key)
boolean
isEmpty()
DynamicValueSortedTreeMap.ValueSortedTreeMapKeySet
keySet()
V
put(K key, V value)
void
putAll(java.util.Map<? extends K,? extends V> m)
V
remove(java.lang.Object key)
int
size()
boolean
update(K key)
Notify the map of an external change to the cost of a key's associated value This is meant to update the entry's position after a change in cost.DynamicValueSortedTreeMap.ValueSortedTreeMapValues
values()
-
-
-
Constructor Detail
-
DynamicValueSortedTreeMap
public DynamicValueSortedTreeMap()
Construct a dynamic value-sorted tree map using the values' natural ordering If the values do not have a natural ordering, you will eventually encounter aClassCastException
. This condition is not checked at construction.
-
DynamicValueSortedTreeMap
public DynamicValueSortedTreeMap(java.util.Comparator<V> comparator)
Construct a dynamic value-sorted tree map using a custom comparator to order the values- Parameters:
comparator
- the comparator, providing a total ordering of the values
-
-
Method Detail
-
eq
protected static boolean eq(java.lang.Object o1, java.lang.Object o2)
A convenience for null-safe comparison
-
clear
public void clear()
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
entrySet
public DynamicValueSortedTreeMap.ValueSortedTreeMapEntrySet entrySet()
- Specified by:
entrySet
in interfacejava.util.Map<K,V>
- Specified by:
entrySet
in classjava.util.AbstractMap<K,V>
- See Also:
DynamicValueSortedTreeMap.ValueSortedTreeMapEntrySet
-
get
public V get(java.lang.Object key)
-
isEmpty
public boolean isEmpty()
-
keySet
public DynamicValueSortedTreeMap.ValueSortedTreeMapKeySet keySet()
- Specified by:
keySet
in interfacejava.util.Map<K,V>
- Overrides:
keySet
in classjava.util.AbstractMap<K,V>
- See Also:
DynamicValueSortedTreeMap.ValueSortedTreeMapKeySet
-
remove
public V remove(java.lang.Object key)
-
size
public int size()
-
update
public boolean update(K key)
Notify the map of an external change to the cost of a key's associated value This is meant to update the entry's position after a change in cost. The position may not necessarily change, however, if the cost did not change significantly.- Parameters:
key
- the key whose associated value has changed in cost- Returns:
- true if the entry's position changed
-
values
public DynamicValueSortedTreeMap.ValueSortedTreeMapValues values()
- Specified by:
values
in interfacejava.util.Map<K,V>
- Overrides:
values
in classjava.util.AbstractMap<K,V>
- See Also:
DynamicValueSortedTreeMap.ValueSortedTreeMapValues
-
-