Description
One of the main things people often look at standard libraries for are good containers.
Right now, as far as I can tell, there are the following containers:
HashMap - in std/map.rs - a chained hash-table, with the usual performance characteristics (expected constant time access, insert, removal, no order, no comparing)
LinearMap - in core/send_map.rs - open addressing hash table, sendable (same general behavior as above, but sendable)
TreeMap - in std/treemap.rs - unbalanced binary search tree, very bad pathological inputs, is ordered, can be compared
FunTreeMap - in std/fun_treemap.rs - looks to be the same as above, but without mutation.
SmallIntMap - in std/smallintmap.rs - wee! constant time everything, ordered, comparable! oh yeah, space order the maximum key :)
So here are some questions I have:
- There are tradeoffs between chained hashing and open addressing - are the implementation differences relevant for sendability? If not, could they both be sendable? It seems that in general having two different hash tables to have different performance characteristics makes sense, as long as it is clear and documented, but having them differ in sendability seems like a separate issue (but I may just not understand what's going on). Also, is LinearMap in core because it is used internally for rustc? Otherwise, seems a bit odd (as even the Map trait is in std).
- The TreeMaps should be replaced with self-balancing trees, as the comments in the file suggest (Red-black seems like the choice), but I'm wondering if the distinction between TreeMap and FunTreeMap makes sense. Is there a way that this could be pushed into the interface? I'm not sure if this is possible, but if it is, it definitely seems desirable (as having two basically parallel implementations is not good).
- Right now there is a Map trait (in std/map.rs) - How about also having an OrderedMap interface? Is there a way to tie mutability into the interfaces, and is that desired?
- There is a type alias in TreeMap that defines a Set as a TreeMap to unit values. It would be good to have an actual Set type (though it could internally be the the same).
Any thoughts people have about containers? Time permitting, I might work on a red-black tree implementation to replace the TreeMap.