Documentation
¶
Overview ¶
Hash based data structures and tool set.
RWMap is map with sync.RWMutex embedded.
StrRWMap is a string based, partitioned map, internally managing multiple RWMap to furture enhance parallel performance.
Set is a HashSet data structure backed by a map.
Index ¶
- func MapCopy[T comparable, V any](v map[T]V) map[T]V
- func MapFirst[K comparable, V any](m map[K]V) V
- func MapKV[T comparable, V any](m map[T]V) []pair.Pair[T, V]
- func MapKeys[T comparable, V any](m map[T]V) []T
- func MapValues[K comparable, V any](m map[K]V) []V
- func StrMap[T any, V any](l []T, keyMapper func(T) string, valueMapper func(T) V) map[string]V
- func StrSliceMap[T any, V any](l []T, keyMapper func(T) string, valueMapper func(T) V) map[string][]V
- type RWMap
- func (r *RWMap[K, V]) Clear()
- func (r *RWMap[K, V]) Del(k K) (prev V, hasPrev bool)
- func (r *RWMap[K, V]) Get(k K) (V, bool)
- func (r *RWMap[K, V]) GetElse(k K, elseFunc func(k K) V) (V, bool)
- func (r *RWMap[K, V]) GetElseErr(k K, elseFunc func(k K) (V, error)) (V, error)
- func (r *RWMap[K, V]) Keys() []K
- func (r *RWMap[K, V]) Put(k K, v V)
- func (r *RWMap[K, V]) PutIfAbsent(k K, f func() V)
- func (r *RWMap[K, V]) PutIfAbsentErr(k K, f func() (V, error)) error
- type Set
- func (s *Set[T]) Add(key T) bool
- func (s *Set[T]) AddAll(keys []T)
- func (s *Set[T]) AddThen(key T) *Set[T]
- func (s *Set[T]) All() iter.Seq[T]
- func (s *Set[T]) Clear()
- func (s *Set[T]) CopyKeys() []T
- func (s *Set[T]) Del(key T)
- func (s *Set[T]) ForEach(f func(v T) (stop bool))
- func (s *Set[T]) ForEachErr(f func(v T) (stop bool, err error)) error
- func (s Set[T]) GoString() string
- func (s *Set[T]) Has(key T) bool
- func (s *Set[T]) InSet(b Set[T]) iter.Seq[T]
- func (s *Set[T]) IsEmpty() bool
- func (s Set[T]) MarshalJSON() ([]byte, error)
- func (s *Set[T]) NotInSet(b Set[T]) iter.Seq[T]
- func (s *Set[T]) Scan(value interface{}) error
- func (s *Set[T]) Size() int
- func (s Set[T]) String() string
- func (s *Set[T]) UnmarshalJSON(b []byte) error
- func (s Set[T]) Value() (driver.Value, error)
- type StrRWMap
- func (r *StrRWMap[V]) Del(k string) (V, bool)
- func (r *StrRWMap[V]) Get(k string) (V, bool)
- func (r *StrRWMap[V]) GetElse(k string, elseFunc func(k string) V) (V, bool)
- func (r *StrRWMap[V]) GetElseErr(k string, elseFunc func(k string) (V, error)) (V, error)
- func (r *StrRWMap[V]) Keys() []string
- func (r *StrRWMap[V]) Put(k string, v V)
- func (r *StrRWMap[V]) PutIfAbsent(k string, f func() V)
- func (r *StrRWMap[V]) PutIfAbsentErr(k string, f func() (V, error))
- type SyncSet
- func (s *SyncSet[T]) Add(key T) bool
- func (s *SyncSet[T]) AddAll(keys []T)
- func (s *SyncSet[T]) All() iter.Seq[T]
- func (s *SyncSet[T]) Clear()
- func (s *SyncSet[T]) CopyKeys() []T
- func (s *SyncSet[T]) Del(key T)
- func (s *SyncSet[T]) GoString() string
- func (s *SyncSet[T]) Has(key T) bool
- func (s *SyncSet[T]) MarshalJSON() ([]byte, error)
- func (s *SyncSet[T]) Scan(value interface{}) error
- func (s *SyncSet[T]) Size() int
- func (s *SyncSet[T]) String() string
- func (s *SyncSet[T]) UnmarshalJSON(b []byte) error
- func (s *SyncSet[T]) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapCopy ¶
func MapCopy[T comparable, V any](v map[T]V) map[T]V
Types ¶
type RWMap ¶
type RWMap[K comparable, V any] struct { // contains filtered or unexported fields }
Map with sync.RWMutex embeded.
func (*RWMap[K, V]) GetElseErr ¶
func (*RWMap[K, V]) PutIfAbsent ¶
func (r *RWMap[K, V]) PutIfAbsent(k K, f func() V)
func (*RWMap[K, V]) PutIfAbsentErr ¶
type Set ¶
type Set[T comparable] struct { // Keys in Set Keys map[T]struct{} }
Hash Set.
It's internally backed by a Map.
To create a new Set, use NewSet.
func NewSetWithCap ¶ added in v0.4.0
func NewSetWithCap[T comparable](cap int, keys ...T) Set[T]
Create new Set with capacity.
func (*Set[T]) ForEachErr ¶ added in v0.4.0
func (Set[T]) MarshalJSON ¶ added in v0.3.8
Implements encoding/json Marshaler
func (*Set[T]) UnmarshalJSON ¶ added in v0.3.8
Implements encoding/json Unmarshaler.
type StrRWMap ¶
type StrRWMap[V any] struct { // contains filtered or unexported fields }
func NewStrRWMap ¶
Create new sharded, concurrent access StrRWMap.
func (*StrRWMap[V]) GetElseErr ¶
func (*StrRWMap[V]) PutIfAbsent ¶
func (*StrRWMap[V]) PutIfAbsentErr ¶
type SyncSet ¶ added in v0.4.10
type SyncSet[T comparable] struct { // contains filtered or unexported fields }
Hash Set.
It's internally backed by a Map.
To create a new Set, use NewSet.
func NewSyncSet ¶ added in v0.4.10
func NewSyncSet[T comparable](keys ...T) *SyncSet[T]
Create new SyncSet
func (*SyncSet[T]) Add ¶ added in v0.4.10
Add key to set, return true if the key wasn't present previously
func (*SyncSet[T]) MarshalJSON ¶ added in v0.4.10
Implements encoding/json Marshaler
func (*SyncSet[T]) UnmarshalJSON ¶ added in v0.4.10
Implements encoding/json Unmarshaler.