How to create a lookup table in C ++?

I am a complete newbie in C ++. I am trying to read a file and build a lookup table (rather, like a hash table, just to check if a string value exists). The file contains about 300 thousand records, which I will use to create a lookup table. And after that, I will carry out about 1 million searches about this. What is the most efficient way to do this? Is this a map (Googleโ€™s first result) or is there a better structure for this purpose?

+3
source share
8 answers

Based on the script, you probably also want to see Tries

+5
source

TRIE. . , O (n) , n - . Trie , .

+3

map log(n) , O(1) -, . , STL , hash_map.

+2

++ std::map -, , .

, ++:

  • O (log n)
  • O (log n)
  • O (log n)

, , std::map (, , - ), node .

Google Sparsehash

+2

set, , -. . .

+1
source

If your biggest problem is the search time (and it seems like it is), consider the hash table a lot. The amortized search time is O (1), which is better than a regular map in O (log n).

0
source

If you have a very good hash function (there is no collision with your dataset) and you just need to check if the record exists or not, you are trying to use a bitset (say, http://bmagic.sourceforge.net/ )

I believe this can reduce memory requirements very quickly.

0
source

Source: https://habr.com/ru/post/1767112/


All Articles