hashmap

package
v0.0.0-...-749c54f Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package hashmap wraps the Go built-in map and provides a more intuitive API. It is safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashMap

type HashMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

HashMap is a generic hash table (map).

func Collect

func Collect[K comparable, V any](seq iter.Seq2[K, V]) *HashMap[K, V]

Collect collects key-value pairs from an iterator and returns a new map.

func New

func New[K comparable, V any]() *HashMap[K, V]

New creates and initialize a new HashMap.

func (*HashMap[K, V]) All

func (m *HashMap[K, V]) All() iter.Seq2[K, V]

All returns an iterator over key-value pairs in the map. The iteration order is unspecified and not guaranteed to remain the same between calls.

The iterator must not modify the map to avoid deadlock.

func (*HashMap[K, V]) Clear

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

Clear removes all key-value pairs from the map.

func (*HashMap[K, V]) Contains

func (m *HashMap[K, V]) Contains(key K) bool

Contains reports whether the map contains the key.

func (*HashMap[K, V]) Empty

func (m *HashMap[K, V]) Empty() bool

Empty reports whether the map is empty.

func (*HashMap[K, V]) Get

func (m *HashMap[K, V]) Get(key K) (V, bool)

Get retrieves the value associated with the key. If the key does not exist, it returns the zero value of the value type and false.

func (*HashMap[K, V]) Insert

func (m *HashMap[K, V]) Insert(key K, value V)

Insert inserts a key-value pair into the map.

If the map does not contain the key, it will be added.

If the map already contains the key, the value will be updated.

func (*HashMap[K, V]) Keys

func (m *HashMap[K, V]) Keys() iter.Seq[K]

Keys returns an iterator over keys in the map. The iteration order is unspecified and not guaranteed to remain the same between calls.

The iterator must not modify the map to avoid deadlock.

func (*HashMap[K, V]) Len

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

Len returns the number of key-value pairs in the map.

func (*HashMap[K, V]) Remove

func (m *HashMap[K, V]) Remove(key K)

Remove removes the key-value pair from the map. If the key does not exist, this is a no-op.

func (*HashMap[K, V]) Values

func (m *HashMap[K, V]) Values() iter.Seq[V]

Values returns an iterator over values in the map. The iteration order is unspecified and not guaranteed to remain the same between calls.

The iterator must not modify the map to avoid deadlock.

Jump to

Keyboard shortcuts

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