c++ - Two separate keys map to a single entry in a std::map -


i'm working on piece of code has objective of being fast "search engine". have entries in file need searchable after reading whole file in. need searchable both name of entry, , it's offset beginning of file. problem 1 of memory usage since there millions of entries. using 2 separate std::maps store data either search term can specified. leads double storage of data trying reduce.

i've used valgrind massif find major part of memory usage double storage of entries.

current method of storage:

struct entry {     std::string name;     uint16_t offset;     uint16_t size;     bool isconst; };  namesearchmap.insert(std::pair<std::string, entry>(s_entry.name, e_entry)); offsetsearchmap.insert(std::pair<uint16_t, syminfo>(s_entry.offset, s_entry)); 

is there way can can make single map searchable either type of key?

you might consider using

std::map<std::string, std::shared_ptr<entry>> 

for mapping strings entry, ,

std::map<uint16_t, std::shared_ptr<entry>> 

note using shared pointers value payload (thus using same entry object both maps), save size of payload. while pay 2 shared pointers, you'll still come out ahead specific structure.

enter image description here

(felt drawing diagram. point, though, there 1 entry object in memory.)


you might interested in boost::bimap.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -