Algorithm
Development Kit 1.0

algs.model.tree
Class BalancedBinaryNode<K,V>

java.lang.Object
  extended by algs.model.tree.BalancedBinaryNode<K,V>
Type Parameters:
K - the base type of the keys stored by each node.
V - the base type of the values stored by the BinaryNode.
All Implemented Interfaces:
IGraphEntity
Direct Known Subclasses:
AugmentedNode

public class BalancedBinaryNode<K,V>
extends java.lang.Object
implements IGraphEntity

Standard node for an unbalanced binary tree.

Each node has a 'key' which is used to determine location of the node within the balanced binary tree. Each node also has a 'value' which can be anything else.

Use the mutator methods CAREFULLY!

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Nested Class Summary
 
Nested classes/interfaces inherited from interface algs.debug.IGraphEntity
IGraphEntity.Formatter
 
Field Summary
static boolean BLACK
          Value to use when node is a BLACK node.
protected  boolean color
          Color.
protected  BalancedBinaryNode<K,V> left
          Left son.
protected  BalancedBinaryNode<K,V> parent
          Parent.
static boolean RED
          Value to use when node is a RED node.
protected  BalancedBinaryNode<K,V> right
          Right son.
 
Constructor Summary
BalancedBinaryNode(K key, V value, BalancedBinaryNode<K,V> parent)
          Make a new node with given key, value, and parent, and with null child links, and BLACK color.
 
Method Summary
 boolean color()
          Get node color.
 void color(boolean color)
          Set node color.
 boolean equals(java.lang.Object o)
          Provide standard equals method.
 K key()
          Return the key for this node.
 BalancedBinaryNode<K,V> left()
          Return left son.
 void left(BalancedBinaryNode<K,V> newLeft)
          Set the left child.
 java.lang.String nodeLabel()
          Return string label for this entity.
 BalancedBinaryNode<K,V> parent()
          Get parent (needed for rotations and the like).
 void parent(BalancedBinaryNode<K,V> newParent)
          Set parent.
 BalancedBinaryNode<K,V> right()
          Return right son.
 void right(BalancedBinaryNode<K,V> newRight)
          Set the right child.
 V setValue(V value)
          Replaces the value currently associated with the key with the given value.
 java.lang.String toString()
          Return string representation of this node.
 V value()
          Return the value for this node.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

left

protected BalancedBinaryNode<K,V> left
Left son.


right

protected BalancedBinaryNode<K,V> right
Right son.


parent

protected BalancedBinaryNode<K,V> parent
Parent.


RED

public static final boolean RED
Value to use when node is a RED node.

See Also:
Constant Field Values

BLACK

public static final boolean BLACK
Value to use when node is a BLACK node.

See Also:
Constant Field Values

color

protected boolean color
Color.

Constructor Detail

BalancedBinaryNode

public BalancedBinaryNode(K key,
                          V value,
                          BalancedBinaryNode<K,V> parent)
Make a new node with given key, value, and parent, and with null child links, and BLACK color.

Parameters:
key -
value -
parent -
Method Detail

color

public void color(boolean color)
Set node color.

Parameters:
color - true for BLACK; false for RED.

color

public boolean color()
Get node color.


left

public BalancedBinaryNode<K,V> left()
Return left son.


right

public BalancedBinaryNode<K,V> right()
Return right son.


right

public void right(BalancedBinaryNode<K,V> newRight)
Set the right child.

Parameters:
newRight - new node to be right child.

left

public void left(BalancedBinaryNode<K,V> newLeft)
Set the left child.

Parameters:
newLeft - new node to be left child.

parent

public BalancedBinaryNode<K,V> parent()
Get parent (needed for rotations and the like).


parent

public void parent(BalancedBinaryNode<K,V> newParent)
Set parent.

Parameters:
newParent -

key

public K key()
Return the key for this node.


value

public V value()
Return the value for this node.


setValue

public V setValue(V value)
Replaces the value currently associated with the key with the given value.

Returns:
the value associated with the key before this method was called.

toString

public java.lang.String toString()
Return string representation of this node.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Provide standard equals method.

Overrides:
equals in class java.lang.Object

nodeLabel

public java.lang.String nodeLabel()
Description copied from interface: IGraphEntity
Return string label for this entity.

Specified by:
nodeLabel in interface IGraphEntity

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.