My goal is to do string-interning. For this I am looking for a hashed container class that can do the following:
- allocate only one block of memory per node
- different userdata size per node
The value type looks like this:
struct String
{
size_t refcnt;
size_t len;
char data[];
};
Every String object will have a different size. This will be accomplished with opereator new + placement new. So basically I want to allocate the Node myself and push it in the container later.
Following containers are not suitable:
- std::unordored_set
boost::multi_index::*
Cannot allocate different sized nodes
boost::intrusive::unordered_set
Seems to work at first. But has some drawbacks. First of all you have to allocate the bucket array and maintain the load-factor yourself. This is just unnecessary and error-prone.
But another problem is harder to solve: You can only search for objects that have the type String. But it is inefficient to allocate a String everytime you look for an entry and you only have i.e. a std::string as input.
Are there any other hashed containers that can be used for this task?