dmap

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Examples

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
}

AnyAnyMap 并发安全的hash字典表

func NewAnyAnyMap

func NewAnyAnyMap(safe ...bool) *AnyAnyMap

NewAnyAnyMap 创建hash表

func NewAnyAnyMapFrom

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

NewAnyAnyMapFrom 通过map创建hash表

func (*AnyAnyMap) Clear

func (that *AnyAnyMap) Clear()

Clear 清除map

func (*AnyAnyMap) Clone

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

Clone clone一份数据。并返回新的对象指针

func (*AnyAnyMap) Contains

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

Contains 判断传入的key是否存在于map中

func (*AnyAnyMap) FilterEmpty

func (that *AnyAnyMap) FilterEmpty()

FilterEmpty 清除空值

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
	"github.com/osgochina/donkeygo/frame/d"
)

func main() {
	m := dmap.NewFrom(d.MapAnyAny{
		"k1": "",
		"k2": nil,
		"k3": 0,
		"k4": 1,
	})
	m.FilterEmpty()
	fmt.Println(m.Map())

	// May Output:
	// map[k4:1]
}
Output:

func (*AnyAnyMap) FilterNil

func (that *AnyAnyMap) FilterNil()

FilterNil 清除nil值

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
	"github.com/osgochina/donkeygo/frame/d"
)

func main() {
	m := dmap.NewFrom(d.MapAnyAny{
		"k1": "",
		"k2": nil,
		"k3": 0,
		"k4": 1,
	})
	m.FilterNil()
	fmt.Println(m.Map())

	// May Output:
	// map[k1: k3:0 k4:1]
}
Output:

func (*AnyAnyMap) Flip

func (that *AnyAnyMap) Flip()

Flip 翻转key和value

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
	"github.com/osgochina/donkeygo/frame/d"
)

func main() {
	var m dmap.Map
	m.Sets(d.MapAnyAny{
		"k1": "v1",
		"k2": "v2",
	})
	m.Flip()
	fmt.Println(m.Map())

	// May Output:
	// map[v1:k1 v2:k2]
}
Output:

func (*AnyAnyMap) Get

func (that *AnyAnyMap) Get(key interface{}) (value interface{})

Get 查找key

func (*AnyAnyMap) GetOrSet

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

GetOrSet 查找key对应的值是否存在,如果未找到,则写入

func (*AnyAnyMap) GetOrSetFunc

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

GetOrSetFunc 获取指定key的值,如果不存在,则通过方法f生成该值,并写入到map,然后返回 生成新值的方法未使用到锁,不会造成阻塞

func (*AnyAnyMap) GetOrSetFuncLock

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

GetOrSetFuncLock 与上面GetOrSetFunc方法的区别,在乎生成值的时候是否使用锁,此方法生成值的时候会使用到做,传入的方法不能阻塞, 不然会造成map加锁不可读写

func (*AnyAnyMap) IsEmpty

func (that *AnyAnyMap) IsEmpty() bool

IsEmpty 判断map是否为空

func (*AnyAnyMap) Iterator

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

Iterator 迭代hash表

func (*AnyAnyMap) Keys

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

Keys 返回map的所有key

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
	"github.com/osgochina/donkeygo/frame/d"
)

func main() {
	var m dmap.Map
	m.Sets(d.MapAnyAny{
		"k1": "v1",
		"k2": "v2",
		"k3": "v3",
		"k4": "v4",
	})
	fmt.Println(m.Keys())
	fmt.Println(m.Values())

	// May Output:
	// [k1 k2 k3 k4]
	// [v2 v3 v4 v1]
}
Output:

func (*AnyAnyMap) LockFunc

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

LockFunc 加锁执行方法操作数据

func (*AnyAnyMap) Map

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

Map 返回原始结构

func (*AnyAnyMap) MapCopy

func (that *AnyAnyMap) MapCopy() map[interface{}]interface{}

MapCopy copy一份map数据

func (*AnyAnyMap) MarshalJSON

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

MarshalJSON json序列化

func (*AnyAnyMap) Merge

func (that *AnyAnyMap) Merge(other *AnyAnyMap)

Merge 合并两个map

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
)

func main() {
	var m1, m2 dmap.Map
	m1.Set("key1", "val1")
	m2.Set("key2", "val2")
	m1.Merge(&m2)
	fmt.Println(m1.Map())

	// May Output:
	// map[key1:val1 key2:val2]
}
Output:

func (*AnyAnyMap) Pop

func (that *AnyAnyMap) Pop() (key, value interface{})

Pop 随机获取一个字典key,value

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
	"github.com/osgochina/donkeygo/frame/d"
)

func main() {
	var m dmap.Map
	m.Sets(d.MapAnyAny{
		"k1": "v1",
		"k2": "v2",
		"k3": "v3",
		"k4": "v4",
	})
	fmt.Println(m.Pop())
	fmt.Println(m.Pops(2))
	fmt.Println(m.Size())

	// May Output:
	// k1 v1
	// map[k2:v2 k4:v4]
	// 1
}
Output:

func (*AnyAnyMap) Pops

func (that *AnyAnyMap) Pops(size int) map[interface{}]interface{}

Pops 随机获取指定size的字典值,-1表示获取全部

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
	"github.com/osgochina/donkeygo/frame/d"
)

func main() {
	var m dmap.Map
	m.Sets(d.MapAnyAny{
		"k1": "v1",
		"k2": "v2",
		"k3": "v3",
		"k4": "v4",
	})
	fmt.Println(m.Pop())
	fmt.Println(m.Pops(2))
	fmt.Println(m.Size())

	// May Output:
	// k1 v1
	// map[k2:v2 k4:v4]
	// 1
}
Output:

func (*AnyAnyMap) RLockFunc

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

RLockFunc 加读锁执行方法操作数据

func (*AnyAnyMap) Random

func (that *AnyAnyMap) Random() (key, value interface{}, exist bool)

func (*AnyAnyMap) Remove

func (that *AnyAnyMap) Remove(key interface{}) (value interface{})

Remove 移除指定的key,并返回它对应的值

func (*AnyAnyMap) Removes

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

Removes 批量删除key

func (*AnyAnyMap) Replace

func (that *AnyAnyMap) Replace(data map[interface{}]interface{})

Replace 替换map

func (*AnyAnyMap) Search

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

Search 通过key查找value

func (*AnyAnyMap) Set

func (that *AnyAnyMap) Set(key interface{}, value interface{})

Set 设置key value

func (*AnyAnyMap) SetIfNotExist

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

SetIfNotExist 如果map中不存在该key,则设置

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
)

func main() {
	var m dmap.Map
	fmt.Println(m.SetIfNotExist("k1", "v1"))
	fmt.Println(m.SetIfNotExist("k1", "v1"))
	fmt.Println(m.Map())

}
Output:

true
false
map[k1:v1]

func (*AnyAnyMap) SetIfNotExistFunc

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

SetIfNotExistFunc 如果map中不存在key,则调用方法f生成,生成的时候未加锁

func (*AnyAnyMap) SetIfNotExistFuncLock

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

SetIfNotExistFuncLock 如果map中不存在key,则调用方法f生成,生成的时候加锁

func (*AnyAnyMap) Sets

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

Sets 批量设置

func (*AnyAnyMap) Size

func (that *AnyAnyMap) Size() int

Size 返回map的长度

func (*AnyAnyMap) String

func (that *AnyAnyMap) String() string

转换成字符串

func (*AnyAnyMap) UnmarshalJSON

func (that *AnyAnyMap) UnmarshalJSON(b []byte) error

UnmarshalJSON json反序列化

func (*AnyAnyMap) UnmarshalValue

func (that *AnyAnyMap) UnmarshalValue(value interface{}) (err error)

func (*AnyAnyMap) Values

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

Values 返回map所有的值

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
	"github.com/osgochina/donkeygo/frame/d"
)

func main() {
	var m dmap.Map
	m.Sets(d.MapAnyAny{
		"k1": "v1",
		"k2": "v2",
		"k3": "v3",
		"k4": "v4",
	})
	fmt.Println(m.Keys())
	fmt.Println(m.Values())

	// May Output:
	// [k1 k2 k3 k4]
	// [v2 v3 v4 v1]
}
Output:

type AtomicMap added in v0.1.9

type AtomicMap interface {
	// Load returns the value stored in the map for a key, or nil if no
	// value is present.
	// The ok result indicates whether value was found in the map.
	Load(key interface{}) (value interface{}, ok bool)
	// Store sets the value for a key.
	Store(key, value interface{})
	// LoadOrStore returns the existing value for the key if present.
	// Otherwise, it stores and returns the given value.
	// The loaded result is true if the value was loaded, false if stored.
	LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)
	// Range calls f sequentially for each key and value present in the map.
	// If f returns false, range stops the iteration.
	Range(f func(key, value interface{}) bool)
	// Random returns a pair kv randomly.
	// If exist=false, no kv data is exist.
	Random() (key, value interface{}, exist bool)
	// Delete deletes the value for a key.
	Delete(key interface{})
	// Clear clears all current data in the map.
	Clear()
	// Len returns the length of the map.
	Len() int
}

AtomicMap is a concurrent map with loads, stores, and deletes. It is safe for multiple goroutines to call a Map's methods concurrently.

func NewAtomicMap added in v0.1.9

func NewAtomicMap() AtomicMap

NewAtomicMap creates a concurrent map with amortized-constant-time loads, stores, and deletes. It is safe for multiple goroutines to call a atomicMap's methods concurrently. From go v1.9 sync.Map.

type HashMap

type HashMap = AnyAnyMap // HashMap is alias of AnyAnyMap.

type IntAnyMap added in v0.0.5

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

func NewIntAnyMap added in v0.0.5

func NewIntAnyMap(safe ...bool) *IntAnyMap

NewIntAnyMap 创建key值为int类型的hash表

func NewIntAnyMapFrom added in v0.0.5

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

NewIntAnyMapFrom 通过基础数据格式创建map

func (*IntAnyMap) Clear added in v0.0.5

func (that *IntAnyMap) Clear()

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

func (*IntAnyMap) Clone added in v0.0.5

func (that *IntAnyMap) Clone() *IntAnyMap

Clone 返回一个新的map对象,内容是当前map对象的副本

func (*IntAnyMap) Contains added in v0.0.5

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

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

func (*IntAnyMap) FilterEmpty added in v0.0.5

func (that *IntAnyMap) FilterEmpty()

FilterEmpty 删除空值

func (*IntAnyMap) FilterNil added in v0.0.5

func (that *IntAnyMap) FilterNil()

FilterNil 删除nil值

func (*IntAnyMap) Flip added in v0.0.5

func (that *IntAnyMap) Flip()

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

func (*IntAnyMap) Get added in v0.0.5

func (that *IntAnyMap) Get(key int) (value interface{})

Get returns the value by given <key>.

func (*IntAnyMap) GetOrSet added in v0.0.5

func (that *IntAnyMap) GetOrSet(key int, 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 (*IntAnyMap) GetOrSetFunc added in v0.0.5

func (that *IntAnyMap) GetOrSetFunc(key int, 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 returns this value.

func (*IntAnyMap) GetOrSetFuncLock added in v0.0.5

func (that *IntAnyMap) GetOrSetFuncLock(key int, 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 returns this value.

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

func (*IntAnyMap) GetVar added in v0.0.5

func (that *IntAnyMap) GetVar(key int) *dvar.Var

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

func (*IntAnyMap) GetVarOrSet added in v0.0.5

func (that *IntAnyMap) GetVarOrSet(key int, value interface{}) *dvar.Var

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

func (*IntAnyMap) GetVarOrSetFunc added in v0.0.5

func (that *IntAnyMap) GetVarOrSetFunc(key int, f func() interface{}) *dvar.Var

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

func (*IntAnyMap) GetVarOrSetFuncLock added in v0.0.5

func (that *IntAnyMap) GetVarOrSetFuncLock(key int, f func() interface{}) *dvar.Var

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

func (*IntAnyMap) IsEmpty added in v0.0.5

func (that *IntAnyMap) IsEmpty() bool

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

func (*IntAnyMap) Iterator added in v0.0.5

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

Iterator 迭代map

func (*IntAnyMap) Keys added in v0.0.5

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

Keys returns all keys of the map as a slice.

func (*IntAnyMap) LockFunc added in v0.0.5

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

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

func (*IntAnyMap) Map added in v0.0.5

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

Map 返回基础map类型

func (*IntAnyMap) MapCopy added in v0.0.5

func (that *IntAnyMap) MapCopy() map[int]interface{}

MapCopy 复制一份数据返回

func (*IntAnyMap) MapStrAny added in v0.0.5

func (that *IntAnyMap) MapStrAny() map[string]interface{}

MapStrAny 把key转换成字符串返回

func (*IntAnyMap) MarshalJSON added in v0.0.5

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*IntAnyMap) Merge added in v0.0.5

func (that *IntAnyMap) Merge(other *IntAnyMap)

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

func (*IntAnyMap) Pop added in v0.0.5

func (that *IntAnyMap) Pop() (key int, value interface{})

Pop retrieves and deletes an item from the map.

func (*IntAnyMap) Pops added in v0.0.5

func (that *IntAnyMap) Pops(size int) map[int]interface{}

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

func (*IntAnyMap) RLockFunc added in v0.0.5

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

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

func (*IntAnyMap) Remove added in v0.0.5

func (that *IntAnyMap) Remove(key int) (value interface{})

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

func (*IntAnyMap) Removes added in v0.0.5

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

Removes batch deletes values of the map by keys.

func (*IntAnyMap) Replace added in v0.0.5

func (that *IntAnyMap) Replace(data map[int]interface{})

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

func (*IntAnyMap) Search added in v0.0.5

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

Search 搜索数据

func (*IntAnyMap) Set added in v0.0.5

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

Set 写入单个数据

func (*IntAnyMap) SetIfNotExist added in v0.0.5

func (that *IntAnyMap) SetIfNotExist(key int, 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 (*IntAnyMap) SetIfNotExistFunc added in v0.0.5

func (that *IntAnyMap) SetIfNotExistFunc(key int, 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 (*IntAnyMap) SetIfNotExistFuncLock added in v0.0.5

func (that *IntAnyMap) SetIfNotExistFuncLock(key int, 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 (*IntAnyMap) Sets added in v0.0.5

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

Sets 写入数组

func (*IntAnyMap) Size added in v0.0.5

func (that *IntAnyMap) Size() int

Size returns the size of the map.

func (*IntAnyMap) String added in v0.0.5

func (that *IntAnyMap) String() string

String returns the map as a string.

func (*IntAnyMap) UnmarshalJSON added in v0.0.5

func (that *IntAnyMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*IntAnyMap) UnmarshalValue added in v0.0.5

func (that *IntAnyMap) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*IntAnyMap) Values added in v0.0.5

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

Values returns all values of the map as a slice.

type IntIntMap added in v0.0.9

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

func NewIntIntMap added in v0.0.9

func NewIntIntMap(safe ...bool) *IntIntMap

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

func NewIntIntMapFrom added in v0.0.9

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

NewIntIntMapFrom 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 (*IntIntMap) Clear added in v0.0.9

func (that *IntIntMap) Clear()

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

func (*IntIntMap) Clone added in v0.0.9

func (that *IntIntMap) Clone() *IntIntMap

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

func (*IntIntMap) Contains added in v0.0.9

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

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

func (*IntIntMap) FilterEmpty added in v0.0.9

func (that *IntIntMap) 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 (*IntIntMap) Flip added in v0.0.9

func (that *IntIntMap) Flip()

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

func (*IntIntMap) Get added in v0.0.9

func (that *IntIntMap) Get(key int) (value int)

Get returns the value by given <key>.

func (*IntIntMap) GetOrSet added in v0.0.9

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

GetOrSet returns the value by key, or sets value with given <value> if it does not exist and then returns this value.

func (*IntIntMap) GetOrSetFunc added in v0.0.9

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

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

func (*IntIntMap) GetOrSetFuncLock added in v0.0.9

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

GetOrSetFuncLock returns the value by key, or sets value with returned value of callback function <f> if it does 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 added in v0.0.9

func (that *IntIntMap) IsEmpty() bool

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

func (*IntIntMap) Iterator added in v0.0.9

func (that *IntIntMap) Iterator(f func(k int, v int) 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 (*IntIntMap) Keys added in v0.0.9

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

Keys returns all keys of the map as a slice.

func (*IntIntMap) LockFunc added in v0.0.9

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

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

func (*IntIntMap) Map added in v0.0.9

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

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 (*IntIntMap) MapCopy added in v0.0.9

func (that *IntIntMap) MapCopy() map[int]int

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

func (*IntIntMap) MapStrAny added in v0.0.9

func (that *IntIntMap) MapStrAny() map[string]interface{}

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

func (*IntIntMap) MarshalJSON added in v0.0.9

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*IntIntMap) Merge added in v0.0.9

func (that *IntIntMap) Merge(other *IntIntMap)

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

func (*IntIntMap) Pop added in v0.0.9

func (that *IntIntMap) Pop() (key, value int)

Pop retrieves and deletes an item from the map.

func (*IntIntMap) Pops added in v0.0.9

func (that *IntIntMap) Pops(size int) map[int]int

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

func (*IntIntMap) RLockFunc added in v0.0.9

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

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

func (*IntIntMap) Remove added in v0.0.9

func (that *IntIntMap) Remove(key int) (value int)

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

func (*IntIntMap) Removes added in v0.0.9

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

Removes batch deletes values of the map by keys.

func (*IntIntMap) Replace added in v0.0.9

func (that *IntIntMap) Replace(data map[int]int)

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

func (*IntIntMap) Search added in v0.0.9

func (that *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 added in v0.0.9

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

Set sets key-value to the hash map.

func (*IntIntMap) SetIfNotExist added in v0.0.9

func (that *IntIntMap) SetIfNotExist(key int, value int) 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 (*IntIntMap) SetIfNotExistFunc added in v0.0.9

func (that *IntIntMap) SetIfNotExistFunc(key int, f func() int) 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 (*IntIntMap) SetIfNotExistFuncLock added in v0.0.9

func (that *IntIntMap) SetIfNotExistFuncLock(key int, f func() int) 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 (*IntIntMap) Sets added in v0.0.9

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

Sets batch sets key-values to the hash map.

func (*IntIntMap) Size added in v0.0.9

func (that *IntIntMap) Size() int

Size returns the size of the map.

func (*IntIntMap) String added in v0.0.9

func (that *IntIntMap) String() string

String returns the map as a string.

func (*IntIntMap) UnmarshalJSON added in v0.0.9

func (that *IntIntMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*IntIntMap) UnmarshalValue added in v0.0.9

func (that *IntIntMap) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*IntIntMap) Values added in v0.0.9

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

Values returns all values of the map as a slice.

type IntStrMap added in v0.0.9

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

func NewIntStrMap added in v0.0.9

func NewIntStrMap(safe ...bool) *IntStrMap

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

func NewIntStrMapFrom added in v0.0.9

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

NewIntStrMapFrom 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 (*IntStrMap) Clear added in v0.0.9

func (that *IntStrMap) Clear()

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

func (*IntStrMap) Clone added in v0.0.9

func (that *IntStrMap) Clone() *IntStrMap

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

func (*IntStrMap) Contains added in v0.0.9

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

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

func (*IntStrMap) FilterEmpty added in v0.0.9

func (that *IntStrMap) 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 (*IntStrMap) Flip added in v0.0.9

func (that *IntStrMap) Flip()

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

func (*IntStrMap) Get added in v0.0.9

func (that *IntStrMap) Get(key int) (value string)

Get returns the value by given <key>.

func (*IntStrMap) GetOrSet added in v0.0.9

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

GetOrSet returns the value by key, or sets value with given <value> if it does not exist and then returns this value.

func (*IntStrMap) GetOrSetFunc added in v0.0.9

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

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

func (*IntStrMap) GetOrSetFuncLock added in v0.0.9

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

GetOrSetFuncLock returns the value by key, or sets value with returned value of callback function <f> if it does 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 added in v0.0.9

func (that *IntStrMap) IsEmpty() bool

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

func (*IntStrMap) Iterator added in v0.0.9

func (that *IntStrMap) Iterator(f func(k int, v string) 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 (*IntStrMap) Keys added in v0.0.9

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

Keys returns all keys of the map as a slice.

func (*IntStrMap) LockFunc added in v0.0.9

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

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

func (*IntStrMap) Map added in v0.0.9

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

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 (*IntStrMap) MapCopy added in v0.0.9

func (that *IntStrMap) MapCopy() map[int]string

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

func (*IntStrMap) MapStrAny added in v0.0.9

func (that *IntStrMap) MapStrAny() map[string]interface{}

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

func (*IntStrMap) MarshalJSON added in v0.0.9

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*IntStrMap) Merge added in v0.0.9

func (that *IntStrMap) Merge(other *IntStrMap)

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

func (*IntStrMap) Pop added in v0.0.9

func (that *IntStrMap) Pop() (key int, value string)

Pop retrieves and deletes an item from the map.

func (*IntStrMap) Pops added in v0.0.9

func (that *IntStrMap) Pops(size int) map[int]string

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

func (*IntStrMap) RLockFunc added in v0.0.9

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

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

func (*IntStrMap) Remove added in v0.0.9

func (that *IntStrMap) Remove(key int) (value string)

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

func (*IntStrMap) Removes added in v0.0.9

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

Removes batch deletes values of the map by keys.

func (*IntStrMap) Replace added in v0.0.9

func (that *IntStrMap) Replace(data map[int]string)

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

func (*IntStrMap) Search added in v0.0.9

func (that *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 added in v0.0.9

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

Set sets key-value to the hash map.

func (*IntStrMap) SetIfNotExist added in v0.0.9

func (that *IntStrMap) SetIfNotExist(key int, value string) 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 (*IntStrMap) SetIfNotExistFunc added in v0.0.9

func (that *IntStrMap) SetIfNotExistFunc(key int, f func() string) 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 (*IntStrMap) SetIfNotExistFuncLock added in v0.0.9

func (that *IntStrMap) SetIfNotExistFuncLock(key int, f func() string) 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 (*IntStrMap) Sets added in v0.0.9

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

Sets batch sets key-values to the hash map.

func (*IntStrMap) Size added in v0.0.9

func (that *IntStrMap) Size() int

Size returns the size of the map.

func (*IntStrMap) String added in v0.0.9

func (that *IntStrMap) String() string

String returns the map as a string.

func (*IntStrMap) UnmarshalJSON added in v0.0.9

func (that *IntStrMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*IntStrMap) UnmarshalValue added in v0.0.9

func (that *IntStrMap) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*IntStrMap) Values added in v0.0.9

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

Values returns all values of the map as a slice.

type ListMap added in v0.0.9

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

func NewListMap added in v0.0.9

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> is used to specify whether using map in concurrent-safety, which is false in default.

func NewListMapFrom added in v0.0.9

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 added in v0.0.9

func (m *ListMap) Clear()

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

func (*ListMap) Clone added in v0.0.9

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

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

func (*ListMap) Contains added in v0.0.9

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) FilterEmpty added in v0.0.9

func (m *ListMap) FilterEmpty()

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

func (*ListMap) Flip added in v0.0.9

func (m *ListMap) Flip()

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

func (*ListMap) Get added in v0.0.9

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

Get returns the value by given <key>.

func (*ListMap) GetOrSet added in v0.0.9

func (m *ListMap) GetOrSet(key interface{}, 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 (*ListMap) GetOrSetFunc added in v0.0.9

func (m *ListMap) GetOrSetFunc(key interface{}, 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 (*ListMap) GetOrSetFuncLock added in v0.0.9

func (m *ListMap) GetOrSetFuncLock(key interface{}, 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 map.

func (*ListMap) GetVar added in v0.0.9

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

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

func (*ListMap) GetVarOrSet added in v0.0.9

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

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

func (*ListMap) GetVarOrSetFunc added in v0.0.9

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

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

func (*ListMap) GetVarOrSetFuncLock added in v0.0.9

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

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

func (*ListMap) IsEmpty added in v0.0.9

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 added in v0.0.9

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

Iterator is alias of IteratorAsc.

func (*ListMap) IteratorAsc added in v0.0.9

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

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

func (*ListMap) IteratorDesc added in v0.0.9

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

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

func (*ListMap) Keys added in v0.0.9

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

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

func (*ListMap) Map added in v0.0.9

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

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

func (*ListMap) MapStrAny added in v0.0.9

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

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

func (*ListMap) MarshalJSON added in v0.0.9

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ListMap) Merge added in v0.0.9

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

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

func (*ListMap) Pop added in v0.0.9

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

Pop retrieves and deletes an item from the map.

func (*ListMap) Pops added in v0.0.9

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

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

func (*ListMap) Remove added in v0.0.9

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

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

func (*ListMap) Removes added in v0.0.9

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

Removes batch deletes values of the map by keys.

func (*ListMap) Replace added in v0.0.9

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

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

func (*ListMap) Search added in v0.0.9

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 added in v0.0.9

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

Set sets key-value to the map.

func (*ListMap) SetIfNotExist added in v0.0.9

func (m *ListMap) SetIfNotExist(key interface{}, 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 (*ListMap) SetIfNotExistFunc added in v0.0.9

func (m *ListMap) SetIfNotExistFunc(key interface{}, 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 (*ListMap) SetIfNotExistFuncLock added in v0.0.9

func (m *ListMap) SetIfNotExistFuncLock(key interface{}, 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 map.

func (*ListMap) Sets added in v0.0.9

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

Sets batch sets key-values to the map.

func (*ListMap) Size added in v0.0.9

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

Size returns the size of the map.

func (*ListMap) String added in v0.0.9

func (m *ListMap) String() string

String returns the map as a string.

func (*ListMap) UnmarshalJSON added in v0.0.9

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*ListMap) UnmarshalValue added in v0.0.9

func (m *ListMap) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*ListMap) Values added in v0.0.9

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

Values returns all values of the map as a slice.

type Map

type Map = AnyAnyMap // Map is alias of AnyAnyMap.

func New

func New(safe ...bool) *Map

New 创建一个map对象

Example
package main

import (
	"fmt"
	"github.com/osgochina/donkeygo/container/dmap"
)

func main() {
	m := dmap.New()

	// Add data.
	m.Set("key1", "val1")

	// Print size.
	fmt.Println(m.Size())

	addMap := make(map[interface{}]interface{})
	addMap["key2"] = "val2"
	addMap["key3"] = "val3"
	addMap[1] = 1

	fmt.Println(m.Values())

	// Batch add data.
	m.Sets(addMap)

	// Gets the value of the corresponding key.
	fmt.Println(m.Get("key3"))

	// Get the value by key, or set it with given key-value if not exist.
	fmt.Println(m.GetOrSet("key4", "val4"))

	// Set key-value if the key does not exist, then return true; or else return false.
	fmt.Println(m.SetIfNotExist("key3", "val3"))

	// Remove key
	m.Remove("key2")
	fmt.Println(m.Keys())

	// Batch remove keys.
	m.Removes([]interface{}{"key1", 1})
	fmt.Println(m.Keys())

	// Contains checks whether a key exists.
	fmt.Println(m.Contains("key3"))

	// Flip exchanges key-value of the map, it will change key-value to value-key.
	m.Flip()
	fmt.Println(m.Map())

	// Clear deletes all data of the map.
	m.Clear()

	fmt.Println(m.Size())

	// May Output:
	// 1
	// [val1]
	// val3
	// val4
	// false
	// [key4 key1 key3 1]
	// [key4 key3]
	// true
	// map[val3:key3 val4:key4]
	// 0
}
Output:

func NewFrom

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

NewFrom 创建一个map对象,并把参数data作为值

func NewHashMap

func NewHashMap(safe ...bool) *Map

NewHashMap 创建一个map对象

func NewHashMapFrom

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

NewHashMapFrom 创建一个map对象,并把参数data作为值

type StrAnyMap added in v0.0.3

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

func NewStrAnyMap added in v0.0.3

func NewStrAnyMap(safe ...bool) *StrAnyMap

NewStrAnyMap 返回一个空的StrAnyMap对象

func NewStrAnyMapFrom added in v0.0.3

func NewStrAnyMapFrom(data map[string]interface{}, safe ...bool) *StrAnyMap

NewStrAnyMapFrom 从给定的map 创建并返回一个哈希映射。 注意,param map将被设置为底层数据map(没有深层复制), 当改变外部映射时,可能会有一些并发安全问题。

func (*StrAnyMap) Clear added in v0.0.3

func (that *StrAnyMap) Clear()

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

func (*StrAnyMap) Clone added in v0.0.3

func (that *StrAnyMap) Clone() *StrAnyMap

Clone 返回一个新的StrAnyMap对象,其中的值是赋值的当前StrAnyMap对象

func (*StrAnyMap) Contains added in v0.0.3

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

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

func (*StrAnyMap) FilterEmpty added in v0.0.3

func (that *StrAnyMap) FilterEmpty()

FilterEmpty 删除map对象中的空值 空值的定义: 0, nil, false, "", len(slice/map/chan) == 0

func (*StrAnyMap) FilterNil added in v0.0.3

func (that *StrAnyMap) FilterNil()

FilterNil 删除map中值为 nil的对象

func (*StrAnyMap) Flip added in v0.0.3

func (that *StrAnyMap) Flip()

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

func (*StrAnyMap) Get added in v0.0.3

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

Get 返回key对应的值

func (*StrAnyMap) GetOrSet added in v0.0.3

func (that *StrAnyMap) GetOrSet(key string, value interface{}) interface{}

GetOrSet 如果存在,则返回,不存在则设置并返回

func (*StrAnyMap) GetOrSetFunc added in v0.0.3

func (that *StrAnyMap) GetOrSetFunc(key string, f func() interface{}) interface{}

GetOrSetFunc 如果存在,则返回,不存在则设置并返回

func (*StrAnyMap) GetOrSetFuncLock added in v0.0.3

func (that *StrAnyMap) GetOrSetFuncLock(key string, f func() interface{}) interface{}

GetOrSetFuncLock 如果存在,则返回,不存在则设置并返回

func (*StrAnyMap) GetVar added in v0.0.3

func (that *StrAnyMap) GetVar(key string) *dvar.Var

GetVar 返回Var类型的值

func (*StrAnyMap) GetVarOrSet added in v0.0.3

func (that *StrAnyMap) GetVarOrSet(key string, value interface{}) *dvar.Var

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

func (*StrAnyMap) GetVarOrSetFunc added in v0.0.3

func (that *StrAnyMap) GetVarOrSetFunc(key string, f func() interface{}) *dvar.Var

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

func (*StrAnyMap) GetVarOrSetFuncLock added in v0.0.3

func (that *StrAnyMap) GetVarOrSetFuncLock(key string, f func() interface{}) *dvar.Var

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

func (*StrAnyMap) IsEmpty added in v0.0.3

func (that *StrAnyMap) IsEmpty() bool

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

func (*StrAnyMap) Iterator added in v0.0.3

func (that *StrAnyMap) Iterator(f func(k string, v interface{}) bool)

Iterator 迭代该map,如果其中有一次迭代返回false,则整个迭代过程将会终止

func (*StrAnyMap) Keys added in v0.0.3

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

Keys returns all keys of the map as a slice.

func (*StrAnyMap) LockFunc added in v0.0.3

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

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

func (*StrAnyMap) Map added in v0.0.3

func (that *StrAnyMap) Map() map[string]interface{}

Map 返回一个原始的map对象

func (*StrAnyMap) MapCopy added in v0.0.3

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

MapCopy 把对象的值赋值到新的地址中并返回

func (*StrAnyMap) MapStrAny added in v0.0.3

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

MapStrAny 返回一个map[string]interface{}类型的map对象

func (*StrAnyMap) MarshalJSON added in v0.0.3

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*StrAnyMap) Merge added in v0.0.3

func (that *StrAnyMap) Merge(other *StrAnyMap)

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

func (*StrAnyMap) Pop added in v0.0.3

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

Pop 从map中返回一个元素并删除它

func (*StrAnyMap) Pops added in v0.0.3

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

Pops 返回指定数量的元素并删除它

func (*StrAnyMap) RLockFunc added in v0.0.3

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

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

func (*StrAnyMap) Remove added in v0.0.3

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

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

func (*StrAnyMap) Removes added in v0.0.3

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

Removes batch deletes values of the map by keys.

func (*StrAnyMap) Replace added in v0.0.3

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

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

func (*StrAnyMap) Search added in v0.0.3

func (that *StrAnyMap) Search(key string) (value interface{}, found bool)

Search 查找key是否存在map中,知道则返回该值,found为true,没有找到value=nil,found=false

func (*StrAnyMap) Set added in v0.0.3

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

Set 写入key,val到map中

func (*StrAnyMap) SetIfNotExist added in v0.0.3

func (that *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 added in v0.0.3

func (that *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 added in v0.0.3

func (that *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 added in v0.0.3

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

Sets 批量写入

func (*StrAnyMap) Size added in v0.0.3

func (that *StrAnyMap) Size() int

Size returns the size of the map.

func (*StrAnyMap) String added in v0.0.3

func (that *StrAnyMap) String() string

String returns the map as a string.

func (*StrAnyMap) UnmarshalJSON added in v0.0.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*StrAnyMap) UnmarshalValue added in v0.0.3

func (that *StrAnyMap) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*StrAnyMap) Values added in v0.0.3

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

Values returns all values of the map as a slice.

type StrIntMap added in v0.0.9

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

func NewStrIntMap added in v0.0.9

func NewStrIntMap(safe ...bool) *StrIntMap

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

func NewStrIntMapFrom added in v0.0.9

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

NewStrIntMapFrom 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 (*StrIntMap) Clear added in v0.0.9

func (that *StrIntMap) Clear()

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

func (*StrIntMap) Clone added in v0.0.9

func (that *StrIntMap) Clone() *StrIntMap

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

func (*StrIntMap) Contains added in v0.0.9

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

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

func (*StrIntMap) FilterEmpty added in v0.0.9

func (that *StrIntMap) 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 (*StrIntMap) Flip added in v0.0.9

func (that *StrIntMap) Flip()

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

func (*StrIntMap) Get added in v0.0.9

func (that *StrIntMap) Get(key string) (value int)

Get returns the value by given <key>.

func (*StrIntMap) GetOrSet added in v0.0.9

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

GetOrSet returns the value by key, or sets value with given <value> if it does not exist and then returns this value.

func (*StrIntMap) GetOrSetFunc added in v0.0.9

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

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 (*StrIntMap) GetOrSetFuncLock added in v0.0.9

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

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 (*StrIntMap) IsEmpty added in v0.0.9

func (that *StrIntMap) IsEmpty() bool

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

func (*StrIntMap) Iterator added in v0.0.9

func (that *StrIntMap) Iterator(f func(k string, v int) 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 (*StrIntMap) Keys added in v0.0.9

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

Keys returns all keys of the map as a slice.

func (*StrIntMap) LockFunc added in v0.0.9

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

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

func (*StrIntMap) Map added in v0.0.9

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

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 (*StrIntMap) MapCopy added in v0.0.9

func (that *StrIntMap) MapCopy() map[string]int

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

func (*StrIntMap) MapStrAny added in v0.0.9

func (that *StrIntMap) MapStrAny() map[string]interface{}

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

func (*StrIntMap) MarshalJSON added in v0.0.9

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*StrIntMap) Merge added in v0.0.9

func (that *StrIntMap) Merge(other *StrIntMap)

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

func (*StrIntMap) Pop added in v0.0.9

func (that *StrIntMap) Pop() (key string, value int)

Pop retrieves and deletes an item from the map.

func (*StrIntMap) Pops added in v0.0.9

func (that *StrIntMap) Pops(size int) map[string]int

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

func (*StrIntMap) RLockFunc added in v0.0.9

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

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

func (*StrIntMap) Remove added in v0.0.9

func (that *StrIntMap) Remove(key string) (value int)

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

func (*StrIntMap) Removes added in v0.0.9

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

Removes batch deletes values of the map by keys.

func (*StrIntMap) Replace added in v0.0.9

func (that *StrIntMap) Replace(data map[string]int)

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

func (*StrIntMap) Search added in v0.0.9

func (that *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 added in v0.0.9

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

Set sets key-value to the hash map.

func (*StrIntMap) SetIfNotExist added in v0.0.9

func (that *StrIntMap) SetIfNotExist(key string, value int) 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 (*StrIntMap) SetIfNotExistFunc added in v0.0.9

func (that *StrIntMap) SetIfNotExistFunc(key string, f func() int) 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 (*StrIntMap) SetIfNotExistFuncLock added in v0.0.9

func (that *StrIntMap) SetIfNotExistFuncLock(key string, f func() int) 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 (*StrIntMap) Sets added in v0.0.9

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

Sets batch sets key-values to the hash map.

func (*StrIntMap) Size added in v0.0.9

func (that *StrIntMap) Size() int

Size returns the size of the map.

func (*StrIntMap) String added in v0.0.9

func (that *StrIntMap) String() string

String returns the map as a string.

func (*StrIntMap) UnmarshalJSON added in v0.0.9

func (that *StrIntMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*StrIntMap) UnmarshalValue added in v0.0.9

func (that *StrIntMap) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*StrIntMap) Values added in v0.0.9

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

Values returns all values of the map as a slice.

type StrStrMap added in v0.0.9

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

func NewStrStrMap added in v0.0.9

func NewStrStrMap(safe ...bool) *StrStrMap

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

func NewStrStrMapFrom added in v0.0.9

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

NewStrStrMapFrom 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 (*StrStrMap) Clear added in v0.0.9

func (that *StrStrMap) Clear()

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

func (*StrStrMap) Clone added in v0.0.9

func (that *StrStrMap) Clone() *StrStrMap

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

func (*StrStrMap) Contains added in v0.0.9

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

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

func (*StrStrMap) FilterEmpty added in v0.0.9

func (that *StrStrMap) 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 (*StrStrMap) Flip added in v0.0.9

func (that *StrStrMap) Flip()

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

func (*StrStrMap) Get added in v0.0.9

func (that *StrStrMap) Get(key string) (value string)

Get returns the value by given <key>.

func (*StrStrMap) GetOrSet added in v0.0.9

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

GetOrSet returns the value by key, or sets value with given <value> if it does not exist and then returns this value.

func (*StrStrMap) GetOrSetFunc added in v0.0.9

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

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 (*StrStrMap) GetOrSetFuncLock added in v0.0.9

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

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 (*StrStrMap) IsEmpty added in v0.0.9

func (that *StrStrMap) IsEmpty() bool

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

func (*StrStrMap) Iterator added in v0.0.9

func (that *StrStrMap) Iterator(f func(k string, v string) 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 (*StrStrMap) Keys added in v0.0.9

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

Keys returns all keys of the map as a slice.

func (*StrStrMap) LockFunc added in v0.0.9

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

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

func (*StrStrMap) Map added in v0.0.9

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

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 (*StrStrMap) MapCopy added in v0.0.9

func (that *StrStrMap) MapCopy() map[string]string

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

func (*StrStrMap) MapStrAny added in v0.0.9

func (that *StrStrMap) MapStrAny() map[string]interface{}

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

func (*StrStrMap) MarshalJSON added in v0.0.9

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*StrStrMap) Merge added in v0.0.9

func (that *StrStrMap) Merge(other *StrStrMap)

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

func (*StrStrMap) Pop added in v0.0.9

func (that *StrStrMap) Pop() (key, value string)

Pop retrieves and deletes an item from the map.

func (*StrStrMap) Pops added in v0.0.9

func (that *StrStrMap) Pops(size int) map[string]string

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

func (*StrStrMap) RLockFunc added in v0.0.9

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

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

func (*StrStrMap) Remove added in v0.0.9

func (that *StrStrMap) Remove(key string) (value string)

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

func (*StrStrMap) Removes added in v0.0.9

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

Removes batch deletes values of the map by keys.

func (*StrStrMap) Replace added in v0.0.9

func (that *StrStrMap) Replace(data map[string]string)

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

func (*StrStrMap) Search added in v0.0.9

func (that *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 added in v0.0.9

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

Set sets key-value to the hash map.

func (*StrStrMap) SetIfNotExist added in v0.0.9

func (that *StrStrMap) SetIfNotExist(key string, value string) 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 (*StrStrMap) SetIfNotExistFunc added in v0.0.9

func (that *StrStrMap) SetIfNotExistFunc(key string, f func() string) 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 (*StrStrMap) SetIfNotExistFuncLock added in v0.0.9

func (that *StrStrMap) SetIfNotExistFuncLock(key string, f func() string) 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 (*StrStrMap) Sets added in v0.0.9

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

Sets batch sets key-values to the hash map.

func (*StrStrMap) Size added in v0.0.9

func (that *StrStrMap) Size() int

Size returns the size of the map.

func (*StrStrMap) String added in v0.0.9

func (that *StrStrMap) String() string

String returns the map as a string.

func (*StrStrMap) UnmarshalJSON added in v0.0.9

func (that *StrStrMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*StrStrMap) UnmarshalValue added in v0.0.9

func (that *StrStrMap) UnmarshalValue(value interface{}) (err error)

UnmarshalValue is an interface implement which sets any type of value for map.

func (*StrStrMap) Values added in v0.0.9

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

Values returns all values of the map as a slice.

type TreeMap added in v0.1.9

type TreeMap = dtree.RedBlackTree

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

func NewTreeMap added in v0.1.9

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

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

func NewTreeMapFrom added in v0.1.9

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 <safe> is used to specify whether using tree in 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