hashmap

package
v0.0.0-...-a479826 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package hashmap implements a map backed by a hash table.

Index

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]) Clear

func (m *Map[K, V]) Clear()

Clear removes all key-value pairs in map.

func (*Map[K, V]) Contains

func (m *Map[K, V]) Contains(k ...K) bool

Contains returns true if map contains all of the given keys k.

func (*Map[K, V]) ContainsAny

func (m *Map[K, V]) ContainsAny(k ...K) bool

Contains returns true if map contains any of the given keys k.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) (value V, ok bool)

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]) Keys

func (m *Map[K, V]) Keys() []K

Values returns all keys in map.

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

Len returns the number of entries of map m.

func (*Map[K, V]) MarshalJSON

func (m *Map[K, V]) MarshalJSON() ([]byte, error)

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]) String

func (m *Map[K, V]) String() string

String returns the string representation of map. Ref: std fmt.Stringer.

func (*Map[K, V]) UnmarshalJSON

func (m *Map[K, V]) UnmarshalJSON(data []byte) error

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.

func (*Map[K, V]) Values

func (m *Map[K, V]) Values() []V

Values returns all values in map.

func (*Map[K, V]) WithLock

func (m *Map[K, V]) WithLock() *Map[K, V]

WithLock adds sync.RWMutex to support concurrent use by multiple goroutines without additional locking or coordination.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL