safemap

package module
v0.0.0-...-423f686 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

safemap

go 泛型 + map

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyID

type KeyID interface {
	ToUint32() uint32
}

type SafeMap

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

func New

func New[K comparable, V any](shard ...uint32) *SafeMap[K, V]

New

func (*SafeMap[K, V]) Del

func (s *SafeMap[K, V]) Del(key K)

Del deletes the value for key.

func (*SafeMap[K, V]) Exist

func (s *SafeMap[K, V]) Exist(key K) bool

Exist returns true if key exists.

func (*SafeMap[K, V]) FromMap

func (s *SafeMap[K, V]) FromMap(m map[K]V)

FromMap flushes the map and loads the new map.

func (*SafeMap[K, V]) Get

func (s *SafeMap[K, V]) Get(key K) (V, bool)

Get returns the value associated with key.

func (*SafeMap[K, V]) GetOrSet

func (s *SafeMap[K, V]) GetOrSet(key K, value V) V

GetOrSet returns the value for the key if present, otherwise sets and returns the default value

func (*SafeMap[K, V]) Len

func (s *SafeMap[K, V]) Len() int

Len

func (*SafeMap[K, V]) Range

func (s *SafeMap[K, V]) Range(f func(K, V) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (*SafeMap[K, V]) Reset

func (s *SafeMap[K, V]) Reset()

Reset deletes all values.

func (*SafeMap[K, V]) Set

func (s *SafeMap[K, V]) Set(key K, value V)

Set sets the value for key.

func (*SafeMap[K, V]) ToMap

func (s *SafeMap[K, V]) ToMap() map[K]V

ToMap returns a copy of the map.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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