edu.princeton.cs.algs4.growingtree.experiments
Class ExperimentTree<P extends NodeProperties>

java.lang.Object
  extended by edu.princeton.cs.algs4.growingtree.experiments.ExperimentTree<P>
All Implemented Interfaces:
IExperimentLogger<P>

public class ExperimentTree<P extends NodeProperties>
extends java.lang.Object
implements IExperimentLogger<P>

This wraps around the actual tree, keeping track of the root, and passing along calls between the API and the tree (e.g. logging, insertion). It should not be instantiated by the client.

Author:
Josh Israel

Field Summary
 
Fields inherited from interface edu.princeton.cs.algs4.growingtree.experiments.IExperimentLogger
HEIGHT_UPDATE, SIZE_UPDATE
 
Constructor Summary
ExperimentTree(java.lang.String name, P p, IInsertOperator<P> inserter, ISearchOperator<P> searcher, IDeleteOperator<P> deleter, IExperimentLogger<P> logger)
           
 
Method Summary
 void delete(java.lang.Double key)
          Deletes a node from the tree
 void insert(java.lang.Double key)
          Insert a node into the tree
 void logDeletion(ShadowNode<P> n)
          Called on IDeletingNode.predecessorHibbardDelete and IDeletingNode.successorHibbardDelete PRIOR to the actual deletion.
 void logInsertion(ShadowNode<P> n)
          Called on IInsertNode.insertLeft and IInsertNode.insertRight
 void logOther(IAlgorithmNode<P> n, int event_id)
          Catch-all logging function for anything missed by the others.
 void logRotation(ShadowNode<P> n)
          Called on IAlgorithmNode.rotateLeft and IAlgorithmNode.rotateRight PRIOR to the actual rotation.
 void logSearchHit(ShadowNode<P> n)
          Called on ISearchingNode.markFound
 void search(java.lang.Double key)
          Perform a search for an element
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExperimentTree

public ExperimentTree(java.lang.String name,
                      P p,
                      IInsertOperator<P> inserter,
                      ISearchOperator<P> searcher,
                      IDeleteOperator<P> deleter,
                      IExperimentLogger<P> logger)
Parameters:
name - Name of the tree to be created
p - Instance of the proper NodeProperties subclass
inserter - The IInsertOperator to be used for this tree
searcher - The ISearchOperator to be used for this tree
deleter - The IDeleteOperator to be used for this tree
logger - The IExperimentLogger to be used for this tree. This will receive callbacks from the tree when operations occur.
Method Detail

insert

public void insert(java.lang.Double key)
Insert a node into the tree

Parameters:
key - Key of the node to be inserted

search

public void search(java.lang.Double key)
Perform a search for an element

Parameters:
key - Key of node to be sought

delete

public void delete(java.lang.Double key)
Deletes a node from the tree

Parameters:
key - Key of node to be deleted

logInsertion

public void logInsertion(ShadowNode<P> n)
Description copied from interface: IExperimentLogger
Called on IInsertNode.insertLeft and IInsertNode.insertRight

Specified by:
logInsertion in interface IExperimentLogger<P extends NodeProperties>
Parameters:
n - Node that was just inserted

logRotation

public void logRotation(ShadowNode<P> n)
Description copied from interface: IExperimentLogger
Called on IAlgorithmNode.rotateLeft and IAlgorithmNode.rotateRight PRIOR to the actual rotation.

Specified by:
logRotation in interface IExperimentLogger<P extends NodeProperties>
Parameters:
n - Node is being rotated down the tree

logDeletion

public void logDeletion(ShadowNode<P> n)
Description copied from interface: IExperimentLogger
Called on IDeletingNode.predecessorHibbardDelete and IDeletingNode.successorHibbardDelete PRIOR to the actual deletion.

Specified by:
logDeletion in interface IExperimentLogger<P extends NodeProperties>
Parameters:
n - Node being deleted

logSearchHit

public void logSearchHit(ShadowNode<P> n)
Description copied from interface: IExperimentLogger
Called on ISearchingNode.markFound

Specified by:
logSearchHit in interface IExperimentLogger<P extends NodeProperties>
Parameters:
n - Node that has been found

logOther

public void logOther(IAlgorithmNode<P> n,
                     int event_id)
Description copied from interface: IExperimentLogger
Catch-all logging function for anything missed by the others. Meant in part to be used by an actual operator if necessary.

Specified by:
logOther in interface IExperimentLogger<P extends NodeProperties>
Parameters:
n - Node being logged
event_id - Used to identify the event this call represents