Hashing Function for Map C++

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2012-12-09T21:56:07Z Indexed on 2012/12/09 23:04 UTC
Read the original article Hit count: 183

Filed under:
|
|
|
|

I am trying to determine a hash function which takes an input (i, k) and determines a unique solution.

The possible inputs for (i, k) range from 0 to 100. Consider each (i, k) as a position of a node in a trinomial tree.

Ex: (0, 0) can diverge to (1, 1) (1, 0) (1, -1). 
    (1, 1) can diverge to (2, 2) (2, 1) (2, 0).

Sample given here:

http://www.google.com/imgres?imgurl=http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/stfhtmlimg1156.gif&imgrefurl=http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/stfhtmlnode41.html&h=413&w=416&sz=4&tbnid=OegDZu-yeVitZM:&tbnh=90&tbnw=91&zoom=1&usg=__9uQWDNYNLV14YioWWbrqPgfa3DQ=&docid=2hhitNyRWjI_DM&hl=en&sa=X&ei=xAfFUIbyG8nzyAHv2YDICg&ved=0CDsQ9QEwAQ

I am using a map

map <double, double> hash_table

I need a key value to be determined from pairs (i, k) to hash to to value for that (i, k)

So far I was only able to come up with linear functions such as: double Hash_function(int i, int k)

{
    //double val = pow(i, k) + i;
    //return (val % 4294967296);
    return (i*3.1415 + k*i*9.12341); 
}

However, I cannot determine a unique key with a certain (i, k). What kind of functions can I use to help me do so?

© Stack Overflow or respective owner

Related posts about c++

Related posts about data-structures