gmap

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package empty provides checks for empty variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmpty

func IsEmpty(value interface{}) bool

IsEmpty checks whether given <value> empty. It returns true if <value> is in: 0, nil, false, "", len(slice/map/chan) == 0, or else it returns false.

func IsNil

func IsNil(value interface{}) bool

IsNil checks whether given <value> is nil. Note that it might use reflect feature which affects performance a little bit.

Types

type StrAnyMap

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

func NewStrAnyMap

func NewStrAnyMap(safe ...bool) *StrAnyMap

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{}, safe ...bool) *StrAnyMap

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 (*StrAnyMap) Clear

func (m *StrAnyMap) Clear()

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

func (*StrAnyMap) Clone

func (m *StrAnyMap) Clone() *StrAnyMap

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

func (*StrAnyMap) Contains

func (m *StrAnyMap) Contains(key string) bool

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

func (*StrAnyMap) FilterEmpty

func (m *StrAnyMap) FilterEmpty()

FilterEmpty deletes all key-value pair of which the value is empty.

func (*StrAnyMap) Get

func (m *StrAnyMap) Get(key string) (value interface{})

Get returns the value by given <key>.

func (*StrAnyMap) GetOrSet

func (m *StrAnyMap) 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 (*StrAnyMap) GetOrSetFunc

func (m *StrAnyMap) 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 (*StrAnyMap) GetOrSetFuncLock

func (m *StrAnyMap) 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 (*StrAnyMap) IsEmpty

func (m *StrAnyMap) IsEmpty() bool

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

func (*StrAnyMap) Iterator

func (m *StrAnyMap) 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 (*StrAnyMap) Keys

func (m *StrAnyMap) Keys() []string

Keys returns all keys of the map as a slice.

func (*StrAnyMap) LockFunc

func (m *StrAnyMap) LockFunc(f func(m map[string]interface{}))

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

func (*StrAnyMap) Map

func (m *StrAnyMap) 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 (*StrAnyMap) MapCopy

func (m *StrAnyMap) MapCopy() map[string]interface{}

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

func (*StrAnyMap) MapStrAny

func (m *StrAnyMap) MapStrAny() map[string]interface{}

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

func (*StrAnyMap) MarshalJSON

func (m *StrAnyMap) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*StrAnyMap) Merge

func (m *StrAnyMap) Merge(other *StrAnyMap)

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

func (*StrAnyMap) Pop

func (m *StrAnyMap) Pop() (key string, value interface{})

Pop retrieves and deletes an item from the map.

func (*StrAnyMap) Pops

func (m *StrAnyMap) Pops(size int) map[string]interface{}

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

func (*StrAnyMap) RLockFunc

func (m *StrAnyMap) RLockFunc(f func(m map[string]interface{}))

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

func (*StrAnyMap) Remove

func (m *StrAnyMap) Remove(key string) (value interface{})

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

func (*StrAnyMap) Removes

func (m *StrAnyMap) Removes(keys []string)

Removes batch deletes values of the map by keys.

func (*StrAnyMap) Replace

func (m *StrAnyMap) Replace(data map[string]interface{})

Replace the data of the map with given <data>.

func (*StrAnyMap) Search

func (m *StrAnyMap) 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 (*StrAnyMap) Set

func (m *StrAnyMap) Set(key string, val interface{})

Set sets key-value to the hash map.

func (*StrAnyMap) SetIfNotExist

func (m *StrAnyMap) 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 (*StrAnyMap) SetIfNotExistFunc

func (m *StrAnyMap) 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 (*StrAnyMap) SetIfNotExistFuncLock

func (m *StrAnyMap) 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 (*StrAnyMap) Sets

func (m *StrAnyMap) Sets(data map[string]interface{})

Sets batch sets key-values to the hash map.

func (*StrAnyMap) Size

func (m *StrAnyMap) Size() int

Size returns the size of the map.

func (*StrAnyMap) UnmarshalJSON

func (m *StrAnyMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*StrAnyMap) Values

func (m *StrAnyMap) 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