cherryMap

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cherryMap file from https://github.com/beego/beego/blob/develop/core/utils/safemap.go

Package cherryMap file from https://github.com/gogf/gf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SafeMap

type SafeMap struct {
	// contains filtered or unexported fields
}

SafeMap is a map with lock

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap return new SafeMap

func (*SafeMap) Check

func (m *SafeMap) Check(k interface{}) bool

Check Returns true if k is exist in the map.

func (*SafeMap) Count

func (m *SafeMap) Count() int

Count returns the number of items within the map.

func (*SafeMap) Delete

func (m *SafeMap) Delete(k interface{})

Delete the given key and value.

func (*SafeMap) Get

func (m *SafeMap) Get(k interface{}) interface{}

Get from maps return the k's value

func (*SafeMap) Items

func (m *SafeMap) Items() map[interface{}]interface{}

Items returns all items in safemap.

func (*SafeMap) Set

func (m *SafeMap) Set(k interface{}, v interface{}) bool

Set Maps the given key and value. Returns false if the key is already in the map and changes nothing.

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) Size

func (m *StringAnyMap) Size() int

Size returns the size of the 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.

Jump to

Keyboard shortcuts

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