Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include "BinarySearchTree.h"
- //#include "BinarySearchTree.cpp"
- #include <fstream>
- #include "Timer.h"
- extern template class BinarySearchTree< string, int >;
- void insertAllWords( BinarySearchTree< string, int > & bst, int j, const char * src )
- {
- int i = 0;
- ifstream in;
- string line;
- Timer t_1;
- double eTime = 0.0;
- in.open( src );
- i = 0;
- int k = j * 50000 / 10;
- t_1.start( );
- while( getline( in, line ) && i < k )
- {
- bst.insert( line, 1 );
- //cout << line << " " << ++bst[ line ] << endl;
- ++i;
- }
- t_1.elapsedUserTime( eTime );
- cout << "File: " << src << " Partition: " << j << "/10. Function: insertAllWords. Time: " << eTime << "s" << endl;
- in.close( );
- }
- void findAllWords( BinarySearchTree< string, int > & bst, int j, const char * src )
- {
- int i = 0;
- ifstream in;
- string line;
- Timer t_1;
- double eTime = 0.0;
- in.open( src );
- i = 0;
- int k = j * 50000 / 10;
- t_1.start( );
- while( getline( in, line ) && i < k )
- {
- bst.find( line );
- //cout << line << " " << ++bst[ line ] << endl;
- ++i;
- }
- t_1.elapsedUserTime( eTime );
- cout << "File: " << src << " Partition: " << j << "/10. Function: findAllWords. Time: " << eTime << "s" << endl;
- in.close( );
- }
- void removeAllWords( BinarySearchTree< string, int > & bst, int j, const char * src )
- {
- int i = 0;
- ifstream in;
- string line;
- Timer t_1;
- double eTime = 0.0;
- in.open( src );
- i = 0;
- int k = j * 50000 / 10;
- t_1.start( );
- while( getline( in, line ) && i < k )
- {
- bst.remove( line );
- ++i;
- }
- t_1.elapsedUserTime( eTime );
- cout << "File: " << src << " Partition: " << j << "/10. Function: removeAllWords. Time: " << eTime << "s" << endl;
- in.close( );
- }
- void measureAll( char * src )
- {
- BinarySearchTree< string, int > bst;
- try
- {
- for( int i = 1; i < 11; ++i )
- {
- insertAllWords( bst, i, src );
- findAllWords( bst, i, src );
- removeAllWords( bst, i, src );
- }
- }
- catch( int i )
- {
- cout << "int thrown\n" << i << endl;
- }
- }
- int main( int argc, char * argv[] )
- {
- measureAll( argv[1] );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement