Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HashTable {
- public:
- HashTable(){}
- string find(const string& key);
- string remove(const string& key);
- string genStr(size_t len);
- int getHash(const string& str);
- void insert(const string& key, const string& value);
- private:
- };
- string HashTable::genStr(size_t len) {
- string newStr = "";
- while(len--) {
- newStr += static_cast<char>(rand() % 26 + 'a');
- }
- return newStr;
- }
- int HashTable::getHash(const string& str) {
- int value = 0;
- for(size_t i = 0; i < str.size(); ++i) {
- value = (value * 17 + str[i]) % 1597;
- }
- return value;
- }
- set<int> all;
- int main ()
- {
- freopen("input.txt" , "r" , stdin);
- freopen("output.txt" , "w" , stdout);
- ios_base::sync_with_stdio(false);
- srand(time(NULL));
- for(int i = 0; i < 100; ++i) {
- string z = HashTable.genStr(6);
- int h = HashTable.getHash(z);
- all.insert(h);
- }
- cout << all.size() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement