Saksham_Sahgal's blog

By Saksham_Sahgal, history, 22 months ago, In English

can anyone tell me how to make a custom hash for an —

unordered_set< pair < unordered_set<vector< int > , hashFunction > , vector< int > > >

where hashFunction is a custom hashFunction for unordered_set<vector> .

here it is —

struct hashFunction //hash function for unordered set

{

    size_t operator()(const vector<int> &myVector) const

    {
        std::hash<int> hasher;
        size_t answer = 0;

        for (int i : myVector)
        {
            answer ^= hasher(i) + 0x9e3779b9 +
                      (answer << 6) + (answer >> 2);
        }
        return answer;
    }
};
  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

struct cuh { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
Your code here...
»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

You can try smth like that

https://onlinegdb.com/RVYfaVtmt

P.S. Don't know how to write it shorter, but I sure that there is a way.