Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdint>
- #include <array>
- #include <cmath>
- #include <set>
- #include <random>
- using namespace std;
- std::array<std::uint32_t, 8> P = {
- 2,
- 59,
- 137,
- 10321,
- 434981,
- 2002547,
- 1676902,
- 1073676287
- };
- std::int64_t hash1(std::int32_t x) {
- std::int64_t result = 0;
- for (std::size_t i = 0; i < P.size(); ++i) {
- std::int64_t left = (x % P[i]);
- std::int64_t right = std::floor((x / (std::pow(16.0f, i) - 1.0f)));
- //std::cout << "P[" << i << "]: " << P[i] << std::endl;
- //std::cout << "left: " << left << std::endl;
- //std::cout << "right: " << right << std::endl;
- result += left * right;
- }
- return result;
- }
- std::int64_t hash2(std::int32_t x) {
- std::int64_t result = 0;
- for (std::size_t i = 0; i < P.size(); ++i) {
- result += std::pow((x >> i) ^ (x & P[i]), 2);
- }
- return result;
- }
- std::set<std::int64_t> hash1_values;
- std::set<std::int64_t> hash2_values;
- int main() {
- std::mt19937 gen{std::random_device{}()};
- for (std::int32_t i = 0; i < 2000000; ++i) {
- auto h = hash1(gen());
- hash1_values.insert(h);
- }
- for (std::int32_t i = 0; i < 2000000; ++i) {
- auto h = hash2(gen());
- hash2_values.insert(h);
- }
- std::cout << hash1_values.size() << std::endl;
- std::cout << hash2_values.size() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement