hashmap

package module
v0.0.0-...-ce82bb3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

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 {
	*vector.Vector[map[K]V]
	maphash.Hash
	// contains filtered or unexported fields
}

HashMap is a hash map data structure, using hash/maphash for key hashing.

func New

func New[K comparable, V any](loadFactor float32, capacity int) *HashMap[K, V]

New constructs a new HashMap

func (*HashMap[K, V]) Collect

func (m *HashMap[K, V]) Collect(pairs ...MapPair[K, V])

Collect inserts a variable number of key-value pairs into the hash map. This method implements part of the iterator.Collection interface.

func (HashMap[K, V]) Get

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

Get retrieves the value associated with a specified key. Returns nil, errors.NotFound if key does not exist.

func (*HashMap[K, V]) Iterator

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

Iterator returns an iterator over the key-value pairs in the hash map. This method implements part of the iterator.Collection interface.

func (*HashMap[K, V]) Set

func (m *HashMap[K, V]) Set(key K, val V) error

Set inserts a key value pair into the hash map, overwriting the value if the key already exists. Returns error on vector error.

type Iterator

type Iterator[K comparable, V any] struct {
	*HashMap[K, V]
}

func (*Iterator[K, V]) Next

func (i *Iterator[K, V]) Next() (*MapPair[K, V], error)

type MapPair

type MapPair[K, V any] struct {
	Key K
	Val V
}

MapPair is a key-value pair for the HashMap structure

Jump to

Keyboard shortcuts

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