News for hackers. Stuff that matters.
Re:Without the Futex, It's Futile by gpderetta on Tuesday August 19, 2025 @02:57PM (#44954979)
It was standardized in c++11, but it was standardizing hash_map that was in the original STL pre-C++98 and was available as an extension in most STL derived standard libraries.

For me the remaining reason I still reach for unordered_map is if I need reference stability as most faster hash tables don't provide it (and I don't care enough about performance to build reference stability on top of a better hash map).

Re:Without the Futex, It's Futile by tialaramex on Tuesday August 19, 2025 @04:12PM (#44955781)
When you want reference stability, do you need references to stay working even where something moved to a different hash table?

That is suppose we have two std::unordered_map<Goose> labelled A and B, and we put a particular Goose in A, later we get a reference to it, and we might, or might not, move it to B, but it definitely still exists. Do you need that? (As I understand it this is in fact what you get in std::unordered_map today)

Or for your purposes is it enough that it works only so long as the goose we're referring to is in A still and if we moved it out of A then it's fine that the reference is invalidated ?

Re:Without the Futex, It's Futile by gpderetta on Tuesday August 19, 2025 @05:14PM (#44956319)
If I need the lifetime of an object to outlive it's presence in the map then I use boost intrusive or simply a map of (smart) pointers.

For me it is usually when I need a multi indexed map where I use a fast map of pointers for the fast access and unordered_map both to keep the object alive and as a secondary access key.

Really I should use boost intrusive or boost multiindex, but these days I value the implementation simplicity in many cases, even if I have to keep the indices in sync myself

Re:Without the Futex, It's Futile by senderista on Tuesday August 19, 2025 @07:07PM (#44957085)
Can you use the CPython approach: an open-addressed hashtable mapping keys to indices into a dynamic array holding (pointers to) the actual keys and values? (Reference stability of course precludes implementing deletes by moving the last key/value entry into the vacated slot; instead you must track empty slots for reuse.)
Re:Without the Futex, It's Futile by masklinn on Wednesday August 20, 2025 @12:56AM (#44958737)
As soon as the hashmap needs to resize the array will be realloc’d, so it won’t be stable unless you add virtual memory tricks or an indirection via some sort of segmented array.
Re:Without the Futex, It's Futile by dragontamer on Wednesday August 20, 2025 @12:01PM (#44963137)
Of course. That's just map<obj*>. The pointer-to-pointers could move but the pointers are now staying put. But now you have a bit of a lifetime worry.

Map<shared_ptr<obj>> with weak_ptr probably is the best general solution. If the object decided to delete itself the weakptr will be set to null.