mapkit

package
v0.0.0-...-7b6962b Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[K comparable, V any](m *map[K]V, key K, value V) bool

func Clean

func Clean[K comparable, V any](m map[K]V)

func Each

func Each[K comparable, V any](m map[K]V, handler func(K, V))

func EachEx

func EachEx[K comparable, V any](m map[K]V, handler func(K, V) error) error

func First

func First[K cmp.Ordered, V any](m map[K]V) (key K, value V, ok bool)

func FirstKey

func FirstKey[K cmp.Ordered, V any](m map[K]V) (firstKey K, ok bool)

func Get

func Get[K comparable, V any](m map[K]V, key K) (V, bool)

func GetValue

func GetValue[K comparable, V any](m map[K]V, key K) V

func Keys

func Keys[M ~map[K]V, K comparable, V any](m M) []K

Keys returns the keys of the map m. The keys will be in an indeterminate order.

func MapToStruct

func MapToStruct(m map[string]any, v any) error

func Set

func Set[K comparable, V any](m *map[K]V, key K, value V)

func SortedKeys

func SortedKeys[K cmp.Ordered, V any](m map[K]V) []K

func SortedValues

func SortedValues[K cmp.Ordered, V any](m map[K]V) []V

func Values

func Values[M ~map[K]V, K comparable, V any](m M) []V

Values returns the values of the map m. The values will be in an indeterminate order.

Types

type Map

type Map[K comparable, V any] interface {
	Exists(K) bool
	Get(K) (V, bool)
	GetOrDefault(K, V) V
	Set(K, V)
	Del(K)
	Keys() []K
	Values() []V
	Size() int
}

Map

type MapEntry

type MapEntry[K comparable, V any] struct {
	Key   K
	Value V
}

common

type StableMap

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

StableMap 有序map,保持插入顺序; 零值可用

func (*StableMap[K, V]) Del

func (m *StableMap[K, V]) Del(key K)

func (*StableMap[K, V]) Exists

func (m *StableMap[K, V]) Exists(key K) bool

func (*StableMap[K, V]) Get

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

func (*StableMap[K, V]) GetOrDefault

func (m *StableMap[K, V]) GetOrDefault(key K, defaultValue V) V

func (*StableMap[K, V]) Keys

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

func (*StableMap[K, V]) Len

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

func (*StableMap[K, V]) Set

func (m *StableMap[K, V]) Set(key K, value V)

func (*StableMap[K, V]) Size

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

func (*StableMap[K, V]) Values

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

Jump to

Keyboard shortcuts

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