Package org.apache.hadoop.hbase.util
Class AvlUtil.AvlTree
java.lang.Object
org.apache.hadoop.hbase.util.AvlUtil.AvlTree
- Enclosing class:
- AvlUtil
Helper class that allows to create and manipulate an AVL Tree
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprivate static <TNode extends AvlUtil.AvlNode>
 TNodebalance(TNode p) private static <TNode extends AvlUtil.AvlNode>
 intbalanceFactor(TNode node) private static <TNode extends AvlUtil.AvlNode>
 voidfixHeight(TNode node) static <TNode extends AvlUtil.AvlNode>
 TNodeget(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator) Return the node that matches the specified key or null in case of node not found.static <TNode extends AvlUtil.AvlNode>
 TNodegetFirst(TNode root) Return the first node of the tree.static <TNode extends AvlUtil.AvlNode>
 TNodegetLast(TNode root) Return the last node of the tree.private static <TNode extends AvlUtil.AvlNode>
 intheight(TNode node) static <TNode extends AvlUtil.AvlNode>
 TNodeinsert(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator, AvlUtil.AvlInsertOrReplace<TNode> insertOrReplace) Insert a node into the tree.static <TNode extends AvlUtil.AvlNode>
 TNodeinsert(TNode root, TNode node) Insert a node into the tree.static <TNode extends AvlUtil.AvlNode>
 TNoderemove(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator) Removes the node matching the specified key from the treestatic <TNode extends AvlUtil.AvlNode>
 TNoderemove(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator, AtomicBoolean removed) Removes the node matching the specified key from the treeprivate static <TNode extends AvlUtil.AvlNode>
 TNoderemoveMin(TNode p) private static <TNode extends AvlUtil.AvlNode>
 TNoderotateLeft(TNode q) private static <TNode extends AvlUtil.AvlNode>
 TNoderotateRight(TNode p) static <TNode extends AvlUtil.AvlNode>
 voidvisit(TNode root, AvlUtil.AvlNodeVisitor<TNode> visitor) Visit each node of the tree
- 
Constructor Details- 
AvlTreepublic AvlTree()
 
- 
- 
Method Details- 
getpublic static <TNode extends AvlUtil.AvlNode> TNode get(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator) Return the node that matches the specified key or null in case of node not found.- Parameters:
- root- the current root of the tree
- key- the key for the node we are trying to find
- keyComparator- the comparator to use to match node and key
- Returns:
- the node that matches the specified key or null in case of node not found.
 
- 
getFirstReturn the first node of the tree.- Parameters:
- root- the current root of the tree
- Returns:
- the first (min) node of the tree
 
- 
getLastReturn the last node of the tree.- Parameters:
- root- the current root of the tree
- Returns:
- the last (max) node of the tree
 
- 
insertInsert a node into the tree. It uses the AvlNode.compareTo() for ordering. NOTE: The node must not be already in the tree.- Parameters:
- root- the current root of the tree
- node- the node to insert
- Returns:
- the new root of the tree
 
- 
insertpublic static <TNode extends AvlUtil.AvlNode> TNode insert(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator, AvlUtil.AvlInsertOrReplace<TNode> insertOrReplace) Insert a node into the tree. This is useful when you want to create a new node or replace the content depending if the node already exists or not. Using AvlInsertOrReplace class you can return the node to add/replace.- Parameters:
- root- the current root of the tree
- key- the key for the node we are trying to insert
- keyComparator- the comparator to use to match node and key
- insertOrReplace- the class to use to insert or replace the node
- Returns:
- the new root of the tree
 
- 
removeMin
- 
removepublic static <TNode extends AvlUtil.AvlNode> TNode remove(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator) Removes the node matching the specified key from the tree- Parameters:
- root- the current root of the tree
- key- the key for the node we are trying to find
- keyComparator- the comparator to use to match node and key
- Returns:
- the new root of the tree
 
- 
removepublic static <TNode extends AvlUtil.AvlNode> TNode remove(TNode root, Object key, AvlUtil.AvlKeyComparator<TNode> keyComparator, AtomicBoolean removed) Removes the node matching the specified key from the tree- Parameters:
- root- the current root of the tree
- key- the key for the node we are trying to find
- keyComparator- the comparator to use to match node and key
- removed- will be set to true if the node was found and removed, otherwise false
- Returns:
- the new root of the tree
 
- 
visitpublic static <TNode extends AvlUtil.AvlNode> void visit(TNode root, AvlUtil.AvlNodeVisitor<TNode> visitor) Visit each node of the tree- Parameters:
- root- the current root of the tree
- visitor- the AvlNodeVisitor instance
 
- 
balance
- 
rotateRight
- 
rotateLeft
- 
fixHeight
- 
height
- 
balanceFactor
 
-