Criteria, don't want creating copies of objects all over the place. Should be fast, memory efficient and should not create leaks. Should be threadsafe.
Ideally I would want to store pointers to vectors in the HashMap, but I am worried about memory leaks that way.
Is this the best way?
std::map<std::string, std::auto_ptr<std::vector<std::string> > > adjacencyMap;
You're prohibited from storing an auto_ptr in any standard container. §23.1/3: "The type of objects stored in these components must meet the requirements of CopyConstructible
types (20.1.3), and the additional requirements of Assignable types." std::auto_ptr doesn't meet that requirement.
A std::map<> is not implemented as a hash_map, but as a red-black tree (see http://en.wikipedia.org/wiki/Map_(C%2B%2B))
You can use std::unordered_map<> for c++0x compilers or std::tr1::unordered_map<> for non c++0x compilers.
Boost also has its version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With