Documentation ¶
Overview ¶
Package typemap defines type M, a hash-table-based mapping from types (go/types.Type) to arbitrary values, and a hash function on types.
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.
Not thread-safe.
Index ¶
- type Hasher
- type M
- func (m *M) At(key types.Type) interface{}
- func (m *M) Delete(key types.Type) bool
- func (m *M) Iterate(f func(key types.Type, value interface{}))
- func (m *M) Keys() []types.Type
- func (m *M) KeysString() string
- func (m *M) Len() int
- func (m *M) Set(key types.Type, value interface{}) (prev interface{})
- func (m *M) SetHasher(hasher Hasher)
- func (m *M) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 M ¶
type M struct {
// contains filtered or unexported fields
}
typemap.M is a mapping from types.Type to interface{} values.
Just as with map[K]V, a nil *typemap.M is a valid empty map.
func (*M) At ¶
At returns the map entry for the given key. The result is nil if the entry is not present.
func (*M) Delete ¶
Delete removes the entry with the given key, if any. It returns true if the entry was found.
func (*M) 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 (*M) KeysString ¶
KeysString returns a string representation of the map's key set. Order is unspecified.
func (*M) SetHasher ¶
SetHasher sets the hasher used by typemap.M.
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 typemap.M instances. 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 M.Lookup require updates to the hasher, so a full Mutex lock (not a read-lock) is require around all typemap.M operations if a shared hasher is accessed from multiple threads.
If SetHasher is not called, the type-map will create a private hasher at the first call to Insert.