Documentation ¶
Index ¶
- type HashMap
- func (m *HashMap[TK, TD]) Clear()
- func (m *HashMap[TK, TD]) Clone(safe ...bool) *HashMap[TK, TD]
- func (m *HashMap[TK, TD]) Contains(key TK) bool
- func (m *HashMap[TK, TD]) DeepCopy() *HashMap[TK, TD]
- func (m *HashMap[TK, TD]) FilterEmpty()
- func (m *HashMap[TK, TD]) FilterNil()
- func (m *HashMap[TK, TD]) Get(key TK) (value TD)
- func (m *HashMap[TK, TD]) GetOrSet(key TK, value TD) TD
- func (m *HashMap[TK, TD]) GetOrSetFunc(key TK, f func() TD) TD
- func (m *HashMap[TK, TD]) GetOrSetFuncLock(key TK, f func() TD) TD
- func (m *HashMap[TK, TD]) IsEmpty() bool
- func (m *HashMap[TK, TD]) Iterator(f func(k TK, v TD) bool)
- func (m *HashMap[TK, TD]) Keys() []TK
- func (m *HashMap[TK, TD]) LockFunc(f func(m map[TK]TD))
- func (m *HashMap[TK, TD]) Map() map[TK]TD
- func (m *HashMap[TK, TD]) MapCopy() map[TK]TD
- func (m *HashMap[TK, TD]) MapStrAny() map[string]interface{}
- func (m HashMap[TK, TD]) MarshalJSON() ([]byte, error)
- func (m *HashMap[TK, TD]) Merge(other *HashMap[TK, TD])
- func (m *HashMap[TK, TD]) Pop() (key TK, value TD)
- func (m *HashMap[TK, TD]) Pops(size int) map[TK]TD
- func (m *HashMap[TK, TD]) RLockFunc(f func(m map[TK]TD))
- func (m *HashMap[TK, TD]) Remove(key TK) (value TD)
- func (m *HashMap[TK, TD]) Removes(keys []TK)
- func (m *HashMap[TK, TD]) Replace(data map[TK]TD)
- func (m *HashMap[TK, TD]) Search(key TK) (value TD, found bool)
- func (m *HashMap[TK, TD]) Set(key TK, value TD)
- func (m *HashMap[TK, TD]) SetIfNotExist(key TK, value TD) bool
- func (m *HashMap[TK, TD]) SetIfNotExistFunc(key TK, f func() interface{}) bool
- func (m *HashMap[TK, TD]) SetIfNotExistFuncLock(key TK, f func() interface{}) bool
- func (m *HashMap[TK, TD]) Sets(data map[TK]TD)
- func (m *HashMap[TK, TD]) Size() int
- func (m *HashMap[TK, TD]) String() string
- func (m *HashMap[TK, TD]) UnmarshalJSON(b []byte) error
- func (m *HashMap[TK, TD]) UnmarshalValue(value *HashMap[TK, TD]) (err error)
- func (m *HashMap[TK, TD]) Values() []TD
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HashMap ¶
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]) Contains ¶
Contains checks whether a key exists. It returns true if the `key` exists, or else false.
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 ¶
IsEmpty checks whether the map is empty. It returns true if map is empty, or else false.
func (*HashMap[TK, TD]) Iterator ¶
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 ¶
MapStrAny returns a copy of the underlying data of the map as map[string]interface{}.
func (HashMap[TK, TD]) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*HashMap[TK, TD]) Merge ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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]) UnmarshalJSON ¶
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*HashMap[TK, TD]) UnmarshalValue ¶
UnmarshalValue is an interface implement which sets any type of value for map.