Skip to content

proposal: builtin: Standard library adds interface type for creating a hash #73453

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

Closed
pjebs opened this issue Apr 20, 2025 · 2 comments
Closed
Labels
Milestone

Comments

@pjebs
Copy link
Contributor

pjebs commented Apr 20, 2025

Proposal Details

This proposal is that:

  1. Standard Library creates a new Interface like fmt.Stringer or fmt.GoStringer called builtin.Hasher{ Hash() string}.
  2. Where appropriate, all comparable standard library types implement Hasher which returns a unique hash that represents the contents of that type. Ideally, this function remains stable irrespective of how the internals of the type change in the future (except for changes that effect the exported behaviour of the type)

In my use-case:

@bcmills in #6535 asks if reflect.Type is hashable. The response from the Elders is that it is comparable. That was satisfactory for OP.

However for faster comparisons, comparable and hashable are not the same. I suspect having reflect.Type for map keys is not as fast for lookups as a hash of that same reflect.Type for map keys.

@pjebs pjebs added the Proposal label Apr 20, 2025
@gopherbot gopherbot added this to the Proposal milestone Apr 20, 2025
@seankhliao
Copy link
Member

see #54670

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants