Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: container: add generic ordered map #53196

Open
rcoreilly opened this issue Jun 2, 2022 · 2 comments
Open

proposal: container: add generic ordered map #53196

rcoreilly opened this issue Jun 2, 2022 · 2 comments

Comments

@rcoreilly
Copy link

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.

@gopherbot gopherbot added this to the Proposal milestone Jun 2, 2022
@ianlancetaylor
Copy link
Contributor

This is the kind of package that we normally suggest should be created outside the standard library, and it sounds like that is already happening. When a package becomes popular we can consider bringing it in.

@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Jun 2, 2022
@earthboundkid
Copy link
Contributor

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.

The decision was made to wait until the dust settles before adding a lot of generics to the standard library. There's discussion mentioning math.Min/Max at #48287.

I think something like this proposal makes sense as part of rethinking of the container types: deque, sets, ordered map, a generic heap, possibly others…

@rsc rsc changed the title proposal: generic ordered map proposal: container: add generic ordered map Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants