Package ghidra.util.datastruct
Class RedBlackTree<K extends Comparable<K>,V>
java.lang.Object
ghidra.util.datastruct.RedBlackTree<K,V>
- All Implemented Interfaces:
Iterable<RedBlackEntry<K,
V>>
public class RedBlackTree<K extends Comparable<K>,V>
extends Object
implements Iterable<RedBlackEntry<K,V>>
A RedBlack Tree implementation with K type keys and place to store V type values.
-
Constructor Summary
ConstructorDescriptionCreates a new RedBlackKeySet that can store keys between 0 and n. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(K key) Returns true if the key is in the set.void
deleteEntry
(RedBlackEntry<K, V> p) Delete node p, and then rebalance the tree.Returns the node with largest key in the set that is less or equal to the given key.getEntryLessThanEqual
(K key) Returns the node with largest key in the set that is less or equal to the given key.getFirst()
Returns the first entry in this set.getLast()
Returns the last entry in this set.getOrCreateEntry
(K key) boolean
isEmpty()
Test if the set is empty.iterator()
iterator
(boolean forward) iterator
(RedBlackEntry<K, V> firstEntry, boolean forward) Adds the given key,value to the map.Removes the given key (first if duplicates are allowed) from the set.void
Removes all entries from the set.void
removeNode
(RedBlackEntry<K, V> node) int
size()
Returns the number keys in this set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
RedBlackTree
public RedBlackTree()Creates a new RedBlackKeySet that can store keys between 0 and n.
-
-
Method Details
-
size
public int size()Returns the number keys in this set. -
containsKey
Returns true if the key is in the set.- Parameters:
key
- the key whose presence is to be tested.
-
getFirst
Returns the first entry in this set. -
getLast
Returns the last entry in this set. -
getEntryLessThanEqual
Returns the node with largest key in the set that is less or equal to the given key. Returns null if there are no keys less than or equal to the given key.- Parameters:
key
- the search key
-
getEntryGreaterThanEqual
Returns the node with largest key in the set that is less or equal to the given key. Returns null if there are no keys less than or equal to the given key.- Parameters:
key
- the search key
-
put
Adds the given key,value to the map. If the map does not allow duplicate keys and a key already exists, the old value will be replaced by the new value and the old value will be returned.- Parameters:
key
- the key to add to the set.- Returns:
- the old value associated with the key, or null if the key was not previously in the map.
-
getOrCreateEntry
-
getEntry
-
remove
Removes the given key (first if duplicates are allowed) from the set.- Parameters:
key
- the key to remove from the set.- Returns:
- the value associated with the key removed or null if the key not found.
-
removeNode
-
removeAll
public void removeAll()Removes all entries from the set. -
isEmpty
public boolean isEmpty()Test if the set is empty.- Returns:
- true if the set is empty.
-
iterator
- Specified by:
iterator
in interfaceIterable<K extends Comparable<K>>
-
iterator
-
iterator
-
iterator
-
deleteEntry
Delete node p, and then rebalance the tree.
-