std::bitset hash function algorithm

Viewed 1614

Does anybody know what algorithm thw hash function for bitset is using,

this is from website : http://en.cppreference.com/w/cpp/utility/bitset/hash

#include <iostream>
#include <bitset>
#include <functional>

int main()
{
    std::bitset<4> b1(1);
    std::bitset<4> b2(2);
    std::bitset<4> b3(b2);
    std::bitset<4> b4(8);
    std::cout<<b4<<'\n';
    std::hash<std::bitset<4>> hash_fn;

    size_t h1 = hash_fn(b1);
    size_t h2 = hash_fn(b2);
    size_t h3 = hash_fn(b4);

    std::cout << h1 << '\n';
    std::cout << h2 << '\n';
    std::cout << h3 << '\n';
}

and the output is

1000
4334672815104069193
16667047557902998627
2258353126044249582

http://en.cppreference.com/w/cpp/utility/bitset/hash

Also why doesn't it convert the bits to unsigend long and generate a hash value?

1 Answers
Related