Unordered container of Glib::ustring



Hi,

I'm writing an application in C++ with gtkmm.

I want to have an unordered container, std::unordered_map, in which the
key type is Glib::ustring. It means I need choose one of these options:

1. Make the map actually have Glib::ustring objects, and write a hash
functor for them (since none is defined by default)

2. Make the map have std::string objects, which have a standard
std::hash functor

Assume I choose the first option. How do I write the hash function? I
see two options:

1. Take a Glib::ustring object, get its collate_key() which is a
std::string, and apply the standard string hash on it

2. Take a Glib::ustring object, get its underlying std::string using the
raw() method, and apply the standard hash on that string.

I mentioned a few different questions here, but the important one is:
For the purpose of hashing Glib::ustring for an unordered container,
which hash function should I use? A custom one or use collate_key() or
use raw()?
Does in make a difference whether I use raw() or collate_key()? (in
terms of the chance that different strings get the same hash)

Thanks in advance,
- Anatoly Krasner



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]