#ifndef MERGTEST_H
#define MERGETEST_H
/************************************************************
  FILE: mergetest.h
  K.Becker
  September 27 2000

  Program to compare polyphase merge against cascade

  WARNING: input error checking is minimal

  Expected arguments:
  1: -n N :: the order of the merge [# devices = n+1]

  2: -f F :: the file size in bytes [default = 1 GB]

  3: -m M :: amount of available memory [default = 10 MB]
  
  4: -r R :: size of one record [default = 1000 bytes]

  5: -k K :: the number of initial runs [can be calculated]
  
  6: (optional) debug flag: -d 1 | 2 | 3
        [0] no trace (default)
	[1] minimal 
	[2] medium
	[3] full trace

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

#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <fstream.h>
#include <string.h>

// GLOBALS ARE ALL DEFINED IN MERGETEST.CC

extern int debug;

extern const int MAXR;     // maximum number of rows
extern int       maxR;      // max number of useful rows
    // these numbers can get big so we watch for overflow

class Device;

//-----------------------------------------------------------------------
// The routines:
void help( ); // displayed when mergetest invoked w/o arguments
              // command line args stuff
void getargs (int argc, char* argv[], 
	      int& order, 
	      long int& fsize, 
	      long int& memsize, 
	      long int& recsize, 
	      long int& nruns );

              // for displaying generated tables DEBUG
void displaytable( char str[], long int** p, int rows, int cols );

long int** genpoly( int cols, int& maxR );  // polyphase merge table
long int** gencascade( int cols, int& maxR ); // cascade merge table

void SetUp( long int** table, // polyphase/cascade merge table
	    int order,
	    int nruns,
	    int runsize,
	    Device* devices[], Device* sources[], Device*& dest );
                       // set up the initial distribution for this run

     // do one round of mreges (till one device goes empty)
void do_round( Device* sources[], Device* dest, 
	       int order, 
	       long int rps,       // records per seek
	       long int& setseeks, 
	       long int& whos_empty,
	       bool& done );


void polyphase ( Device* sources[], Device*& dest, int order, int runsize );



// end mergetest header
#endif
