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 ofMapwhere 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 theListinterface, 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 classDynamicValueSortedTreeMap.EntryListIteratorAn iterator of the entriesprotected classDynamicValueSortedTreeMap.KeyListIteratorAn iterator of the keysprotected classDynamicValueSortedTreeMap.NodeAn entry in the map.protected classDynamicValueSortedTreeMap.ValueListIteratorAn iterator of the valuesclassDynamicValueSortedTreeMap.ValueSortedTreeMapEntrySetA public view of the map as a set of entries In addition toSet, this view implementsListandDeque, 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.classDynamicValueSortedTreeMap.ValueSortedTreeMapKeySetA public view of the map as a set of keys In addition toSet, this view implementsListandDeque, 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.classDynamicValueSortedTreeMap.ValueSortedTreeMapValuesA public view of the map as a list of values This view implementsListandDeque, 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 voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)DynamicValueSortedTreeMap.ValueSortedTreeMapEntrySetentrySet()protected static booleaneq(java.lang.Object o1, java.lang.Object o2)A convenience for null-safe comparisonVget(java.lang.Object key)booleanisEmpty()DynamicValueSortedTreeMap.ValueSortedTreeMapKeySetkeySet()Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> m)Vremove(java.lang.Object key)intsize()booleanupdate(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.ValueSortedTreeMapValuesvalues()
-
-
-
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:
entrySetin interfacejava.util.Map<K,V>- Specified by:
entrySetin 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:
keySetin interfacejava.util.Map<K,V>- Overrides:
keySetin 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:
valuesin interfacejava.util.Map<K,V>- Overrides:
valuesin classjava.util.AbstractMap<K,V>- See Also:
DynamicValueSortedTreeMap.ValueSortedTreeMapValues
-
-