Documentation ¶
Overview ¶
Package cherryMap file from https://github.com/gogf/gf
Index ¶
- type Map
- func (p *Map[K, V]) Clear()
- func (p *Map[K, V]) Empty() bool
- func (p *Map[K, V]) Get(key K) (V, bool)
- func (p *Map[K, V]) Keys() []K
- func (p *Map[K, V]) Put(key K, value V)
- func (p *Map[K, V]) Remove(key K) (V, bool)
- func (p *Map[K, V]) Size() int
- func (p *Map[K, V]) String() string
- func (p *Map[K, V]) Values() []V
- type StringAnyMap
- func (m *StringAnyMap) Clear()
- func (m *StringAnyMap) Clone() *StringAnyMap
- func (m *StringAnyMap) Contains(key string) bool
- func (m *StringAnyMap) FilterEmpty()
- func (m *StringAnyMap) FilterNil()
- func (m *StringAnyMap) Get(key string) (value interface{})
- func (m *StringAnyMap) GetOrSet(key string, value interface{}) interface{}
- func (m *StringAnyMap) GetOrSetFunc(key string, f func() interface{}) interface{}
- func (m *StringAnyMap) GetOrSetFuncLock(key string, f func() interface{}) interface{}
- func (m *StringAnyMap) GetVar(key string) interface{}
- func (m *StringAnyMap) GetVarOrSet(key string, value interface{}) interface{}
- func (m *StringAnyMap) GetVarOrSetFunc(key string, f func() interface{}) interface{}
- func (m *StringAnyMap) GetVarOrSetFuncLock(key string, f func() interface{}) interface{}
- func (m *StringAnyMap) IsEmpty() bool
- func (m *StringAnyMap) Iterator(f func(k string, v interface{}) bool)
- func (m *StringAnyMap) Keys() []string
- func (m *StringAnyMap) LockFunc(f func(m map[string]interface{}))
- func (m *StringAnyMap) Map() map[string]interface{}
- func (m *StringAnyMap) MapCopy() map[string]interface{}
- func (m *StringAnyMap) MapStrAny() map[string]interface{}
- func (m *StringAnyMap) MarshalJSON() ([]byte, error)
- func (m *StringAnyMap) Merge(other *StringAnyMap)
- func (m *StringAnyMap) Pop() (key string, value interface{})
- func (m *StringAnyMap) Pops(size int) map[string]interface{}
- func (m *StringAnyMap) RLockFunc(f func(m map[string]interface{}))
- func (m *StringAnyMap) Remove(key string) (value interface{})
- func (m *StringAnyMap) Removes(keys []string)
- func (m *StringAnyMap) Replace(data map[string]interface{})
- func (m *StringAnyMap) Search(key string) (value interface{}, found bool)
- func (m *StringAnyMap) Set(key string, val interface{})
- func (m *StringAnyMap) SetIfNotExist(key string, value interface{}) bool
- func (m *StringAnyMap) SetIfNotExistFunc(key string, f func() interface{}) bool
- func (m *StringAnyMap) SetIfNotExistFuncLock(key string, f func() interface{}) bool
- func (m *StringAnyMap) Sets(data map[string]interface{})
- func (m *StringAnyMap) Size() int
- func (m *StringAnyMap) String() string
- func (m *StringAnyMap) UnmarshalJSON(b []byte) error
- func (m *StringAnyMap) Values() []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶ added in v1.3.0
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map 泛型map,可加锁
type StringAnyMap ¶
type StringAnyMap struct {
// contains filtered or unexported fields
}
func NewStrAnyMap ¶
func NewStrAnyMap() *StringAnyMap
NewStrAnyMap returns an empty StrAnyMap object. The parameter <safe> is used to specify whether using map in concurrent-safety, which is false in default.
func NewStrAnyMapFrom ¶
func NewStrAnyMapFrom(data map[string]interface{}) *StringAnyMap
NewStrAnyMapFrom creates and returns a hash map from given map <data>. Note that, the param <data> map will be set as the underlying data map(no deep copy), there might be some concurrent-safe issues when changing the map outside.
func (*StringAnyMap) Clear ¶
func (m *StringAnyMap) Clear()
Clear deletes all data of the map, it will remake a new underlying data map.
func (*StringAnyMap) Clone ¶
func (m *StringAnyMap) Clone() *StringAnyMap
Clone returns a new hash map with copy of current map data.
func (*StringAnyMap) Contains ¶
func (m *StringAnyMap) Contains(key string) bool
Contains checks whether a key exists. It returns true if the <key> exists, or else false.
func (*StringAnyMap) FilterEmpty ¶
func (m *StringAnyMap) 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 (*StringAnyMap) FilterNil ¶
func (m *StringAnyMap) FilterNil()
FilterNil deletes all key-value pair of which the value is nil.
func (*StringAnyMap) Get ¶
func (m *StringAnyMap) Get(key string) (value interface{})
Get returns the value by given <key>.
func (*StringAnyMap) GetOrSet ¶
func (m *StringAnyMap) GetOrSet(key string, value interface{}) interface{}
GetOrSet returns the value by key, or sets value with given <value> if it does not exist and then returns this value.
func (*StringAnyMap) GetOrSetFunc ¶
func (m *StringAnyMap) GetOrSetFunc(key string, f func() interface{}) interface{}
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 (*StringAnyMap) GetOrSetFuncLock ¶
func (m *StringAnyMap) GetOrSetFuncLock(key string, f func() interface{}) interface{}
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 (*StringAnyMap) GetVar ¶
func (m *StringAnyMap) GetVar(key string) interface{}
GetVar returns a Var with the value by given <key>. The returned Var is un-concurrent safe.
func (*StringAnyMap) GetVarOrSet ¶
func (m *StringAnyMap) GetVarOrSet(key string, value interface{}) interface{}
GetVarOrSet returns a Var with result from GetVarOrSet. The returned Var is un-concurrent safe.
func (*StringAnyMap) GetVarOrSetFunc ¶
func (m *StringAnyMap) GetVarOrSetFunc(key string, f func() interface{}) interface{}
GetVarOrSetFunc returns a Var with result from GetOrSetFunc. The returned Var is un-concurrent safe.
func (*StringAnyMap) GetVarOrSetFuncLock ¶
func (m *StringAnyMap) GetVarOrSetFuncLock(key string, f func() interface{}) interface{}
GetVarOrSetFuncLock returns a Var with result from GetOrSetFuncLock. The returned Var is un-concurrent safe.
func (*StringAnyMap) IsEmpty ¶
func (m *StringAnyMap) IsEmpty() bool
IsEmpty checks whether the map is empty. It returns true if map is empty, or else false.
func (*StringAnyMap) Iterator ¶
func (m *StringAnyMap) Iterator(f func(k string, v interface{}) 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 (*StringAnyMap) Keys ¶
func (m *StringAnyMap) Keys() []string
Keys returns all keys of the map as a slice.
func (*StringAnyMap) LockFunc ¶
func (m *StringAnyMap) LockFunc(f func(m map[string]interface{}))
LockFunc locks writing with given callback function <f> within RWMutex.Lock.
func (*StringAnyMap) Map ¶
func (m *StringAnyMap) Map() map[string]interface{}
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 (*StringAnyMap) MapCopy ¶
func (m *StringAnyMap) MapCopy() map[string]interface{}
MapCopy returns a copy of the underlying data of the hash map.
func (*StringAnyMap) MapStrAny ¶
func (m *StringAnyMap) MapStrAny() map[string]interface{}
MapStrAny returns a copy of the underlying data of the map as map[string]interface{}.
func (*StringAnyMap) MarshalJSON ¶
func (m *StringAnyMap) MarshalJSON() ([]byte, error)
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*StringAnyMap) Merge ¶
func (m *StringAnyMap) Merge(other *StringAnyMap)
Merge merges two hash maps. The <other> map will be merged into the map <m>.
func (*StringAnyMap) Pop ¶
func (m *StringAnyMap) Pop() (key string, value interface{})
Pop retrieves and deletes an item from the map.
func (*StringAnyMap) Pops ¶
func (m *StringAnyMap) Pops(size int) map[string]interface{}
Pops retrieves and deletes <size> items from the map. It returns all items if size == -1.
func (*StringAnyMap) RLockFunc ¶
func (m *StringAnyMap) RLockFunc(f func(m map[string]interface{}))
RLockFunc locks reading with given callback function <f> within RWMutex.RLock.
func (*StringAnyMap) Remove ¶
func (m *StringAnyMap) Remove(key string) (value interface{})
Remove deletes value from map by given <key>, and return this deleted value.
func (*StringAnyMap) Removes ¶
func (m *StringAnyMap) Removes(keys []string)
Removes batch deletes values of the map by keys.
func (*StringAnyMap) Replace ¶
func (m *StringAnyMap) Replace(data map[string]interface{})
Replace the data of the map with given <data>.
func (*StringAnyMap) Search ¶
func (m *StringAnyMap) Search(key string) (value interface{}, found bool)
Search searches the map with given <key>. Second return parameter <found> is true if key was found, otherwise false.
func (*StringAnyMap) Set ¶
func (m *StringAnyMap) Set(key string, val interface{})
Set sets key-value to the hash map.
func (*StringAnyMap) SetIfNotExist ¶
func (m *StringAnyMap) SetIfNotExist(key string, value interface{}) 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 (*StringAnyMap) SetIfNotExistFunc ¶
func (m *StringAnyMap) SetIfNotExistFunc(key string, 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 (*StringAnyMap) SetIfNotExistFuncLock ¶
func (m *StringAnyMap) SetIfNotExistFuncLock(key string, 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 (*StringAnyMap) Sets ¶
func (m *StringAnyMap) Sets(data map[string]interface{})
Sets batch sets key-values to the hash map.
func (*StringAnyMap) String ¶
func (m *StringAnyMap) String() string
String returns the map as a string.
func (*StringAnyMap) UnmarshalJSON ¶
func (m *StringAnyMap) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*StringAnyMap) Values ¶
func (m *StringAnyMap) Values() []interface{}
Values returns all values of the map as a slice.