Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. include "BinarySearchTree.h"
  2. //#include "BinarySearchTree.cpp"
  3. #include <fstream>
  4. #include "Timer.h"
  5.  
  6. extern template class BinarySearchTree< string, int >;
  7.  
  8. void insertAllWords( BinarySearchTree< string, int > & bst, int j, const char * src )
  9. {
  10. int i = 0;
  11. ifstream in;
  12. string line;
  13. Timer t_1;
  14. double eTime = 0.0;
  15.  
  16. in.open( src );
  17. i = 0;
  18. int k = j * 50000 / 10;
  19.  
  20. t_1.start( );
  21.  
  22. while( getline( in, line ) && i < k )
  23. {
  24. bst.insert( line, 1 );
  25. //cout << line << " " << ++bst[ line ] << endl;
  26. ++i;
  27. }
  28. t_1.elapsedUserTime( eTime );
  29.  
  30. cout << "File: " << src << " Partition: " << j << "/10. Function: insertAllWords. Time: " << eTime << "s" << endl;
  31. in.close( );
  32. }
  33.  
  34. void findAllWords( BinarySearchTree< string, int > & bst, int j, const char * src )
  35. {
  36. int i = 0;
  37. ifstream in;
  38. string line;
  39. Timer t_1;
  40. double eTime = 0.0;
  41.  
  42. in.open( src );
  43. i = 0;
  44. int k = j * 50000 / 10;
  45.  
  46. t_1.start( );
  47.  
  48. while( getline( in, line ) && i < k )
  49. {
  50. bst.find( line );
  51. //cout << line << " " << ++bst[ line ] << endl;
  52. ++i;
  53. }
  54. t_1.elapsedUserTime( eTime );
  55.  
  56. cout << "File: " << src << " Partition: " << j << "/10. Function: findAllWords. Time: " << eTime << "s" << endl;
  57. in.close( );
  58. }
  59.  
  60. void removeAllWords( BinarySearchTree< string, int > & bst, int j, const char * src )
  61. {
  62. int i = 0;
  63. ifstream in;
  64. string line;
  65. Timer t_1;
  66. double eTime = 0.0;
  67.  
  68. in.open( src );
  69. i = 0;
  70. int k = j * 50000 / 10;
  71.  
  72. t_1.start( );
  73.  
  74. while( getline( in, line ) && i < k )
  75. {
  76. bst.remove( line );
  77. ++i;
  78. }
  79. t_1.elapsedUserTime( eTime );
  80.  
  81.  
  82. cout << "File: " << src << " Partition: " << j << "/10. Function: removeAllWords. Time: " << eTime << "s" << endl;
  83. in.close( );
  84. }
  85.  
  86. void measureAll( char * src )
  87. {
  88. BinarySearchTree< string, int > bst;
  89.  
  90. try
  91. {
  92. for( int i = 1; i < 11; ++i )
  93. {
  94. insertAllWords( bst, i, src );
  95. findAllWords( bst, i, src );
  96. removeAllWords( bst, i, src );
  97. }
  98. }
  99. catch( int i )
  100. {
  101. cout << "int thrown\n" << i << endl;
  102. }
  103. }
  104.  
  105. int main( int argc, char * argv[] )
  106. {
  107. measureAll( argv[1] );
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement