I think the right way to do this is to call
max_load_factor(xxx)
and
min_load_factor(xxx)
You can do min_load_factor(0.0) so we never resize smaller. That
means we'll never clear out deleted elements. I don't know if there's
a simple way to do that without also resizing the hashtable. I guess
you could do something like:
sparse_hash_map<...> new_map(mymap.size());
for (it = mymap.begin(); it != mymap.end(); ++it)
new_map->insert(*it);
mymap.swap(new_map);
This is more or less what the code does internally on a resize.
But I don't know how necessary such behavior is. My guess is that
will be slower than just calling min_load_factor(0.0) and just keeping
doing your inserts and deletes. If you find you're getting too
clogged with deleted keys, you can call
mymap.resize(0)
after you've done a bunch of insertions (so you're at the high end of
the spectrum), to keep the hashtable from getting smaller.
craig
Insert causing a shrink is desired behavior: it's because we never
resize a hashtable on delete (in order to preserve iterators an
pointers while deleting).
So I think your patch would mean, in effect, we never shrink the
hashtable regardless of the min_load_factor, which isn't ideal.
I think, though, it makes sense to add a check there that never
resizes lower when min_load_factor is 0. I'll try to do something
like that for the next release.
craig
Never mind, I looked at the code more closely and see that your fix is
right, and my objection is wrong. I'll do a bit of testing, and look
to get this into the next release.
craig