kmap

package
v0.2.111 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashMap

type HashMap[TK string | int | int64, TD any] struct {
	// contains filtered or unexported fields
}

func New

func New[TK string | int | int64, TD any](safe ...bool) *HashMap[TK, TD]

func NewFrom

func NewFrom[TK string | int | int64, TD any](mapData map[TK]TD, safe ...bool) *HashMap[TK, TD]

func (*HashMap[TK, TD]) Clear

func (m *HashMap[TK, TD]) Clear()

Clear deletes all data of the map, it will remake a new underlying data map.

func (*HashMap[TK, TD]) Clone

func (m *HashMap[TK, TD]) Clone(safe ...bool) *HashMap[TK, TD]

Clone returns a new hash map with copy of current map data.

func (*HashMap[TK, TD]) Contains

func (m *HashMap[TK, TD]) Contains(key TK) bool

Contains checks whether a key exists. It returns true if the `key` exists, or else false.

func (*HashMap[TK, TD]) DeepCopy

func (m *HashMap[TK, TD]) DeepCopy() *HashMap[TK, TD]

DeepCopy implements interface for deep copy of current type.

func (*HashMap[TK, TD]) FilterEmpty

func (m *HashMap[TK, TD]) FilterEmpty()

FilterEmpty deletes all key-value pair of which the value is empty. Values like: 0, nil, false, "", len(slice/map/chan) == 0 are considered empty.

func (*HashMap[TK, TD]) FilterNil

func (m *HashMap[TK, TD]) FilterNil()

FilterNil deletes all key-value pair of which the value is nil.

func (*HashMap[TK, TD]) Get

func (m *HashMap[TK, TD]) Get(key TK) (value TD)

Get returns the value by given `key`.

func (*HashMap[TK, TD]) GetOrSet

func (m *HashMap[TK, TD]) GetOrSet(key TK, value TD) TD

GetOrSet returns the value by key, or sets value with given `value` if it does not exist and then returns this value.

func (*HashMap[TK, TD]) GetOrSetFunc

func (m *HashMap[TK, TD]) GetOrSetFunc(key TK, f func() TD) TD

GetOrSetFunc returns the value by key, or sets value with returned value of callback function `f` if it does not exist and then returns this value.

func (*HashMap[TK, TD]) GetOrSetFuncLock

func (m *HashMap[TK, TD]) GetOrSetFuncLock(key TK, f func() TD) TD

GetOrSetFuncLock returns the value by key, or sets value with returned value of callback function `f` if it does not exist and then returns this value.

GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function `f` with mutex.Lock of the hash map.

func (*HashMap[TK, TD]) IsEmpty

func (m *HashMap[TK, TD]) IsEmpty() bool

IsEmpty checks whether the map is empty. It returns true if map is empty, or else false.

func (*HashMap[TK, TD]) Iterator

func (m *HashMap[TK, TD]) Iterator(f func(k TK, v TD) bool)

Iterator iterates the hash map readonly with custom callback function `f`. If `f` returns true, then it continues iterating; or false to stop.

func (*HashMap[TK, TD]) Keys

func (m *HashMap[TK, TD]) Keys() []TK

Keys returns all keys of the map as a slice.

func (*HashMap[TK, TD]) LockFunc

func (m *HashMap[TK, TD]) LockFunc(f func(m map[TK]TD))

LockFunc locks writing with given callback function `f` within RWMutex.Lock.

func (*HashMap[TK, TD]) Map

func (m *HashMap[TK, TD]) Map() map[TK]TD

Map returns the underlying data map. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.

func (*HashMap[TK, TD]) MapCopy

func (m *HashMap[TK, TD]) MapCopy() map[TK]TD

MapCopy returns a shallow copy of the underlying data of the hash map.

func (*HashMap[TK, TD]) MapStrAny

func (m *HashMap[TK, TD]) MapStrAny() map[string]interface{}

MapStrAny returns a copy of the underlying data of the map as map[string]interface{}.

func (HashMap[TK, TD]) MarshalJSON

func (m HashMap[TK, TD]) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*HashMap[TK, TD]) Merge

func (m *HashMap[TK, TD]) Merge(other *HashMap[TK, TD])

Merge merges two hash maps. The `other` map will be merged into the map `m`.

func (*HashMap[TK, TD]) Pop

func (m *HashMap[TK, TD]) Pop() (key TK, value TD)

Pop retrieves and deletes an item from the map.

func (*HashMap[TK, TD]) Pops

func (m *HashMap[TK, TD]) Pops(size int) map[TK]TD

Pops retrieves and deletes `size` items from the map. It returns all items if size == -1.

func (*HashMap[TK, TD]) RLockFunc

func (m *HashMap[TK, TD]) RLockFunc(f func(m map[TK]TD))

RLockFunc locks reading with given callback function `f` within RWMutex.RLock.

func (*HashMap[TK, TD]) Remove

func (m *HashMap[TK, TD]) Remove(key TK) (value TD)

Remove deletes value from map by given `key`, and return this deleted value.

func (*HashMap[TK, TD]) Removes

func (m *HashMap[TK, TD]) Removes(keys []TK)

Removes batch deletes values of the map by keys.

func (*HashMap[TK, TD]) Replace

func (m *HashMap[TK, TD]) Replace(data map[TK]TD)

Replace the data of the map with given `data`.

func (*HashMap[TK, TD]) Search

func (m *HashMap[TK, TD]) Search(key TK) (value TD, found bool)

Search searches the map with given `key`. Second return parameter `found` is true if key was found, otherwise false.

func (*HashMap[TK, TD]) Set

func (m *HashMap[TK, TD]) Set(key TK, value TD)

Set sets key-value to the hash map.

func (*HashMap[TK, TD]) SetIfNotExist

func (m *HashMap[TK, TD]) SetIfNotExist(key TK, value TD) bool

SetIfNotExist sets `value` to the map if the `key` does not exist, and then returns true. It returns false if `key` exists, and `value` would be ignored.

func (*HashMap[TK, TD]) SetIfNotExistFunc

func (m *HashMap[TK, TD]) SetIfNotExistFunc(key TK, f func() interface{}) bool

SetIfNotExistFunc sets value with return value of callback function `f`, and then returns true. It returns false if `key` exists, and `value` would be ignored.

func (*HashMap[TK, TD]) SetIfNotExistFuncLock

func (m *HashMap[TK, TD]) SetIfNotExistFuncLock(key TK, f func() interface{}) bool

SetIfNotExistFuncLock sets value with return value of callback function `f`, and then returns true. It returns false if `key` exists, and `value` would be ignored.

SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that it executes function `f` with mutex.Lock of the hash map.

func (*HashMap[TK, TD]) Sets

func (m *HashMap[TK, TD]) Sets(data map[TK]TD)

Sets batch sets key-values to the hash map.

func (*HashMap[TK, TD]) Size

func (m *HashMap[TK, TD]) Size() int

Size returns the size of the map.

func (*HashMap[TK, TD]) String

func (m *HashMap[TK, TD]) String() string

String returns the map as a string.

func (*HashMap[TK, TD]) UnmarshalJSON

func (m *HashMap[TK, TD]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*HashMap[TK, TD]) UnmarshalValue

func (m *HashMap[TK, TD]) UnmarshalValue(value *HashMap[TK, TD]) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*HashMap[TK, TD]) Values

func (m *HashMap[TK, TD]) Values() []TD

Values returns all values of the map as a slice.

Jump to

Keyboard shortcuts

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