Search code examples
c++hashkeyvarcharlookup-tables

Best Structure to store hashed values with string type of keys


I am beginner in the field of hash. I am writing a program to index string keys. For that, I hash the first 3 characters of my varachar(512) key and then get the hashed value in numeric form. I intend to index my data using that numeric value. I allow collisions to occur, that is if two strings have their first three characters same, then they might have same hash value.

Now if some query comes to look for particular string key, i will first hash it and will look in the lookup table that what's its hash value.

Do i need to store a look up table for this purpose? or can i just dynamically calculate it's hash value and then perform search?

If yes, which structure would be good if we consider performance and optimization as the main criteria, I am using C++.

Thank you!


Solution

  • STL already has unordered_map and you can use it with user-defined types and custom hash functions.