Skip to content

Containers - meta-issue to talk about quality of containers, what should be replaced, etc #3863

Closed
@dbp

Description

@dbp

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:

  1. 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).
  2. 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).
  3. 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?
  4. 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.

Related issues (that I found): #3385, #2009

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions