Documentation
¶
Overview ¶
Package dict contains map-related functions.
Index ¶
- func DefaultGet[K comparable, V any](items map[K]V, key K, defaultValue V) V
- func Filter[K comparable, V any](items map[K]V, keep func(K, V) bool) map[K]V
- func Flags[T comparable](items []T, flag bool) map[T]bool
- func FromStruct[T, V any](structRef *T) (map[string]V, error)
- func Get[T any](obj Object, key string) (T, bool)
- func GetListRef[T any](obj Object, key string) []*T
- func GetRef[T any](obj Object, key string) *T
- func GroupByValue[K, V comparable](items map[K]V) map[V][]K
- func GroupByValueList[K, V comparable](items map[K][]V) map[V][]K
- func HasKey[K comparable, V any](items map[K]V, key K) bool
- func HasValue[K, V comparable](items map[K]V, value V) bool
- func Inspect[T any](structRef *T) string
- func Keys[K comparable, V any](items map[K]V) []K
- func Length[K comparable, V any](items map[K]V) int
- func MergeCounts[K comparable](counters []map[K]int) map[K]int
- func NoKey[K comparable, V any](items map[K]V, key K) bool
- func NoValue[K, V comparable](items map[K]V, value V) bool
- func SetDefault[K comparable, V any](items map[K]V, key K, defaultValue V)
- func SortValues[K comparable, V cmp.Ordered](items map[K][]V)
- func Swap[K, V comparable](items map[K]V) map[V]K
- func SwapList[K, V comparable](items map[K][]V) map[V]K
- func TallyValues[K, V comparable](items map[K]V, values []V) map[V]int
- func ToStruct[T any](obj Object) (*T, error)
- func Unzip[K comparable, V any](items map[K]V) ([]K, []V)
- func Update[K comparable, V any](oldMap, newMap map[K]V) map[K]V
- func UpdateCounter[T comparable](counter Counter[T], items []T)
- func UpdateCounts[K comparable](oldCounter, newCounter map[K]int)
- func Values[K comparable, V any](items map[K]V) []V
- func Zip[K comparable, V any](keys []K, values []V) map[K]V
- type BoolMap
- type Counter
- type Entry
- type IntCounter
- type IntMap
- type Object
- type StringCounter
- type StringListMap
- type StringMap
- type SyncMap
- func (sm *SyncMap[K, V]) Clear()
- func (sm *SyncMap[K, V]) ClearMap() map[K]V
- func (sm *SyncMap[K, V]) Delete(key K)
- func (sm *SyncMap[K, V]) DeleteKeys(keys []K)
- func (sm *SyncMap[K, V]) Get(key K) (V, bool)
- func (sm *SyncMap[K, V]) Keys() []K
- func (sm *SyncMap[K, V]) Len() int
- func (sm *SyncMap[K, V]) Map() map[K]V
- func (sm *SyncMap[K, V]) Set(key K, value V)
- func (sm *SyncMap[K, V]) SetIf(key K, value V, isValid func(V) bool) bool
- func (sm *SyncMap[K, V]) Values() []V
- type UintMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultGet ¶
func DefaultGet[K comparable, V any](items map[K]V, key K, defaultValue V) V
Get the value of key, or return default value if key is not in map
func Filter ¶
func Filter[K comparable, V any](items map[K]V, keep func(K, V) bool) map[K]V
Filter map: only keep entries that pass keep function
func Flags ¶
func Flags[T comparable](items []T, flag bool) map[T]bool
Create new boolean map, with each item initialized to flag boolean
func FromStruct ¶
Create map from given struct pointer
func GetListRef ¶
Get value = obj[key] then type coerce into []*T
func GroupByValue ¶
func GroupByValue[K, V comparable](items map[K]V) map[V][]K
Group data by values
func GroupByValueList ¶ added in v0.5.2
func GroupByValueList[K, V comparable](items map[K][]V) map[V][]K
Group data (map[K][]V) by values => map[V][]K
func MergeCounts ¶ added in v0.5.11
func MergeCounts[K comparable](counters []map[K]int) map[K]int
Merge the counts from counter maps into one map
func SetDefault ¶
func SetDefault[K comparable, V any](items map[K]V, key K, defaultValue V)
Set default value if key is not in map
func SortValues ¶ added in v0.5.2
func SortValues[K comparable, V cmp.Ordered](items map[K][]V)
Sort the list of values for each key
func Swap ¶
func Swap[K, V comparable](items map[K]V) map[V]K
Swap keys and values, convert map[K]V to map[V]K, Can lose data if values are not unique
func SwapList ¶
func SwapList[K, V comparable](items map[K][]V) map[V]K
Convert map[K][]V to map[V]K, Can lose data if values are not unique
func TallyValues ¶
func TallyValues[K, V comparable](items map[K]V, values []V) map[V]int
Create tally of how many times each value appears in the map
func Unzip ¶
func Unzip[K comparable, V any](items map[K]V) ([]K, []V)
Unzip the map, return list of keys and values, Order of keys is same as order of corresponding values
func Update ¶
func Update[K comparable, V any](oldMap, newMap map[K]V) map[K]V
Add entries of new map into old map, returns old map. If there are key conflicts, new map entries overwrite the old map entries.
func UpdateCounter ¶ added in v0.5.16
func UpdateCounter[T comparable](counter Counter[T], items []T)
Update the counter with the incoming items
func UpdateCounts ¶ added in v0.5.15
func UpdateCounts[K comparable](oldCounter, newCounter map[K]int)
Update the old counter with counts from new counter
func Zip ¶
func Zip[K comparable, V any](keys []K, values []V) map[K]V
Zip list of keys and values to create map
Types ¶
type Counter ¶ added in v0.5.15
type Counter[T comparable] = map[T]int
func CounterFunc ¶ added in v0.5.12
func CounterFunc[T any, K comparable](items []T, key func(T) K) Counter[K]
Create counter, with keys produced from keyFn
func NewCounter ¶
func NewCounter[T comparable](items []T) Counter[T]
Create new counter, with each item initialized to count=0
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V }
Key-Value pair
func SortedEntries ¶
Get map entries, sorted by keys
type IntCounter ¶
type StringCounter ¶
type StringListMap ¶
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
Concurrency-safe generic map
func SyncMapFrom ¶
func SyncMapFrom[K comparable, V any](items map[K]V) *SyncMap[K, V]
Create SyncMap from existing map
func (*SyncMap[K, V]) ClearMap ¶ added in v0.5.31
func (sm *SyncMap[K, V]) ClearMap() map[K]V
Copy SyncMap's underlying map and clear it
func (*SyncMap[K, V]) DeleteKeys ¶ added in v0.5.58
func (sm *SyncMap[K, V]) DeleteKeys(keys []K)
SyncMap.DeleteKeys