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 Summary
Constructors -
Method Summary
Modifier 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
-
AvlTree
public AvlTree()
-
-
Method Details
-
get
public 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 treekey- the key for the node we are trying to findkeyComparator- 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.
-
getFirst
Return the first node of the tree.- Parameters:
root- the current root of the tree- Returns:
- the first (min) node of the tree
-
getLast
Return the last node of the tree.- Parameters:
root- the current root of the tree- Returns:
- the last (max) node of the tree
-
insert
Insert 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 treenode- the node to insert- Returns:
- the new root of the tree
-
insert
public 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 treekey- the key for the node we are trying to insertkeyComparator- the comparator to use to match node and keyinsertOrReplace- the class to use to insert or replace the node- Returns:
- the new root of the tree
-
removeMin
-
remove
public 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 treekey- the key for the node we are trying to findkeyComparator- the comparator to use to match node and key- Returns:
- the new root of the tree
-
remove
public 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 treekey- the key for the node we are trying to findkeyComparator- the comparator to use to match node and keyremoved- will be set to true if the node was found and removed, otherwise false- Returns:
- the new root of the tree
-
visit
public 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 treevisitor- the AvlNodeVisitor instance
-
balance
-
rotateRight
-
rotateLeft
-
fixHeight
-
height
-
balanceFactor
-