Documentation ¶
Index ¶
- func AppendIfNotDuplicate[Type comparable](list []Type, item Type) []Type
- func ContainsItem[Type comparable](list []Type, item Type) bool
- func ContainsItemFn[Type any](list []Type, item Type, equal func(a, b Type) bool) bool
- func DiffSets[Type comparable](set1, set2 []Type) (onlyInSet1, onlyInSet2 []Type)
- func DiffSetsFn[Type any](set1, set2 []Type, equal func(a, b Type) bool) (onlyInSet1, onlyInSet2 []Type)
- func EqualLists[Type comparable](list1, list2 []Type) bool
- func EqualListsFn[Type any](list1, list2 []Type, equal func(a, b Type) bool) bool
- func EqualSets[Type comparable](set1, set2 []Type) bool
- func EqualSetsFn[Type any](set1, set2 []Type, equal func(a, b Type) bool) bool
- func FilterDuplicates[Type comparable](list []Type) (filtered []Type)
- func FilterDuplicatesFn[Type any](list []Type, equal func(a, b Type) bool) (filtered []Type)
- func FilterList[Type any](list []Type, keep func(a Type) bool) (filtered []Type)
- func MapList[Type1, Type2 any](list []Type1, mapFunc func(a Type1) Type2) []Type2
- type LockedMap
- func (lm *LockedMap[K, V]) ApplyOrStore(key K, applyFn LockedMapApplyFunc[V], defaultVal V) bool
- func (lm *LockedMap[K, V]) Delete(key K)
- func (lm *LockedMap[K, V]) Keys() []K
- func (lm *LockedMap[K, V]) Load(key K) (V, bool)
- func (lm *LockedMap[K, V]) Range(callback LockedMapFunc[K, V])
- func (lm *LockedMap[K, V]) Store(key K, value V)
- type LockedMapApplyFunc
- type LockedMapFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendIfNotDuplicate ¶
func AppendIfNotDuplicate[Type comparable](list []Type, item Type) []Type
AppendIfNotDuplicate adds item into list if the list does not yet contain the item.
func ContainsItem ¶
func ContainsItem[Type comparable](list []Type, item Type) bool
ContainsItem returns true if the slice contains the given item. This function can be used if slice items are comparable (operator "==" can be used).
func ContainsItemFn ¶
ContainsItemFn returns true if the slice contains the given item. Two slice items are compared using the provided "equal" callback.
func DiffSets ¶
func DiffSets[Type comparable](set1, set2 []Type) (onlyInSet1, onlyInSet2 []Type)
DiffSets returns slice with items that are present in the first slice but not in the second and vice versa. This function can be used if slice items are comparable (operator "==" can be used).
func DiffSetsFn ¶
func DiffSetsFn[Type any](set1, set2 []Type, equal func(a, b Type) bool) ( onlyInSet1, onlyInSet2 []Type)
DiffSetsFn returns slice with items that are present in the first slice but not in the second and vice versa. Two slice items are compared using the provided "equal" callback.
func EqualLists ¶
func EqualLists[Type comparable](list1, list2 []Type) bool
EqualLists returns true if the two slices representing lists (i.e. order dependent) are equal in size and items they contain. This function can be used if slice items are comparable (operator "==" can be used).
func EqualListsFn ¶
EqualListsFn returns true if the two slices representing lists (i.e. order dependent) are equal in size and items they contain. Two slice items are compared using the provided "equal" callback.
func EqualSets ¶
func EqualSets[Type comparable](set1, set2 []Type) bool
EqualSets returns true if the two slices that represent sets (i.e. order independent) are equal in size and items they contain. This function can be used if slice items are comparable (operator "==" can be used).
func EqualSetsFn ¶
EqualSetsFn returns true if the two slices that represent sets (i.e. order independent) are equal in size and items they contain. Two slice items are compared using the provided "equal" callback.
func FilterDuplicates ¶
func FilterDuplicates[Type comparable](list []Type) (filtered []Type)
FilterDuplicates return a new slice with duplicate entries removed. This function can be used if slice items are comparable (operator "==" can be used).
func FilterDuplicatesFn ¶
FilterDuplicatesFn return a new slice with duplicate entries removed. Two slice items are compared using the provided "equal" callback.
func FilterList ¶
FilterList return a new slice with items that pass the "keep" callback.
Types ¶
type LockedMap ¶
type LockedMap[K comparable, V any] struct { sync.RWMutex // contains filtered or unexported fields }
LockedMap is a wrapper on map with locking API is similar to sync.Map difference is that sync.Map is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times (2) when multiple goroutines read, write and overwrite entries for disjoint set of keys In these casees use sync.Map, in other cases consider using LockedMap
LockedMap should be created by calling NewLockedMap()
func NewLockedMap ¶
func NewLockedMap[K comparable, V any]() *LockedMap[K, V]
NewLockedMap returns initialized LockedMap struct
func (*LockedMap[K, V]) ApplyOrStore ¶
func (lm *LockedMap[K, V]) ApplyOrStore(key K, applyFn LockedMapApplyFunc[V], defaultVal V) bool
ApplyOrStore is used to perform atomic operations, where the operation is performed by the applyFn function. If the key does not exist in the map then defaultVal will be stored. Otherwise the entry for the key will be updated. returns true if the key existed when the function was called
func (*LockedMap[K, V]) Delete ¶
func (lm *LockedMap[K, V]) Delete(key K)
Delete removes value from map for given key
func (*LockedMap[K, V]) Keys ¶
func (lm *LockedMap[K, V]) Keys() []K
Keys return copy of keys for locked map
func (*LockedMap[K, V]) Load ¶
Load returns value for given key; bool shows if map contains variable
func (*LockedMap[K, V]) Range ¶
func (lm *LockedMap[K, V]) Range(callback LockedMapFunc[K, V])
Range iterates over map and applies callback to every element iteration stops if callback returns false. callback function is not allowed to do any changes on map (Store, Delete or Load) since that can deadlock
type LockedMapApplyFunc ¶
type LockedMapApplyFunc[V any] func(V) V
LockedMapApplyFunc is function signature for ApplyOrStore function
type LockedMapFunc ¶
type LockedMapFunc[K comparable, V any] func(K, V) bool
LockedMapFunc is function signature for Range function