maps

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

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

Copy return a copy of given map

func Filter added in v1.9.0

func Filter[K comparable, V any](m map[K]V, fn func(K, V) bool) map[K]V

Filter functional filter for map items

func From added in v1.9.0

func From[T any, K comparable, V any](arr []T, fn func(T) (K, V)) map[K]V

From create a map from array

func Keys

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

Keys return the arr of keys in the given map

func Map

func Map[K comparable, U any, V any](m map[K]U, fn func(U) V) map[K]V

Map functional conversion for map items

func Values

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

Values return the arr of values in the given map

Types

type SyncMap

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

SyncMap defines the thread-safe map

func NewSyncMap

func NewSyncMap[K comparable, V any]() *SyncMap[K, V]

NewSyncMap create a new SyncMap

func NewSyncMapFrom

func NewSyncMapFrom[K comparable, V any](in map[K]V) *SyncMap[K, V]

NewSyncMapFrom create a new SyncMap from existing map. The data is copied instead of directly referring to the given map.

func (*SyncMap[K, V]) Data added in v1.9.0

func (in *SyncMap[K, V]) Data() map[K]V

Data return a full copy of underlying

func (*SyncMap[K, V]) Del

func (in *SyncMap[K, V]) Del(key K)

Del delete the value for the given key

func (*SyncMap[K, V]) Get

func (in *SyncMap[K, V]) Get(key K) (V, bool)

Get return the value for the given key

func (*SyncMap[K, V]) Keys

func (in *SyncMap[K, V]) Keys() []K

Keys return a copy of keys

func (*SyncMap[K, V]) Load

func (in *SyncMap[K, V]) Load(m map[K]V)

Load function for reset the underlying map, copies all data from the given map

func (*SyncMap[K, V]) Range

func (in *SyncMap[K, V]) Range(f func(K, V))

Range function for ranging over the map, it uses RLock during ranging

func (*SyncMap[K, V]) Set

func (in *SyncMap[K, V]) Set(key K, val V)

Set the value for the given key

func (*SyncMap[K, V]) Values

func (in *SyncMap[K, V]) Values() []V

Values return a copy of values

Jump to

Keyboard shortcuts

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