dictionary - Search all keys with a prefix in map of C++ -


this question has answer here:

i'm using map store data. map has big data. want find keys has prefix, limit number of result items 50. want use fastest way search, not iterate through whole map , check, since map structured key-value container already.

for example, if have pairs:

<"foo123", value>  <"foo234", value>  <"bar12", value>  <"foo456", value>   <"bar200", value> 

if search "foo", suggest me

foo123, foo234, foo456.  

there 2 approaches come mind:

  • the first special container called trie, there no equivalent in c++ standard library, should able locate working versions easily.

  • the second approach uses fact in std::map, key "foo" sorts before "foo123". using upper_bound or lower_bound functions find starting range , there on use linear search.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -