Documentation
¶
Overview ¶
Package hashmap implements a map backed by a hash table.
Index ¶
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Contains(k ...K) bool
- func (m *Map[K, V]) ContainsAny(k ...K) bool
- func (m *Map[K, V]) Get(k K) (value V, ok bool)
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) MarshalJSON() ([]byte, error)
- func (m *Map[K, V]) Put(k K, v V)
- func (m *Map[K, V]) Range(f func(k K, v V))
- func (m *Map[K, V]) Remove(k K)
- func (m *Map[K, V]) String() string
- func (m *Map[K, V]) UnmarshalJSON(data []byte) error
- func (m *Map[K, V]) Values() []V
- func (m *Map[K, V]) WithLock() *Map[K, V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map represents a hashmap which holds the entries in a hash table.
func New ¶
func New[K comparable, V any]() *Map[K, V]
New returns an initialized map with the default capacity as the initial capacity for the backing hash table.
func NewWithCapacity ¶
func NewWithCapacity[K comparable, V any](capacity int) *Map[K, V]
NewWithCapacity returns an initialized map with the given capacity as the initial capacity for the backing hash table.
func (*Map[K, V]) ContainsAny ¶
Contains returns true if map contains any of the given keys k.
func (*Map[K, V]) Get ¶
Get returns the corresponding value of the given key k if exists in map. The ok result indicates whether such value was found in map.
func (*Map[K, V]) MarshalJSON ¶
MarshalJSON marshals map into valid JSON. Ref: std json.Marshaler.
func (*Map[K, V]) Put ¶
func (m *Map[K, V]) Put(k K, v V)
Put adds the key-value pair (k, v) to map.
func (*Map[K, V]) Range ¶
func (m *Map[K, V]) Range(f func(k K, v V))
Range calls f for each key-value pair present in map.
func (*Map[K, V]) Remove ¶
func (m *Map[K, V]) Remove(k K)
Remove removes the given key k and the corresponding value if exists in map. If there is no such key and value found in map, do nothing.
func (*Map[K, V]) UnmarshalJSON ¶
UnmarshalJSON unmarshals a JSON description of map. The input can be assumed to be a valid encoding of a JSON value. UnmarshalJSON must copy the JSON data if it wishes to retain the data after returning. Ref: std json.Unmarshaler.