Documentation ¶
Overview ¶
Package cmap contains an implementation of a canonicalizing map.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Comparator ¶
func Comparator[C comparable]() func(C, C) bool
Comparator returns a comparator for comparable types.
Types ¶
type Entry ¶
type Entry[K, V any] struct { Key K Value V }
An Entry in a Map. Note that the Key type is not necessarily comparable.
type Map ¶
type Map[K any, V any] interface { // CopyInto populates the destination with the contents of the map. CopyInto(dest Map[K, V]) // Delete removes a key from the map. Delete(key K) // Entries returns the entries of the map as a slice. Note that // the iteration order is not stable. Entries() []Entry[K, V] // Get returns the value associated with the canonical form of the // key. Get(key K) (_ V, ok bool) // GetZero returns the value associated with the canonical form of // the key or returns a zero value. GetZero(key K) V // Len returns the number of entries in the Map. Len() int // Match is similar to Get, except that it returns the original key // used to insert the entry. This can be used by callers to // determine if the requested and original keys are an exact match. Match(key K) (_ K, _ V, ok bool) // Put adds a new mapping. Any error returned by the Mapper will be // returned. Put(key K, value V) // Range invokes the callback for each entry in the Map. Range will // stop at the first error returned by the callback. If the callback // never returns an error, neither will Range. Range(func(k K, v V) error) error }
The Map type uses a canonical representation of a key when storing or retrieving values. This allows key types which are not comparable to be used.
A Map is not internally synchronized.
func New ¶
func New[K any, C comparable, V any](mapper Mapper[K, C]) Map[K, V]
New constructs a canonicalizing Map. The K type must implement TextKey if the MarshalJSON or UnmarshalJSON methods are to be called.
func NewIdentity ¶
func NewIdentity[K comparable, V any]() Map[K, V]
NewIdentity returns a Map for comparable keys. A basic map type is recommended unless compatibility with the Map interface is necessary.
Click to show internal directories.
Click to hide internal directories.