/*
  Delay.h
  Contains the function prototypes for delay.c
  These are the loading/analyzing functions only.
  The user-interaction portions of the program go in delay_main.c
*/

#ifndef __DELAY_H
#define __DELAY_H

typedef struct _RC_Node_t
{
  struct _RC_Node_t * Parent_Ptr;
  struct _RC_Node_t * Left_Ptr;
  struct _RC_Node_t * Right_Ptr;

  /* Length of the wire to the parent node */
  double Length;

  /* X and Y coordinates, while defined in the file, are NEVER used, so we 
     won't even waste space on them */

  /***** Node transient variables *****/
  /* (stuff that our program computes that doesn't come from the file */

  /* Computed delay for this node */
  double Delay;

  /* Total capacitance of this node */
  /* Same units as G_Capacitance */
  double Capacitance;

  /* Total resistance value from the source to this element */
  /* Computed by RC_Compute_RC */
  /* See page 2 of the spec, near the bottom */
  /* Also see Note 1 in ALGORITHMS.txt */
  double Resistance;

  /* Total capacitance of this node + all its children */
  /* Computed by RC_Compute_RC */
  double Tree_Capacitance;

}
RC_Node_t;

/* Variables to hold information about the current loaded dataset */
extern double G_Resistance_Per_Length;    // ohm/um
extern double G_Capacitance_Per_Length;   // F/um
extern double G_Sink_Node_Capacitance;    // F
extern double G_Buffer_Output_Resistance; // ohm

extern int G_Sinkcount, G_Nodecount;

extern RC_Node_t * G_Root_Ptr;
extern RC_Node_t * G_Tree_Ptr;

/* This is subject to change */
/* Takes a file pointer as an argument */
/* Allocates G_Tree_Ptr to contain the array of nodes loaded from the file
   Also assigns G_Root_Ptr to point to the tree root
   Caller is responsible for freeing G_Tree_Ptr */
/* This builds the tree and fills in all non-timing-related information in
   the struct fields */
void RC_Load(FILE * Input);

/* Does the timing analysis */

/*Calls RC_Compute_RC and RC_Compute_Delay and finds the min and max
 * delay leaf nodes and prints out the delays.
 * Arguments: void
 */
void RC_Timing();

/* Recursively computes the resistance and capacitance to each node */
/* Arguments: Root pointer (needed since this function is recursive
              Resistance from src to parent node (0 for root node) */
/* Returns: Tree_Capacitance of Root_Ptr */
double RC_Compute_RC(RC_Node_t * Root_Ptr,
		     double Parent_Resistance);

/* Recursively computes the delay */
/* Arguments: Node pointer
              Parent contribution (to the C*R^2 term)
	      
*/
void RC_Compute_Delay(RC_Node_t * Root_Ptr,
		      double Parent_Contribution);

#endif // __DELAY_H
