hashmap

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: BSD-2-Clause, ISC Imports: 4 Imported by: 0

Documentation

Overview

Package hashmap implements a map backed by a hash table.

Elements are unordered in the map.

Structure is not thread safe.

Reference: http://en.wikipedia.org/wiki/Associative_array

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 holds the elements in go's native map

func New

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

New instantiates a hash map.

func (*Map[K, V]) Clear

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

Clear removes all elements from the map.

func (*Map[K, V]) Empty

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

Empty returns true if map does not contain any elements

func (*Map[K, V]) FromJSON

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

FromJSON populates the map from the input JSON representation.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (value V, found bool)

Get searches the element in the map by key and returns its value or nil if key is not found in map. Second return parameter is true if key was found, otherwise false.

func (*Map[K, V]) Keys

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

Keys returns all keys (random order).

func (*Map[K, V]) MarshalJSON

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

MarshalJSON @implements json.Marshaler

func (*Map[K, V]) Put

func (m *Map[K, V]) Put(key K, value V)

Put inserts element into the map.

func (*Map[K, V]) Remove

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

Remove removes the element from the map by key.

func (*Map[K, V]) Size

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

Size returns number of elements in the map.

func (*Map[K, V]) String

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

String returns a string representation of container

func (*Map[K, V]) ToJSON

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

ToJSON outputs the JSON representation of the map.

func (*Map[K, V]) UnmarshalJSON

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

UnmarshalJSON @implements json.Unmarshaler

func (*Map[K, V]) Values

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

Values returns all values (random order).

Jump to

Keyboard shortcuts

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