Documentation ¶
Overview ¶
Package typemap defines Map, a mapping from types.Type to interface{} values.
Index ¶
- func Identical(x, y types.Type) (ret bool)
- type Hasher
- type Map
- func (m *Map) At(key types.Type) interface{}
- func (m *Map) Delete(key types.Type) bool
- func (m *Map) Iterate(f func(key types.Type, value interface{}))
- func (m *Map) Keys() []types.Type
- func (m *Map) KeysString() string
- func (m *Map) Len() int
- func (m *Map) Set(key types.Type, value interface{}) (prev interface{})
- func (m *Map) SetHasher(hasher Hasher)
- func (m *Map) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Identical ¶
Identical reports whether x and y are identical types. Unlike types.Identical, receivers of Signature types are not ignored. Unlike types.Identical, interfaces are compared via pointer equality (except for the empty interface, which gets deduplicated). Unlike types.Identical, structs are compared via pointer equality.
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
A Hasher maps each type to its hash value. For efficiency, a hasher uses memoization; thus its memory footprint grows monotonically over time. Hashers are not thread-safe. Hashers have reference semantics. Call MakeHasher to create a Hasher.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a hash-table-based mapping from types (types.Type) to arbitrary interface{} 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.
Not thread-safe.
This fork handles Signatures correctly, respecting method receivers. Furthermore, it doesn't deduplicate interfaces or structs. Interfaces aren't deduplicated as not to conflate implicit and explicit methods. Structs aren't deduplicated because we track fields of each type separately.
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 sets the hasher used by Map.
All Hashers are functionally equivalent but contain internal state used to cache the results of hashing previously seen types.
A single Hasher created by MakeHasher() may be shared among many Maps. This is recommended if the instances have many keys in common, as it will amortize the cost of hash computation.
A Hasher may grow without bound as new types are seen. Even when a type is deleted from the map, the Hasher never shrinks, since other types in the map may reference the deleted type indirectly.
Hashers are not thread-safe, and read-only operations such as Map.Lookup require updates to the hasher, so a full Mutex lock (not a read-lock) is require around all Map operations if a shared hasher is accessed from multiple threads.
If SetHasher is not called, the Map will create a private hasher at the first call to Insert.