Skip to content

proposal: container: add generic ordered map #53196

@rcoreilly

Description

@rcoreilly

This proposal is just to suggest that an official implementation of an ordered map using the new generics would likely be a widely-appreciated addition to the standard library.

Personally, it took me a while to realize that I was constantly writing some version or another of an ordered map. Now that I've made my own generic version, I've used it several times.

My version is here: https://github.com/goki/kigen/tree/main/ordmap

And here is another example: https://github.com/wk8/go-ordered-map

My version is more "bare metal" and exposes all the impl, so you can add functionality etc as needed, and use standard Go range iteration on the slice or map. It just saves you the effort of keeping the map and slice coordinated when deleting or inserting.

The other example provides iterator functions instead, and hides the impl.

Obviously, anyone can roll their own as desired, but there might be some benefit to having a standard impl with the incomparable design sensibilities of the Go team. Again, the only real point here is to suggest that such a thing would likely be widely used and appreciated..

In any case, this is also an opportunity to provide glowing positive feedback for what a pleasure it was to finally use the generics after all those debates etc -- everything was very intuitive, and I have not noticed either of the two evils of generics slowdowns (though I haven't done any benchmarking). Great job!

ps. did I miss it or is a generic version of Min and Max not yet avail? That was prominent in the original discussions, but I searched under issues here and didn't find discussion of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions