Package generic.stl
Class RedBlackTree<K,V>
- java.lang.Object
- 
- generic.stl.RedBlackTree<K,V>
 
- 
 public class RedBlackTree<K,V> extends java.lang.ObjectA RedBlack Tree implementation with K type keys and place to store V type values.
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringEOL
 - 
Constructor SummaryConstructors Constructor Description RedBlackTree(RedBlackTree<K,V> tree)Creates a copy of an existing RedBlackTreeRedBlackTree(java.util.Comparator<K> comparator, boolean allowDuplicateKeys)Creates a new RedBlackTree
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(K key)Returns true if the key is in the set.voiddeleteEntry(RedBlackNode<K,V> p)Delete node p, and then rebalance the tree.RedBlackNode<K,V>findFirstNode(K key)RedBlackNode<K,V>findLastNode(K key)RedBlackNode<K,V>getFirst()Returns the first entry in this set.RedBlackNode<K,V>getLast()Returns the last entry in this set.booleanisEmpty()Test if the set is empty.RedBlackNode<K,V>lowerBound(K key)Finds the node with the lowest key that is >= to the given key.Pair<RedBlackNode<K,V>,java.lang.Boolean>put(K key, V value)Adds the given key,value to the map.Vremove(K key)Removes the given key (first if duplicates are allowed) from the set.voidremoveAll()Removes all entrys from the set.intsize()Returns the number keys in this set.java.lang.StringtoString()RedBlackNode<K,V>upperBound(K key)Finds the node with the lowest key that is > the given key.
 
- 
- 
- 
Constructor Detail- 
RedBlackTreepublic RedBlackTree(java.util.Comparator<K> comparator, boolean allowDuplicateKeys) Creates a new RedBlackTree- Parameters:
- comparator- the comparator for this tree
- allowDuplicateKeys- true to allow duplicate keys
 
 - 
RedBlackTreepublic RedBlackTree(RedBlackTree<K,V> tree) Creates a copy of an existing RedBlackTree- Parameters:
- tree- the existing tree to copy
 
 
- 
 - 
Method Detail- 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
sizepublic int size() Returns the number keys in this set.
 - 
containsKeypublic boolean containsKey(K key) Returns true if the key is in the set.- Parameters:
- key- the key whose presence is to be tested.
 
 - 
getFirstpublic RedBlackNode<K,V> getFirst() Returns the first entry in this set.
 - 
getLastpublic RedBlackNode<K,V> getLast() Returns the last entry in this set.
 - 
lowerBoundpublic RedBlackNode<K,V> lowerBound(K key) Finds the node with the lowest key that is >= to the given key. Returns null if all nodes in the tree have keys less than the given key.- Parameters:
- key- the key to search for.
- Returns:
- the node with the lowest key that is >= to the given key or null if no such key exists.
 
 - 
upperBoundpublic RedBlackNode<K,V> upperBound(K key) Finds the node with the lowest key that is > the given key. Returns null if all nodes in the tree have keys less than or equal to the given key.- Parameters:
- key- the key to search for.
- Returns:
- the node with the lowest key that is > to the given key or null if no such key exists.
 
 - 
putpublic Pair<RedBlackNode<K,V>,java.lang.Boolean> put(K key, V value) 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.
- value- the key's value.
- Returns:
- the old value associated with the key, or null if the key was not previously in the map.
 
 - 
findFirstNodepublic RedBlackNode<K,V> findFirstNode(K key) 
 - 
findLastNodepublic RedBlackNode<K,V> findLastNode(K key) 
 - 
removepublic V remove(K key) 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.
 
 - 
removeAllpublic void removeAll() Removes all entrys from the set.
 - 
isEmptypublic boolean isEmpty() Test if the set is empty.- Returns:
- true if the set is empty.
 
 - 
deleteEntrypublic void deleteEntry(RedBlackNode<K,V> p) Delete node p, and then rebalance the tree.
 
- 
 
-