/********************************************************
                  types.h
********************************************************/

#define MAXSIZE 100   /* Size of hash table */
#define MAXNUM  10    /* Size of pno, sno fields */
#define MAXNAME 30    /* Size of pname, sname fields */
#define FALSE 0
#define TRUE 1

typedef struct spnode *SPnodeptr;   /* Pointer type for spnode */
typedef struct snode *Snodeptr;     /* Pointer type for snode */
typedef struct pnode *Pnodeptr;     /* Pointer type for pnode */

struct supp_element_type {         /* supplier element type */
  char sno[MAXNUM];
  char sname[MAXNAME];
};

struct part_element_type {         /* part element type */
  char pno[MAXNUM];
  char pname[MAXNAME];
};

struct snode {                           /* supplier node */
  struct supp_element_type supplier;
  SPnodeptr first_sp;
  Snodeptr next;
};

struct pnode {                        /* part node */
  struct part_element_type part;
  SPnodeptr first_sp;
  Pnodeptr next;
};

struct spnode {               /* supply node */
  SPnodeptr snext, pnext;
  Snodeptr s_owner;
  Pnodeptr p_owner;
};

/********************************************************
                  supps.h
********************************************************/

Snodeptr salloc(void); 
/* allocates storage for snode; returns pointer to snode */

int hash(struct supp_element_type x); 
/* hash function; computes a number between 0 and MAXSIZE
   based on the sno field of x */

void makenull_supp(Snodeptr suppliers[]);
/* creates an empty suppliers set, i.e. places NULL in
   all the hash table entries */

int insert_supp(struct supp_element_type x, Snodeptr suppliers[]);
/* inserts supplier element x into the suppliers set */

int delete_supp(struct supp_element_type x, Snodeptr suppliers[],
                Pnodeptr parts);
/* deletes the supplier element x from the suppliers set;
   Also requires access to parts set because we have to delete
   all supply elements for the supplier being deleted  */

int member_supp(struct supp_element_type x, Snodeptr suppliers[], 
                Snodeptr *s);       
/* returns TRUE if supplier element x is present in the suppliers
   set; if present, it also returns the pointer to the snode
   containing x in s */

void print_suppliers(Snodeptr suppliers[]);
/* prints the number and names of all suppliers in the suppliers
   set */

void delete_all_supply_for_supplier(Snodeptr q, Snodeptr suppliers[],
                                    Pnodeptr *parts);
/* given the pointer q to the snode containing a supplier, this
   function deletes all supply records for this supplier from its
   list */


/********************************************************
                  parts.h
********************************************************/

Pnodeptr palloc(void);
/* allocates storage for pnode; returns pointer to pnode */

void makenull_part(Pnodeptr *parts);
/* creates an empty parts set */

int insert_part(struct part_element_type x, Pnodeptr *parts);
/* inserts part element x into the parts set */

int delete_part(struct part_element_type x, Snodeptr suppliers[],
                Pnodeptr *parts);
/* deletes the part element x from the parts set;
   Also requires access to suppliers set because we have to delete
   all supply elements for the part being deleted  */

int member_part(struct part_element_type x, Pnodeptr parts, 
                Pnodeptr *p);
/* returns TRUE if part element x is present in the parts 
   set; if present, it also returns the pointer to the pnode
   containing x in p */

void print_parts(Pnodeptr parts);
/* prints the number and names of all parts in the parts
   set */

void delete_all_supply_for_part(Pnodeptr q, Snodeptr suppliers[],
                                Pnodeptr *parts);
/* given the pointer q to the pnode containing a part, this
   function deletes all supply records for this part from its
   list */


/********************************************************
                  sp.h
********************************************************/

SPnodeptr spalloc(void);
/* allocates storage for spnode; returns pointer to spnode */

int member_supply(struct supp_element_type x,
                  struct part_element_type y,
                  Snodeptr suppliers[],
                  Pnodeptr parts);
/* returns TRUE if  is an element of the supply set 
   otherwise it returns FALSE */

int insert_supply(struct supp_element_type x,
                  struct part_element_type y,
                  Snodeptr suppliers[], 
                  Pnodeptr *parts);
/* inserts the supply element  in the supply set */

int delete_supply(struct supp_element_type x,
                  struct part_element_type y,
                  Snodeptr suppliers[],
                  Pnodeptr *parts);
/* deletes the supply element  from the supply set */

int print_suppliers_given_part(struct part_element_type x,
                               Pnodeptr parts);
/* prints the number and names of all suppliers who
   supply part x */

int print_parts_given_supplier(struct supp_element_type x,
                               Snodeptr suppliers[]);
/* prints the number and names of all parts which are
   supplied by supplier x */
 
void print_supply(Snodeptr suppliers[], Pnodeptr parts);
/* prints all supply elements */

/***************************************************************/