in Education by
Consider the following code. What is a good hashing function for the array in Key to be used in an unordered_map? #include using namespace std; enum TriState { S0 = -1, S1 = 0, S2 = +1 }; struct K { // Key for the map TriState a[8][8]; bool operator==(const K& k1) const { for (int i = 0; i < 64; i++) if (k1.a[0][i] != a[0][i]) return false; return true; } }; struct Hash { size_t operator()(const K& k) const { size_t s; // s = what is a good hash value? return s; } }; unordered_map m; JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This algorithm should be fast and provide near-uniform hashing: size_t s = 0x3a7eb429; // Just some random seed value for (int i = 0; i != 8; ++i) { for (int j = 0; j != 8; ++j) { s = (s >> 1) | (s << (sizeof(size_t) * 8 - 1)); s ^= k.a[i][j] * 0xee6b2807; } } s *= 0xee6b2807; s ^= s >> 16; After that, if you want to make the hashing even stronger, hash s another time using for example MurmurHash3.

Related questions

0 votes
    I'm trying to assemble and display image slices which have been preloaded into a two dimensional array, but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 31, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    ______ Uses Grieg-Smith method on 2 dimensional spatial data. (a) G.S. (b) g.data (c) G1DBN (d) ... Linear Regression of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which of the following package combine multi-dimensional arrays? (a) stringr (b) comb (c) abind (d) ... Regression of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I am trying to implement an algorithm, that finds the shortest path in the following two dimensional array ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 24, 2022 in Education by JackTerrance
0 votes
    There is no way to have a tri-state check button (yes, no, null) in HTML, right? Are there any ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a bunch of vector classes. I have a 2D point vec2_t, a 3D point vec3_t and a 4D point ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a bunch of vector classes. I have a 2D point vec2_t, a 3D point vec3_t and a 4D point ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Series is a one-dimensional labeled array capable of holding any data type. (a) True (b) False The ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    I am trying to implement the Josephus election problem using an array as a mock circular linkedlist. The item and next arrays represent ... array x = next[x]; count++; } std::cout...
asked Apr 7, 2022 in Education by JackTerrance
...