mapz

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Keys added in v0.0.13

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

Keys returns all keys of the map.

func PopEncode

func PopEncode(str string) string

PopEncode encodes the string for pop

func Values added in v0.0.13

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

Values returns all values of the map.

Types

type Body

type Body map[string]any

Body is a map[string]any

func (Body) CleanPayload

func (b Body) CleanPayload()

CleanPayload cleans the payload

func (Body) QueryBytes

func (b Body) QueryBytes(valueEncode func(string) string) []byte

QueryBytes returns the query bytes

func (Body) QueryString

func (b Body) QueryString(valueEncode func(string) string) string

QueryString returns the query string

func (Body) Read

func (b Body) Read(p []byte) (n int, err error)

Read reads the body as bytes.Reader

type KV added in v0.0.15

type KV[K comparable, V any] map[K]V

func (KV[K, V]) Delete added in v0.0.15

func (m KV[K, V]) Delete(keys ...K)

Delete deletes the value associated with the key.

func (KV[K, V]) Get added in v0.0.15

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

Get returns the value associated with the key and whether the key existed or not.

func (KV[K, V]) Has added in v0.0.15

func (m KV[K, V]) Has(key K) bool

Has returns whether the key exists.

func (KV[K, V]) Keys added in v0.0.15

func (m KV[K, V]) Keys() []K

Keys returns all the keys.

func (KV[K, V]) Len added in v0.0.15

func (m KV[K, V]) Len() int

Len returns the number of items.

func (KV[K, V]) Range added in v0.0.15

func (m KV[K, V]) Range(fn func(key K, value V) bool)

Range calls fn sequentially for each key and value present in the map.

func (KV[K, V]) Set added in v0.0.15

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

Set sets the value associated with the key.

func (KV[K, V]) SetNx added in v0.0.15

func (m KV[K, V]) SetNx(key K, value V) bool

SetNx sets the value associated with the key if the key does not exist.

func (KV[K, V]) SetX added in v0.0.15

func (m KV[K, V]) SetX(key K, value V) bool

SetX sets the value associated with the key if the key exists.

func (KV[K, V]) Values added in v0.0.15

func (m KV[K, V]) Values() []V

Values returns all the values.

type SafeKV

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

SafeKV is a thread-safe map

func NewSafeKV

func NewSafeKV[K comparable, V any](cap int) *SafeKV[K, V]

NewSafeKV creates a new SafeKV

func (*SafeKV[K, V]) Clear

func (s *SafeKV[K, V]) Clear()

Clear clears the map

func (*SafeKV[K, V]) Delete

func (s *SafeKV[K, V]) Delete(keys ...K)

Delete deletes the value associated with the key

func (*SafeKV[K, V]) Get

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

Get returns the value associated with the key and whether the key existed

func (*SafeKV[K, V]) GetWithLock added in v0.0.15

func (s *SafeKV[K, V]) GetWithLock(key K, fn func(V))

GetWithLock calls fn with the value associated with the key if the key existed

func (*SafeKV[K, V]) GetWithMap added in v0.0.15

func (s *SafeKV[K, V]) GetWithMap(m map[K]V)

GetWithMap returns the value associated with the key and whether the key existed

func (*SafeKV[K, V]) Has added in v0.0.15

func (s *SafeKV[K, V]) Has(key K) bool

Has returns whether the key exists

func (*SafeKV[K, V]) Keys added in v0.0.15

func (s *SafeKV[K, V]) Keys() []K

Keys returns all the keys

func (*SafeKV[K, V]) Len

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

Len returns the length of the map

func (*SafeKV[K, V]) Map

func (s *SafeKV[K, V]) Map(fn func(KV[K, V]))

Map calls fn with the map

func (*SafeKV[K, V]) Range

func (s *SafeKV[K, V]) Range(fn func(key K, value V) bool)

Range calls fn sequentially for each key and value present in the map.

func (*SafeKV[K, V]) Set

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

Set sets the value associated with the key

func (*SafeKV[K, V]) SetNx

func (s *SafeKV[K, V]) SetNx(key K, value V) bool

SetNx sets the value associated with the key if the key does not exist

func (*SafeKV[K, V]) SetX

func (s *SafeKV[K, V]) SetX(key K, value V) bool

SetX sets the value associated with the key if the key exists

func (*SafeKV[K, V]) Values added in v0.0.15

func (s *SafeKV[K, V]) Values() []V

Values returns all the values

Jump to

Keyboard shortcuts

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