/*
 * a chain is a list of links, which can be partitioned in various
 * ways.  Each partition has an associated cost which we can try
 * to compute
 *
 */

/*
 * a link is the unit for building chains and partitions.  It has
 * two associated double values, x and y, which may work as
 * coordinates for a vertex (vertexChain), dimensions of a matrix
 * (matrix chain), or a key and its frequency (bst chain).
 *
 */

struct link {
    double x, y;
};


/*
 * component: three integers specify a basic unit of a partition
 *
 */

struct component {
    int i, j, k;
};

/*
 * componentNode: single element of a linked list of components
 *
 */

struct componentNode {
    component value;
    componentNode *next;
    componentNode *tail;
};

const double doubleFudge= 0.000001; // for comparing doubles

class chain {
  public:

    /*
     * create a chain given an array of links, linkList, and the
     * size of this array, linkNum.
     *
     */

    chain(link *linkList, int linkNum);

    /*
     * minPartition: return a minimal partition of the range i..k
     * as a list of components.
     *
     */

    componentNode *minPartition(int i, int k);

    /*
     * partitionTally: return the sum of the costs of the components
     * of partitionList.
     *
     */

    double partitionTally(componentNode *partitionList);
};


/*
 * a chain of vertices is a polygon.  If it's a convex polygon
 * (something we don't check) then it can be triangulated, and
 * a minimal triangulation found, so long as there is a component
 * cost function defined for each triangle.
 *
 */

class vertexChain: public chain {

  public:

    vertexChain(link *linkList, int linkNum);

    componentNode *minPartition(int linkNum);
};


/*
 * matrixChain.h: public interface for matrix chains.
 *
 */

class matrixChain : public chain {
 
  public:

    matrixChain(link *linkList, int linkNum);

    componentNode *minPartition(int linkNum);
};

/*
 * bstChain.h
 * public interface for BST chains
 *
 */

class bstChain: public chain {

  public:

    bstChain(link *linkList, int linkNum);

    componentNode *minPartition(int linkNum);
};



