Documentation
¶
Overview ¶
Package typeutil defines various utilities for types, such as Map, a hash table that maps types.Type to any value.
Index ¶
- type Hasher
- type Map
- func (m *Map) At(key types.Type) any
- func (m *Map) Delete(key types.Type) bool
- func (m *Map) Iterate(f func(key types.Type, value any))
- func (m *Map) Keys() []types.Type
- func (m *Map) KeysString() string
- func (m *Map) Len() int
- func (m *Map) Set(key types.Type, value any) (prev any)
- func (m *Map) SetHasher(Hasher)
- func (m *Map) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hasher ¶
type Hasher struct{}
A Hasher provides a Hasher.Hash method to map a type to its hash value. Hashers are stateless, and all are equivalent.
func MakeHasher ¶
func MakeHasher() Hasher
MakeHasher returns Hasher{}. Hashers are stateless; all are equivalent.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a hash-table-based mapping from types (types.Type) to arbitrary values. The concrete types that implement the Type interface are pointers. Since they are not canonicalized, == cannot be used to check for equivalence, and thus we cannot simply use a Go map.
Just as with map[K]V, a nil *Map is a valid empty map.
Read-only map operations (Map.At, Map.Len, and so on) may safely be called concurrently.
TODO(adonovan): deprecate in favor of https://go.dev/issues/69420 and 69559, if the latter proposals for a generic hash-map type and a types.Hash function are accepted.
func (*Map) At ¶
At returns the map entry for the given key. The result is nil if the entry is not present.
func (*Map) Delete ¶
Delete removes the entry with the given key, if any. It returns true if the entry was found.
func (*Map) Iterate ¶
Iterate calls function f on each entry in the map in unspecified order.
If f should mutate the map, Iterate provides the same guarantees as Go maps: if f deletes a map entry that Iterate has not yet reached, f will not be invoked for it, but if f inserts a map entry that Iterate has not yet reached, whether or not f will be invoked for it is unspecified.
func (*Map) Keys ¶
Keys returns a new slice containing the set of map keys. The order is unspecified.
func (*Map) KeysString ¶
KeysString returns a string representation of the map's key set. Order is unspecified.
func (*Map) SetHasher ¶
SetHasher has no effect.
It is a relic of an optimization that is no longer profitable. Do not use Hasher, MakeHasher, or [SetHasher] in new code.