

//  MAIN.CC    
//
//  This is the main file for our fifth programming assignment, HW 6, CS 222 
//  Winter 1999.  

/********************************************
* Main:: test our hash table.
* Read in individuals check for membership, delete names, etc.
* You can rewrite this main however you please in order to
* check out your HashTable member functions properly.
*********************************************/


typedef enum boolean {FALSE,TRUE} BOOLEAN;   //  Have to make our own BOOLEAN type for C/C++ 
const int CHROMLENGTH = 8;                   //  Fix chromosome length to however many bits are
                                             //  used in the input file.
const int NUMBUCKETS = 10;                   //  Use as few buckets as possible, while still keeping
                                             //  avg and max bucket size O(1).

#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include "individual.cc"
#include "unsortedarray.cc"
#include "hashtable.cc"

void main() {
	int index;
        UnSortedArray CurrentPopulation;    
        HashTable ArchiveOfIndividuals;
        LinkedList L;
        char operation = 'f';
        int i, bucket; 
        Individual *who;                         //   An individual from console user, to be
        char tempchar;                          //   searched for in Pool.
        int first, last;
        
who = new Individual;

CurrentPopulation.InitializeFromFile();           // Go get entire current population from a file,
                                                // and insert them in to CurrentPopulation.

                                                // Load individuals from current population into
/*    ADD CODE HERE!  */                        // the Archive of Individuals.


while (operation != 'q')
  {
   cout << "\n Enter your choice: (i)nsert, (d)elete, (m)ember, (w)here, "
        << "(e)mptybucket check, (p)rint entire hash table, (s)izes of buckets, or (q)uit:  ";
   cin  >> operation;
   if (operation == 'i' || operation == 'd' || operation == 'm' ||
       operation == 'w' || operation == 'e')
      {
       cout << "Please enter a chromosome:    ";
       for (i = 0; i < CHROMLENGTH; i++)
          {
            cin >> tempchar;
            if(tempchar == '0')
               who->chromosome[i] = FALSE;
               else who->chromosome[i] = TRUE;
          };
      };
       cout << "\n";
   switch (operation)
    {
     case 'i':                       //  Insert in HashTable.
       ArchiveOfIndividuals.Insert(who);
       who = new Individual;
       break;
     case 'd':
       ArchiveOfIndividuals.Delete(who);
       break;
     case 'm':                       //  Check for a chromosome in HashTable, and return T,F.
       if(ArchiveOfIndividuals.Member(who))
         {cout << "\n Yes, it has been seen.\n";}
         else cout << "\n No, it has not been seen.\n";
       break;
     case 'w':                      //  Search for a chromosome in HashTable and return
       bucket= ArchiveOfIndividuals.BucketOf(who);           // its location (bucket number).
       cout << "\n It is in bucket "  << bucket << " in the archive..\n";
       break;
     case 'e':
       if(ArchiveOfIndividuals.EmptyBucket(who))
         cout << "Bucket is indeed empty. \n";
         else cout << "Bucket is NOT empty. \n";
       break;
     case 'p':
       ArchiveOfIndividuals.PrintTable();
       break;
     case 's':
       ArchiveOfIndividuals.PrintSizes();
       break;
     case 'q':
       break;
     default :
       cout<< "\n INPUT ERROR:  PLEASE CHOOSE ONE OF THE AVAILABLE COMMANDS! \n";
       break;
     }
  }
}



