Rationale in selecting Hash Key type

Posted by Amrish on Stack Overflow See other posts from Stack Overflow or by Amrish
Published on 2010-04-16T21:23:46Z Indexed on 2010/04/16 21:33 UTC
Read the original article Hit count: 209

Filed under:
|
|
|
|

Guys, I have a data structure which has 25 distinct keys (integer) and a value. I have a list of these objects (say 50000) and I intend to use a hash table to store/retrieve them. I am planning to take one of these approaches.

  1. Create a integer hash from these 25 integer keys and store it on a hash table. (Yeah! I have some means to handle collisions)

  2. Make a string concatenation on the individual keys and use it as a hash key for the hash table. For example, if the key values are 1,2,4,6,7 then the hash key would be "12467".

Assuming that I have a total of 50000 records each with 25 distinct keys and a value, then will my second approach be a overkill when it comes to the cost of string comparisons it needs to do to retrieve and insert a record?

Some more information!

  1. Each bucket in the hash table is a balanced binary tree.
  2. I am using the boost library's hash_combine method to create the hash from the 25 keys.

© Stack Overflow or respective owner

Related posts about hashtable

Related posts about key