/******************************************************* Proj4Aux.C CMSC-341 Spring 2004 Project4 Spencer Shimko, Section 001, sshimko1 Created: 07 April 2004 Current: 07 April 2004 Auxillary file for comparing various actions on BSTs and HTs I have read and I understand the course policy on cheating. By submitting the following program, I am stating that the program was produced by my individual effort. *********************************************************/ #include #include #include using namespace std; #include "Proj4Aux.H" #include "BinarySearchTree.H" #include "QuadProbing.H" void setupVectors( vector & v1, vector & v2, int seed, int cnt ){ srand(seed); int num; // number that will be inserted double rv; // number to decide which vector to insert num int numV1 = 0; // number currently in V1 int numV2 = 0; // number currently in V2 // insert random numbers while needed while ( ( numV1 < cnt ) && ( numV2 < cnt ) ){ num = rand ( ); rv = rand ( )/ (double) RAND_MAX; if ( ( rv <= 0.33 ) && ( numV1 < cnt ) ){ v1.push_back ( num ); numV1++; } else if ( ( rv <= 0.66 ) && ( numV2 < cnt ) ){ v2.push_back ( num ); numV2++; } else { if ( numV1 < cnt ) { v1.push_back ( num ); numV1++; } if ( numV2 < cnt) { v2.push_back ( num ); numV2++; } } } } void testBST ( const vector & v1, const vector & v2 ){ cout << "==================================================" << endl; cout << " Running BST simulations..." << endl; cout << "==================================================" << endl; // create bst for timing tests BinarySearchTree bst (-1); // insert items from v1 into tree // insert operation returns a integer based on the number of comparisons for ( unsigned int i = 0; i < v1.size ( ); i++ ){ bst.insert ( v1[ i ] ); } // test find int ignore; for ( unsigned int i = 0; i < v1.size ( ); i++ ){ ignore = bst.find ( v2[ i ] ); } bst.printStats ( ); } void testHT ( const vector & v1, const vector & v2 ){ // run hashtable experiments with these lambdas // 0.3, 0.4, 0.5, 0.6, 0.7, and 0.8 double lambda; cout << "==================================================" << endl; cout << " Running hashtable simulations..." << endl; cout << "==================================================" << endl; for ( int x = 3; x <= 8; x++){ // convert lambda lambda = (double) x / 10; HashTable ht ( -1, (int) (ceil (v1.size ( ) / lambda )) ); // insert items from v1 into tree // insert operation returns a integer based on the number of comparisons for ( unsigned int i = 0; i < v1.size ( ); i++ ){ ht.insert ( v1[ i ] ); } // test find int ignore; for ( unsigned int i = 0; i < v1.size ( ); i++ ){ ignore = ht.find ( v2[ i ] ); } cout << "**********[ LAMBDA: " << fixed << setprecision (4) << lambda << " ]************" << endl; cout << "--------------------------------------------------" << endl; ht.printStats ( ); } }