Skip to content

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

@pjebs

Description

@pjebs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions