Advertisement
Ne-Biolog

Untitled

Mar 29th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class HashTable {
  2. public:
  3. HashTable(){}
  4. string find(const string& key);
  5. string remove(const string& key);
  6. string genStr(size_t len);
  7. int getHash(const string& str);
  8. void insert(const string& key, const string& value);
  9. private:
  10. };
  11.  
  12. string HashTable::genStr(size_t len) {
  13. string newStr = "";
  14. while(len--) {
  15. newStr += static_cast<char>(rand() % 26 + 'a');
  16. }
  17. return newStr;
  18. }
  19.  
  20. int HashTable::getHash(const string& str) {
  21. int value = 0;
  22. for(size_t i = 0; i < str.size(); ++i) {
  23. value = (value * 17 + str[i]) % 1597;
  24. }
  25. return value;
  26. }
  27.  
  28.  
  29. set<int> all;
  30.  
  31. int main ()
  32. {
  33. freopen("input.txt" , "r" , stdin);
  34. freopen("output.txt" , "w" , stdout);
  35. ios_base::sync_with_stdio(false);
  36.  
  37. srand(time(NULL));
  38. for(int i = 0; i < 100; ++i) {
  39. string z = HashTable.genStr(6);
  40. int h = HashTable.getHash(z);
  41. all.insert(h);
  42. }
  43.  
  44.  
  45. cout << all.size() << endl;
  46.  
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement