randomInput.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*Dylan Jeffers
  2. *Tahmid Rahman
  3. *founders of RahmROMJeffers ltd.
  4. *
  5. *cheatDetector implementation - compares documents to each
  6. *other and outputs how many phrases of a given length match
  7. */
  8. #include <iostream>
  9. #include <fstream>
  10. #include <stdlib.h>
  11. #include "pair.h"
  12. #include "SPLAVL.h"
  13. #include "SplayTree.h"
  14. #include "AVLTree.h"
  15. #include "library/circularArrayList.h"
  16. #include <time.h>
  17. #include <vector>
  18. #include <cstdlib>
  19. using namespace std;
  20. void makeTree(vector<int> keyList, BST<int, int> * treeList);
  21. int main(int argc, char* argv[]){
  22. if(argc != 5){
  23. cerr << "Incorrect number of arguments" << endl;
  24. cerr << "Usage: randomInput treeSize maxC maxR useAVL" << endl;
  25. return 1;
  26. }
  27. unsigned int keyNum = atoi(argv[1]);
  28. cout << keyNum << endl;
  29. cout.flush();
  30. int maxC = atoi(argv[2]);
  31. int maxR = atoi(argv[3]);
  32. int useAVL = atoi(argv[4]);
  33. int randNum;
  34. BST<int, int>* tree;
  35. vector<int> keyList;
  36. if (useAVL == 0) {
  37. tree = new SPLAVL<int,int>(maxC, maxR);
  38. }
  39. else if (useAVL == 1) {
  40. tree = new SplayTree<int, int>();
  41. }
  42. else {
  43. tree = new AVLTree<int, int>();
  44. }
  45. randNum = rand() % (keyNum*10);
  46. keyList.push_back(randNum);
  47. while(keyList.size() < keyNum) {
  48. for (unsigned int i = 0; i < keyList.size(); i++) {
  49. if (randNum == keyList[i]) {
  50. break;
  51. }
  52. if (randNum != keyList[i] && (i == keyList.size()-1)) {
  53. keyList.push_back(randNum);
  54. }
  55. }
  56. randNum = rand() % (keyNum*10);
  57. }
  58. makeTree(keyList, tree);
  59. //main engine to test find
  60. clock_t t1, t2;
  61. t1 = clock();
  62. // locality range
  63. unsigned int range = 2;
  64. for (unsigned int i = 1; i <= range; i*=2) {
  65. //note this for loop can be arbitrarily long
  66. for (unsigned int j=0; j < keyNum; j++) {
  67. //considering :((rand() % i) + i) % i
  68. randNum = rand() % i;
  69. tree->find(keyList[randNum]);
  70. }
  71. }
  72. t2 = clock();
  73. cout << useAVL << " " << ((float)(t2-t1))/CLOCKS_PER_SEC << endl;
  74. delete tree;
  75. return 0;
  76. }
  77. void makeTree(vector<int> keyList, BST<int, int> * tree) {
  78. for (unsigned int i=0; i<keyList.size(); i++) {
  79. tree->insert(keyList[i], 0);
  80. }
  81. }