com.mhhe.clrs2e
Class Huffman.Node

java.lang.Object
  |
  +--com.mhhe.clrs2e.Huffman.Node
All Implemented Interfaces:
java.lang.Comparable, DynamicSetElement
Direct Known Subclasses:
Huffman.InternalNode, Huffman.PrefixCodeItem
Enclosing class:
Huffman

private static class Huffman.Node
extends java.lang.Object
implements DynamicSetElement

Inner class for a node in a Huffman tree.


Nested Class Summary
 
Nested classes inherited from class com.mhhe.clrs2e.DynamicSetElement
DynamicSetElement.Helper
 
Field Summary
private  double frequency
          The sum of the frequencies in all leaves of the subtree of which this node is the root.
 
Constructor Summary
Huffman.Node(double freq)
          Sets the frequency, based on the parameter.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this node to another, based on their frequencies.
 java.lang.Comparable getKey()
          Returns the frequency as the key.
 void setKey(java.lang.Comparable key)
          Cannot set the key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frequency

private final double frequency
The sum of the frequencies in all leaves of the subtree of which this node is the root.

Constructor Detail

Huffman.Node

public Huffman.Node(double freq)
Sets the frequency, based on the parameter.

Method Detail

setKey

public void setKey(java.lang.Comparable key)
Cannot set the key.

Specified by:
setKey in interface DynamicSetElement
Parameters:
key - The key, but it cannot be set.
Throws:
java.lang.UnsupportedOperationException - always.

getKey

public java.lang.Comparable getKey()
Returns the frequency as the key.

Specified by:
getKey in interface DynamicSetElement

compareTo

public int compareTo(java.lang.Object o)
Compares this node to another, based on their frequencies.

Specified by:
compareTo in interface DynamicSetElement
Parameters:
o - The other node.
Returns:
A negative integer if this node's frequency is less, 0 if the nodes have equal frequencies, or a positive integer if this node's frequency is greater.
Throws:
java.lang.ClassCastException - if o does not reference a Node object.