-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: go/types: add Hash function #69420
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
|
This type is often used as a set, as this convenience method prints
Those are principled suggestions, but in practice the value has always been either a non-nil pointer (in which case nil => missing) or |
Is there anything Put another way, if there were an appropriately-defined package types
import "container/hashmap"
func MakeHashMap[V any]() hashmap.Map[Type, V] {
return hashmap.Make[Type, V](Hash)
} |
Very good question. Now that you mention it, no, the HashMap is completely generic other than the fact it assumes (K=types.Type, hash=types.Hash, eq=types.Identical). If container/hashmap existed this proposal could reduce to just the Hash function, and perhaps a convenience constructor: func Hash(Type) uint
type HashMap[V any] = hashmap.Map[Type, V]
func NewHashMap[V any]() *HashMap[V] { return hashmap.New(Hash, Identical) } |
In light of @jimmyfrasche's idea, let's restrict this proposal to just the Hash function (the tricky part), with the expectation that a generic hash table (the easy part) will someday follow and that in the meantime it's easy enough for clients to write their own HashMap. |
cc @jba, who is thinking about unordered maps. Our generic unordered and ordered maps should be aligned. |
[Edit: this proposal is now just for the types.Hash function. The HashMap will follow in another proposal.]
We propose to add the HashMap data type (a generic evolution of golang.org/x/tools/go/types/typeutil.Map) to the standard
go/types
package, with the following API:Some notes:
The text was updated successfully, but these errors were encountered: