gmap

package
v0.0.0-...-3e416e1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Less

func Less(v1, v2 interface{}) bool

func Sort

func Sort(s []map[string]interface{}, key string, aes bool)

func SortStr

func SortStr(s []map[string]string, key string, aes bool)

func ToAny

func ToAny(a map[string]string) (b map[string]interface{})

ToAny converts map[string]string to map[string]interface{}

func ToString

func ToString(a map[string]interface{}) (b map[string]string)

ToString converts map[string]interface{} to map[string]string

Types

type M

type M = map[string]interface{}

M alias of type map[string]interface{}

type Map

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

Map a map can kept the sequence of keys when range the map have more useful function, Len(), Shift(), Pop(),Keys(), etc.

func New

func New() *Map

New creates a Map object.

func SortMap

func SortMap(m map[string]interface{}, aes bool) *Map

func SortMapStr

func SortMapStr(m map[string]string, aes bool) *Map

func (*Map) Clear

func (s *Map) Clear()

Clear deletes all data in the map s.

func (*Map) Clone

func (s *Map) Clone() *Map

Clone duplicates the map s.

func (*Map) CloneAndClear

func (s *Map) CloneAndClear() *Map

CloneAndClear duplicates the map s.

func (*Map) Delete

func (s *Map) Delete(key interface{})

Delete deletes the value for a key.

func (*Map) GC

func (s *Map) GC()

GC rebuild the internal map to release memory used by the map.

func (*Map) IndexOf

func (s *Map) IndexOf(k interface{}) int

IndexOf indicates the index of value in Map s, if not found returns -1.

idx start with 0.

func (*Map) IsEmpty

func (s *Map) IsEmpty() bool

IsEmpty indicates if the map is empty.

func (*Map) Keys

func (s *Map) Keys() (keys []interface{})

Keys returns all keys in map s and keep the sequence of store sequence.

func (*Map) Len

func (s *Map) Len() int

Len returns the length of the map s.

func (*Map) Load

func (s *Map) Load(key interface{}) (value interface{}, ok bool)

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.

func (*Map) LoadAndDelete

func (s *Map) LoadAndDelete(key interface{}) (value interface{}, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*Map) LoadAndStoreFunc

func (s *Map) LoadAndStoreFunc(key interface{}, f func(oldValue interface{}, loaded bool) (newValue interface{})) (newValue interface{}, loaded bool)

LoadAndStoreFunc call the given func and stores it returns value. The loaded result is true if the keys was exists, false if not exists. If loaded, the given func firstly parameter is the loaded value, otherwise is nil.

func (*Map) LoadAndStoreFuncErr

func (s *Map) LoadAndStoreFuncErr(key interface{}, f func(oldValue interface{}, loaded bool) (newValue interface{}, err error)) (newValue interface{}, loaded bool, err error)

LoadAndStoreFuncErr call the given func and stores it returns value, if func returns an error, the error be returned. The loaded result is true if the keys was exists, false if not exists. If loaded, the given func firstly parameter is the loaded value, otherwise is nil.

func (*Map) LoadOrStore

func (s *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)

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.

func (*Map) LoadOrStoreFront

func (s *Map) LoadOrStoreFront(key, value interface{}) (actual interface{}, loaded bool)

LoadOrStoreFront 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. The key will be stored the first in keys queue if key not exists.

func (*Map) LoadOrStoreFunc

func (s *Map) LoadOrStoreFunc(key interface{}, f func() interface{}) (actual interface{}, loaded bool)

LoadOrStoreFunc returns the existing value for the key if present. Otherwise, it call the given func and stores it returns value. The loaded result is true if the value was loaded, false if stored.

func (*Map) LoadOrStoreFuncErr

func (s *Map) LoadOrStoreFuncErr(key interface{}, f func() (x interface{}, err error)) (actual interface{}, loaded bool, err error)

LoadOrStoreFuncErr returns the existing value for the key if present. Otherwise, it call the given func and stores it returns value, if the func returns an error, nothing will be stored, the function's error be returned. The loaded result is true if the value was loaded, false if stored.

func (*Map) Merge

func (s *Map) Merge(m *Map) *Map

Merge merges a Map to Map s.

func (*Map) MergeMap

func (s *Map) MergeMap(m Mii) *Map

MergeMap merges a map to Map s.

func (*Map) MergeStrMap

func (s *Map) MergeStrMap(m M) *Map

MergeStrMap merges a map to Map s.

func (*Map) MergeStrStrMap

func (s *Map) MergeStrStrMap(m Mss) *Map

MergeStrStrMap merges a map to Map s.

func (*Map) MergeSyncMap

func (s *Map) MergeSyncMap(m *sync.Map) *Map

MergeSyncMap merges a sync.Map to Map s.

func (*Map) Pop

func (s *Map) Pop() (k, v interface{}, ok bool)

Pop returns the last element of map s or nil if the map is empty.

func (*Map) Range

func (s *Map) Range(f func(key, value interface{}) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range keep the sequence of store sequence.

func (*Map) RangeFast

func (s *Map) RangeFast(f func(key, value interface{}) bool)

RangeFast calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

RangeFast keep the sequence of store sequence.

RangeFast do not create a snapshot for range, so you can not modify map s in range loop, indicate do not call Delete(), Store(), LoadOrStore(), Merge(), etc.

func (*Map) Shift

func (s *Map) Shift() (k, v interface{}, ok bool)

Shift returns the first element of map s or nil if the map is empty.

func (*Map) Store

func (s *Map) Store(key, value interface{})

Store sets the value for a key.

func (*Map) StoreFront

func (s *Map) StoreFront(key, value interface{})

StoreFront sets the value for a key. The key will be stored the first in keys queue.

func (*Map) String

func (s *Map) String() string

String returns string format of the Set.

func (*Map) StringKeys

func (s *Map) StringKeys() (keys []string)

StringKeys returns all keys in map s and keep the sequence of store sequence.

func (*Map) ToMap

func (s *Map) ToMap() map[interface{}]interface{}

ToMap duplicates the map s.

func (*Map) ToStringMap

func (s *Map) ToStringMap() map[string]interface{}

ToStringMap duplicates the map s.

type Mii

type Mii = map[interface{}]interface{}

Mii alias of type map[interface{}]interface{}

type Mss

type Mss = map[string]string

Mss alias of type map[string]string

Jump to

Keyboard shortcuts

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