Skip to content

Instantly share code, notes, and snippets.

@l-bat
Created October 2, 2017 16:39
Show Gist options
  • Save l-bat/80339988ac61e3c3f0b6a832c074792b to your computer and use it in GitHub Desktop.
Save l-bat/80339988ac61e3c3f0b6a832c074792b to your computer and use it in GitHub Desktop.
New 02-10-17
#include <iostream>
#include <unordered_set>
#include <random>
#include <fstream>
using Key = std::pair<std::string, std::pair<float, float>>;
namespace std {
template<>
class hash<Key> {
public:
size_t operator()(const Key& s) const
{
size_t h1 = std::hash<string>()(s.first);
size_t h21 = std::hash<float> ()(s.second.first);
size_t h22 = std::hash<float> ()(s.second.second);
return h1 ^ ( (h21 * h22) << 1 );
}
};
}
int main(int argc, char* argv[]) {
int N = atoi(argv[1]);
std::mt19937_64 generator{std::random_device()()};
std::uniform_real_distribution<float> distribution(0.0f, 10.0f);
std::uniform_int_distribution<> intDistribution(1, 20);
//std::pair<float, float> rating;
//Key FilmRate;
std::unordered_multiset<Key> hashTable; // not INT
std::ifstream ofs;
ofs.open ("Films.txt", std::ofstream::in);
for(int i = 0; i < N; ++i)
{
auto cinemaSearch = distribution(generator);
auto IMDB = distribution(generator);
auto strSize = intDistribution(generator);
char* s;
ofs.getline(s, strSize);
Key key = std::make_pair(s, std::make_pair(cinemaSearch, IMDB));
// FilmRate.first = s;
// rating.first = cinemaSearch;
// rating.second = IMDB;
// FilmRate.second = rating;
//rating = std::make_pair(cinemaSearch, IMDB);
//FilmRate = std::make_pair(s, rating);
hashTable.insert(key);
}
int max = 0;
for (unsigned i = 0; i< hashTable.bucket_count(); ++i)
{
if (max < hashTable.bucket_size(i))
max = hashTable.bucket_size(i);
}
std::cout << "max = " << max;
ofs.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment