gmap

package
v2.0.0-...-cbac34e Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gmap provides concurrent-safe/unsafe map containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyAnyMap

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

func NewAnyAnyMap

func NewAnyAnyMap(safe ...bool) *AnyAnyMap

NewAnyAnyMap returns an empty hash map. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewAnyAnyMapFrom

func NewAnyAnyMapFrom(data map[interface{}]interface{}, safe ...bool) *AnyAnyMap

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

func (m *AnyAnyMap) Clear()

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

func (*AnyAnyMap) Clone

func (m *AnyAnyMap) Clone(safe ...bool) *AnyAnyMap

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

func (*AnyAnyMap) Contains

func (m *AnyAnyMap) Contains(key interface{}) bool

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

func (*AnyAnyMap) Flip

func (m *AnyAnyMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*AnyAnyMap) Get

func (m *AnyAnyMap) Get(key interface{}) interface{}

Get returns the value by given <key>.

func (*AnyAnyMap) GetOrSet

func (m *AnyAnyMap) GetOrSet(key interface{}, value interface{}) interface{}

GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.

func (*AnyAnyMap) GetOrSetFunc

func (m *AnyAnyMap) GetOrSetFunc(key interface{}, f func() interface{}) interface{}

GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

func (*AnyAnyMap) GetOrSetFuncLock

func (m *AnyAnyMap) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}

GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

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

func (*AnyAnyMap) GetVar

func (m *AnyAnyMap) GetVar(key interface{}) *gvar.Var

GetVar returns a gvar.Var with the value by given <key>. The returned gvar.Var is un-concurrent safe.

func (*AnyAnyMap) GetVarOrSet

func (m *AnyAnyMap) GetVarOrSet(key interface{}, value interface{}) *gvar.Var

GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.

func (*AnyAnyMap) GetVarOrSetFunc

func (m *AnyAnyMap) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.

func (*AnyAnyMap) GetVarOrSetFuncLock

func (m *AnyAnyMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.

func (*AnyAnyMap) IsEmpty

func (m *AnyAnyMap) IsEmpty() bool

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

func (*AnyAnyMap) Iterator

func (m *AnyAnyMap) Iterator(f func(k interface{}, v interface{}) bool)

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

func (*AnyAnyMap) Keys

func (m *AnyAnyMap) Keys() []interface{}

Keys returns all keys of the map as a slice.

func (*AnyAnyMap) LockFunc

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

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

func (*AnyAnyMap) Map

func (m *AnyAnyMap) Map() map[interface{}]interface{}

Map returns a copy of the data of the hash map.

func (*AnyAnyMap) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*AnyAnyMap) Merge

func (m *AnyAnyMap) Merge(other *AnyAnyMap)

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

func (*AnyAnyMap) RLockFunc

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

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

func (*AnyAnyMap) Remove

func (m *AnyAnyMap) Remove(key interface{}) interface{}

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

func (*AnyAnyMap) Removes

func (m *AnyAnyMap) Removes(keys []interface{})

Removes batch deletes values of the map by keys.

func (*AnyAnyMap) Search

func (m *AnyAnyMap) Search(key interface{}) (value interface{}, found bool)

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

func (*AnyAnyMap) Set

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

Set sets key-value to the hash map.

func (*AnyAnyMap) SetIfNotExist

func (m *AnyAnyMap) SetIfNotExist(key interface{}, value interface{}) bool

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

func (*AnyAnyMap) SetIfNotExistFunc

func (m *AnyAnyMap) SetIfNotExistFunc(key interface{}, f func() interface{}) bool

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

func (*AnyAnyMap) SetIfNotExistFuncLock

func (m *AnyAnyMap) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool

SetIfNotExistFuncLock sets value with return value of callback function <f>, then return 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 (*AnyAnyMap) Sets

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

Sets batch sets key-values to the hash map.

func (*AnyAnyMap) Size

func (m *AnyAnyMap) Size() int

Size returns the size of the map.

func (*AnyAnyMap) Values

func (m *AnyAnyMap) Values() []interface{}

Values returns all values of the map as a slice.

type HashMap

type HashMap = AnyAnyMap

type IntAnyMap

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

func NewIntAnyMap

func NewIntAnyMap(safe ...bool) *IntAnyMap

NewIntAnyMap returns an empty IntAnyMap object. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewIntAnyMapFrom

func NewIntAnyMapFrom(data map[int]interface{}, safe ...bool) *IntAnyMap

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

func (m *IntAnyMap) Clear()

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

func (*IntAnyMap) Clone

func (m *IntAnyMap) Clone() *IntAnyMap

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

func (*IntAnyMap) Contains

func (m *IntAnyMap) Contains(key int) bool

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

func (*IntAnyMap) Flip

func (m *IntAnyMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*IntAnyMap) Get

func (m *IntAnyMap) Get(key int) interface{}

Get returns the value by given <key>.

func (*IntAnyMap) GetOrSet

func (m *IntAnyMap) GetOrSet(key int, value interface{}) interface{}

GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.

func (*IntAnyMap) GetOrSetFunc

func (m *IntAnyMap) GetOrSetFunc(key int, f func() interface{}) interface{}

GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

func (*IntAnyMap) GetOrSetFuncLock

func (m *IntAnyMap) GetOrSetFuncLock(key int, f func() interface{}) interface{}

GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

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

func (*IntAnyMap) GetVar

func (m *IntAnyMap) GetVar(key int) *gvar.Var

GetVar returns a gvar.Var with the value by given <key>. The returned gvar.Var is un-concurrent safe.

func (*IntAnyMap) GetVarOrSet

func (m *IntAnyMap) GetVarOrSet(key int, value interface{}) *gvar.Var

GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.

func (*IntAnyMap) GetVarOrSetFunc

func (m *IntAnyMap) GetVarOrSetFunc(key int, f func() interface{}) *gvar.Var

GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.

func (*IntAnyMap) GetVarOrSetFuncLock

func (m *IntAnyMap) GetVarOrSetFuncLock(key int, f func() interface{}) *gvar.Var

GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.

func (*IntAnyMap) IsEmpty

func (m *IntAnyMap) IsEmpty() bool

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

func (*IntAnyMap) Iterator

func (m *IntAnyMap) Iterator(f func(k int, v interface{}) bool)

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

func (*IntAnyMap) Keys

func (m *IntAnyMap) Keys() []int

Keys returns all keys of the map as a slice.

func (*IntAnyMap) LockFunc

func (m *IntAnyMap) LockFunc(f func(m map[int]interface{}))

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

func (*IntAnyMap) Map

func (m *IntAnyMap) Map() map[int]interface{}

Map returns a copy of the data of the hash map.

func (*IntAnyMap) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*IntAnyMap) Merge

func (m *IntAnyMap) Merge(other *IntAnyMap)

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

func (*IntAnyMap) RLockFunc

func (m *IntAnyMap) RLockFunc(f func(m map[int]interface{}))

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

func (*IntAnyMap) Remove

func (m *IntAnyMap) Remove(key int) interface{}

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

func (*IntAnyMap) Removes

func (m *IntAnyMap) Removes(keys []int)

Removes batch deletes values of the map by keys.

func (*IntAnyMap) Search

func (m *IntAnyMap) Search(key int) (value interface{}, found bool)

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

func (*IntAnyMap) Set

func (m *IntAnyMap) Set(key int, val interface{})

Set sets key-value to the hash map.

func (*IntAnyMap) SetIfNotExist

func (m *IntAnyMap) SetIfNotExist(key int, value interface{}) bool

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

func (*IntAnyMap) SetIfNotExistFunc

func (m *IntAnyMap) SetIfNotExistFunc(key int, f func() interface{}) bool

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

func (*IntAnyMap) SetIfNotExistFuncLock

func (m *IntAnyMap) SetIfNotExistFuncLock(key int, f func() interface{}) bool

SetIfNotExistFuncLock sets value with return value of callback function <f>, then return 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 (*IntAnyMap) Sets

func (m *IntAnyMap) Sets(data map[int]interface{})

Sets batch sets key-values to the hash map.

func (*IntAnyMap) Size

func (m *IntAnyMap) Size() int

Size returns the size of the map.

func (*IntAnyMap) Values

func (m *IntAnyMap) Values() []interface{}

Values returns all values of the map as a slice.

type IntIntMap

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

func NewIntIntMap

func NewIntIntMap(safe ...bool) *IntIntMap

NewIntIntMap returns an empty IntIntMap object. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewIntIntMapFrom

func NewIntIntMapFrom(data map[int]int, safe ...bool) *IntIntMap

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

func (m *IntIntMap) Clear()

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

func (*IntIntMap) Clone

func (m *IntIntMap) Clone() *IntIntMap

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

func (*IntIntMap) Contains

func (m *IntIntMap) Contains(key int) bool

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

func (*IntIntMap) Flip

func (m *IntIntMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*IntIntMap) Get

func (m *IntIntMap) Get(key int) int

Get returns the value by given <key>.

func (*IntIntMap) GetOrSet

func (m *IntIntMap) GetOrSet(key int, value int) int

GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.

func (*IntIntMap) GetOrSetFunc

func (m *IntIntMap) GetOrSetFunc(key int, f func() int) int

GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

func (*IntIntMap) GetOrSetFuncLock

func (m *IntIntMap) GetOrSetFuncLock(key int, f func() int) int

GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

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

func (*IntIntMap) IsEmpty

func (m *IntIntMap) IsEmpty() bool

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

func (*IntIntMap) Iterator

func (m *IntIntMap) Iterator(f func(k int, v int) bool)

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

func (*IntIntMap) Keys

func (m *IntIntMap) Keys() []int

Keys returns all keys of the map as a slice.

func (*IntIntMap) LockFunc

func (m *IntIntMap) LockFunc(f func(m map[int]int))

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

func (*IntIntMap) Map

func (m *IntIntMap) Map() map[int]int

Map returns a copy of the data of the hash map.

func (*IntIntMap) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*IntIntMap) Merge

func (m *IntIntMap) Merge(other *IntIntMap)

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

func (*IntIntMap) RLockFunc

func (m *IntIntMap) RLockFunc(f func(m map[int]int))

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

func (*IntIntMap) Remove

func (m *IntIntMap) Remove(key int) int

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

func (*IntIntMap) Removes

func (m *IntIntMap) Removes(keys []int)

Removes batch deletes values of the map by keys.

func (*IntIntMap) Search

func (m *IntIntMap) Search(key int) (value int, found bool)

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

func (*IntIntMap) Set

func (m *IntIntMap) Set(key int, val int)

Set sets key-value to the hash map.

func (*IntIntMap) SetIfNotExist

func (m *IntIntMap) SetIfNotExist(key int, value int) bool

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

func (*IntIntMap) SetIfNotExistFunc

func (m *IntIntMap) SetIfNotExistFunc(key int, f func() int) bool

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

func (*IntIntMap) SetIfNotExistFuncLock

func (m *IntIntMap) SetIfNotExistFuncLock(key int, f func() int) bool

SetIfNotExistFuncLock sets value with return value of callback function <f>, then return 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 (*IntIntMap) Sets

func (m *IntIntMap) Sets(data map[int]int)

Sets batch sets key-values to the hash map.

func (*IntIntMap) Size

func (m *IntIntMap) Size() int

Size returns the size of the map.

func (*IntIntMap) Values

func (m *IntIntMap) Values() []int

Values returns all values of the map as a slice.

type IntStrMap

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

func NewIntStrMap

func NewIntStrMap(safe ...bool) *IntStrMap

NewIntStrMap returns an empty IntStrMap object. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewIntStrMapFrom

func NewIntStrMapFrom(data map[int]string, safe ...bool) *IntStrMap

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

func (m *IntStrMap) Clear()

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

func (*IntStrMap) Clone

func (m *IntStrMap) Clone() *IntStrMap

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

func (*IntStrMap) Contains

func (m *IntStrMap) Contains(key int) bool

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

func (*IntStrMap) Flip

func (m *IntStrMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*IntStrMap) Get

func (m *IntStrMap) Get(key int) string

Get returns the value by given <key>.

func (*IntStrMap) GetOrSet

func (m *IntStrMap) GetOrSet(key int, value string) string

GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.

func (*IntStrMap) GetOrSetFunc

func (m *IntStrMap) GetOrSetFunc(key int, f func() string) string

GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

func (*IntStrMap) GetOrSetFuncLock

func (m *IntStrMap) GetOrSetFuncLock(key int, f func() string) string

GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

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

func (*IntStrMap) IsEmpty

func (m *IntStrMap) IsEmpty() bool

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

func (*IntStrMap) Iterator

func (m *IntStrMap) Iterator(f func(k int, v string) bool)

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

func (*IntStrMap) Keys

func (m *IntStrMap) Keys() []int

Keys returns all keys of the map as a slice.

func (*IntStrMap) LockFunc

func (m *IntStrMap) LockFunc(f func(m map[int]string))

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

func (*IntStrMap) Map

func (m *IntStrMap) Map() map[int]string

Map returns a copy of the data of the hash map.

func (*IntStrMap) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*IntStrMap) Merge

func (m *IntStrMap) Merge(other *IntStrMap)

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

func (*IntStrMap) RLockFunc

func (m *IntStrMap) RLockFunc(f func(m map[int]string))

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

func (*IntStrMap) Remove

func (m *IntStrMap) Remove(key int) string

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

func (*IntStrMap) Removes

func (m *IntStrMap) Removes(keys []int)

Removes batch deletes values of the map by keys.

func (*IntStrMap) Search

func (m *IntStrMap) Search(key int) (value string, found bool)

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

func (*IntStrMap) Set

func (m *IntStrMap) Set(key int, val string)

Set sets key-value to the hash map.

func (*IntStrMap) SetIfNotExist

func (m *IntStrMap) SetIfNotExist(key int, value string) bool

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

func (*IntStrMap) SetIfNotExistFunc

func (m *IntStrMap) SetIfNotExistFunc(key int, f func() string) bool

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

func (*IntStrMap) SetIfNotExistFuncLock

func (m *IntStrMap) SetIfNotExistFuncLock(key int, f func() string) bool

SetIfNotExistFuncLock sets value with return value of callback function <f>, then return 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 (*IntStrMap) Sets

func (m *IntStrMap) Sets(data map[int]string)

Sets batch sets key-values to the hash map.

func (*IntStrMap) Size

func (m *IntStrMap) Size() int

Size returns the size of the map.

func (*IntStrMap) Values

func (m *IntStrMap) Values() []string

Values returns all values of the map as a slice.

type ListMap

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

func NewListMap

func NewListMap(safe ...bool) *ListMap

NewListMap returns an empty link map. ListMap is backed by a hash table to store values and doubly-linked list to store ordering. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewListMapFrom

func NewListMapFrom(data map[interface{}]interface{}, safe ...bool) *ListMap

NewListMapFrom returns a link 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 (*ListMap) Clear

func (m *ListMap) Clear()

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

func (*ListMap) Clone

func (m *ListMap) Clone(safe ...bool) *ListMap

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

func (*ListMap) Contains

func (m *ListMap) Contains(key interface{}) (ok bool)

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

func (*ListMap) Flip

func (m *ListMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*ListMap) Get

func (m *ListMap) Get(key interface{}) (value interface{})

Get returns the value by given <key>.

func (*ListMap) GetOrSet

func (m *ListMap) GetOrSet(key interface{}, value interface{}) interface{}

GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.

func (*ListMap) GetOrSetFunc

func (m *ListMap) GetOrSetFunc(key interface{}, f func() interface{}) interface{}

GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

func (*ListMap) GetOrSetFuncLock

func (m *ListMap) GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}

GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

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

func (*ListMap) GetVar

func (m *ListMap) GetVar(key interface{}) *gvar.Var

GetVar returns a gvar.Var with the value by given <key>. The returned gvar.Var is un-concurrent safe.

func (*ListMap) GetVarOrSet

func (m *ListMap) GetVarOrSet(key interface{}, value interface{}) *gvar.Var

GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.

func (*ListMap) GetVarOrSetFunc

func (m *ListMap) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.

func (*ListMap) GetVarOrSetFuncLock

func (m *ListMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var

GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.

func (*ListMap) IsEmpty

func (m *ListMap) IsEmpty() bool

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

func (*ListMap) Iterator

func (m *ListMap) Iterator(f func(key, value interface{}) bool)

Iterator is alias of IteratorAsc.

func (*ListMap) IteratorAsc

func (m *ListMap) IteratorAsc(f func(key interface{}, value interface{}) bool)

IteratorAsc iterates the map in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*ListMap) IteratorDesc

func (m *ListMap) IteratorDesc(f func(key interface{}, value interface{}) bool)

IteratorDesc iterates the map in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*ListMap) Keys

func (m *ListMap) Keys() []interface{}

Keys returns all keys of the map as a slice in ascending order.

func (*ListMap) Map

func (m *ListMap) Map() map[interface{}]interface{}

Map returns a copy of the data of the map.

func (*ListMap) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ListMap) Merge

func (m *ListMap) Merge(other *ListMap)

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

func (*ListMap) Remove

func (m *ListMap) Remove(key interface{}) (value interface{})

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

func (*ListMap) Removes

func (m *ListMap) Removes(keys []interface{})

Removes batch deletes values of the map by keys.

func (*ListMap) Search

func (m *ListMap) Search(key interface{}) (value interface{}, found bool)

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

func (*ListMap) Set

func (m *ListMap) Set(key interface{}, value interface{})

Set sets key-value to the map.

func (*ListMap) SetIfNotExist

func (m *ListMap) SetIfNotExist(key interface{}, value interface{}) bool

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

func (*ListMap) SetIfNotExistFunc

func (m *ListMap) SetIfNotExistFunc(key interface{}, f func() interface{}) bool

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

func (*ListMap) SetIfNotExistFuncLock

func (m *ListMap) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool

SetIfNotExistFuncLock sets value with return value of callback function <f>, then return 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 map.

func (*ListMap) Sets

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

Sets batch sets key-values to the map.

func (*ListMap) Size

func (m *ListMap) Size() (size int)

Size returns the size of the map.

func (*ListMap) Values

func (m *ListMap) Values() []interface{}

Values returns all values of the map as a slice.

type Map

type Map = AnyAnyMap

Map based on hash table, alias of AnyAnyMap.

func New

func New(safe ...bool) *Map

New returns an empty hash map. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewFrom

func NewFrom(data map[interface{}]interface{}, safe ...bool) *Map

NewFrom 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. The parameter <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.

func NewHashMap

func NewHashMap(safe ...bool) *Map

NewHashMap returns an empty hash map. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewHashMapFrom

func NewHashMapFrom(data map[interface{}]interface{}, safe ...bool) *Map

NewHashMapFrom 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. The parameter <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.

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

func (m *StrAnyMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*StrAnyMap) Get

func (m *StrAnyMap) Get(key string) 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 set value with given <value> if not exist and 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 return value of callback function <f> if not exist and 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 return value of callback function <f> if not exist and returns this value.

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

func (*StrAnyMap) GetVar

func (m *StrAnyMap) GetVar(key string) *gvar.Var

GetVar returns a gvar.Var with the value by given <key>. The returned gvar.Var is un-concurrent safe.

func (*StrAnyMap) GetVarOrSet

func (m *StrAnyMap) GetVarOrSet(key string, value interface{}) *gvar.Var

GetVarOrSet returns a gvar.Var with result from GetVarOrSet. The returned gvar.Var is un-concurrent safe.

func (*StrAnyMap) GetVarOrSetFunc

func (m *StrAnyMap) GetVarOrSetFunc(key string, f func() interface{}) *gvar.Var

GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. The returned gvar.Var is un-concurrent safe.

func (*StrAnyMap) GetVarOrSetFuncLock

func (m *StrAnyMap) GetVarOrSetFuncLock(key string, f func() interface{}) *gvar.Var

GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. The returned gvar.Var is un-concurrent safe.

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 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 a copy of the data of the hash map.

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) 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) 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) 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, then return 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>, then return 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>, then return 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) Values

func (m *StrAnyMap) Values() []interface{}

Values returns all values of the map as a slice.

type StrIntMap

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

func NewStrIntMap

func NewStrIntMap(safe ...bool) *StrIntMap

NewStrIntMap returns an empty StrIntMap object. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewStrIntMapFrom

func NewStrIntMapFrom(data map[string]int, safe ...bool) *StrIntMap

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

func (m *StrIntMap) Clear()

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

func (*StrIntMap) Clone

func (m *StrIntMap) Clone() *StrIntMap

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

func (*StrIntMap) Contains

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

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

func (*StrIntMap) Flip

func (m *StrIntMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*StrIntMap) Get

func (m *StrIntMap) Get(key string) int

Get returns the value by given <key>.

func (*StrIntMap) GetOrSet

func (m *StrIntMap) GetOrSet(key string, value int) int

GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.

func (*StrIntMap) GetOrSetFunc

func (m *StrIntMap) GetOrSetFunc(key string, f func() int) int

GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

func (*StrIntMap) GetOrSetFuncLock

func (m *StrIntMap) GetOrSetFuncLock(key string, f func() int) int

GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

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

func (*StrIntMap) IsEmpty

func (m *StrIntMap) IsEmpty() bool

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

func (*StrIntMap) Iterator

func (m *StrIntMap) Iterator(f func(k string, v int) bool)

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

func (*StrIntMap) Keys

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

Keys returns all keys of the map as a slice.

func (*StrIntMap) LockFunc

func (m *StrIntMap) LockFunc(f func(m map[string]int))

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

func (*StrIntMap) Map

func (m *StrIntMap) Map() map[string]int

Map returns a copy of the data of the hash map.

func (*StrIntMap) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*StrIntMap) Merge

func (m *StrIntMap) Merge(other *StrIntMap)

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

func (*StrIntMap) RLockFunc

func (m *StrIntMap) RLockFunc(f func(m map[string]int))

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

func (*StrIntMap) Remove

func (m *StrIntMap) Remove(key string) int

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

func (*StrIntMap) Removes

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

Removes batch deletes values of the map by keys.

func (*StrIntMap) Search

func (m *StrIntMap) Search(key string) (value int, found bool)

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

func (*StrIntMap) Set

func (m *StrIntMap) Set(key string, val int)

Set sets key-value to the hash map.

func (*StrIntMap) SetIfNotExist

func (m *StrIntMap) SetIfNotExist(key string, value int) bool

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

func (*StrIntMap) SetIfNotExistFunc

func (m *StrIntMap) SetIfNotExistFunc(key string, f func() int) bool

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

func (*StrIntMap) SetIfNotExistFuncLock

func (m *StrIntMap) SetIfNotExistFuncLock(key string, f func() int) bool

SetIfNotExistFuncLock sets value with return value of callback function <f>, then return 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 (*StrIntMap) Sets

func (m *StrIntMap) Sets(data map[string]int)

Sets batch sets key-values to the hash map.

func (*StrIntMap) Size

func (m *StrIntMap) Size() int

Size returns the size of the map.

func (*StrIntMap) Values

func (m *StrIntMap) Values() []int

Values returns all values of the map as a slice.

type StrStrMap

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

func NewStrStrMap

func NewStrStrMap(safe ...bool) *StrStrMap

NewStrStrMap returns an empty StrStrMap object. The parameter <safe> used to specify whether using map in concurrent-safety, which is false in default.

func NewStrStrMapFrom

func NewStrStrMapFrom(data map[string]string, safe ...bool) *StrStrMap

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

func (m *StrStrMap) Clear()

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

func (*StrStrMap) Clone

func (m *StrStrMap) Clone() *StrStrMap

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

func (*StrStrMap) Contains

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

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

func (*StrStrMap) Flip

func (m *StrStrMap) Flip()

Flip exchanges key-value of the map to value-key.

func (*StrStrMap) Get

func (m *StrStrMap) Get(key string) string

Get returns the value by given <key>.

func (*StrStrMap) GetOrSet

func (m *StrStrMap) GetOrSet(key string, value string) string

GetOrSet returns the value by key, or set value with given <value> if not exist and returns this value.

func (*StrStrMap) GetOrSetFunc

func (m *StrStrMap) GetOrSetFunc(key string, f func() string) string

GetOrSetFunc returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

func (*StrStrMap) GetOrSetFuncLock

func (m *StrStrMap) GetOrSetFuncLock(key string, f func() string) string

GetOrSetFuncLock returns the value by key, or sets value with return value of callback function <f> if not exist and returns this value.

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

func (*StrStrMap) IsEmpty

func (m *StrStrMap) IsEmpty() bool

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

func (*StrStrMap) Iterator

func (m *StrStrMap) Iterator(f func(k string, v string) bool)

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

func (*StrStrMap) Keys

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

Keys returns all keys of the map as a slice.

func (*StrStrMap) LockFunc

func (m *StrStrMap) LockFunc(f func(m map[string]string))

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

func (*StrStrMap) Map

func (m *StrStrMap) Map() map[string]string

Map returns a copy of the data of the hash map.

func (*StrStrMap) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*StrStrMap) Merge

func (m *StrStrMap) Merge(other *StrStrMap)

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

func (*StrStrMap) RLockFunc

func (m *StrStrMap) RLockFunc(f func(m map[string]string))

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

func (*StrStrMap) Remove

func (m *StrStrMap) Remove(key string) string

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

func (*StrStrMap) Removes

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

Removes batch deletes values of the map by keys.

func (*StrStrMap) Search

func (m *StrStrMap) Search(key string) (value string, found bool)

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

func (*StrStrMap) Set

func (m *StrStrMap) Set(key string, val string)

Set sets key-value to the hash map.

func (*StrStrMap) SetIfNotExist

func (m *StrStrMap) SetIfNotExist(key string, value string) bool

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

func (*StrStrMap) SetIfNotExistFunc

func (m *StrStrMap) SetIfNotExistFunc(key string, f func() string) bool

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

func (*StrStrMap) SetIfNotExistFuncLock

func (m *StrStrMap) SetIfNotExistFuncLock(key string, f func() string) bool

SetIfNotExistFuncLock sets value with return value of callback function <f>, then return 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 (*StrStrMap) Sets

func (m *StrStrMap) Sets(data map[string]string)

Sets batch sets key-values to the hash map.

func (*StrStrMap) Size

func (m *StrStrMap) Size() int

Size returns the size of the map.

func (*StrStrMap) Values

func (m *StrStrMap) Values() []string

Values returns all values of the map as a slice.

type TreeMap

type TreeMap = gtree.RedBlackTree

Map based on red-black tree, alias of RedBlackTree.

func NewTreeMap

func NewTreeMap(comparator func(v1, v2 interface{}) int, safe ...bool) *TreeMap

NewTreeMap instantiates a tree map with the custom comparator. The parameter <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.

func NewTreeMapFrom

func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *TreeMap

NewTreeMapFrom instantiates a tree map with the custom comparator and <data> map. 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. The parameter <unsafe> used to specify whether using tree in un-concurrent-safety, which is false in default.

Jump to

Keyboard shortcuts

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