Documentation
¶
Index ¶
- func CopyReverse[V any](s []V) []V
- func Reverse[V any](s []V)
- func ToMap[Slice ~[]V, V any, K comparable](s Slice, getKey func(V) K) (result map[K]V)
- type Map
- type RWMutexMap
- func (sm *RWMutexMap[K, V]) Delete(key K)
- func (sm *RWMutexMap[K, V]) Len() int
- func (sm *RWMutexMap[K, V]) Load(key K) (value V, ok bool)
- func (sm *RWMutexMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (sm *RWMutexMap[K, V]) Range(f func(key K, value V) (shouldContinue bool))
- func (sm *RWMutexMap[K, V]) Store(key K, value V)
- type Slice
- type SyncMap
- func (t *SyncMap[K, V]) CompareAndDelete(old, new V) (deleted bool)
- func (t *SyncMap[K, V]) CompareAndSwap(k K, old, new V) (swapped bool)
- func (t *SyncMap[K, V]) Delete(key K)
- func (t *SyncMap[K, V]) Load(k K) (V, bool)
- func (t *SyncMap[K, V]) LoadOrStore(k K, v V) (actual V, loaded bool)
- func (t *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (t *SyncMap[K, V]) Store(k K, v V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyReverse ¶
func CopyReverse[V any](s []V) []V
func ToMap ¶
func ToMap[Slice ~[]V, V any, K comparable](s Slice, getKey func(V) K) (result map[K]V)
Types ¶
type Map ¶
type Map[K comparable, V any] interface { Load(K) (V, bool) Store(K, V) LoadOrStore(K, V) (actual V, loaded bool) Delete(K) Range(func(K, V) (shouldContinue bool)) }
type RWMutexMap ¶
type RWMutexMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewRWMutexMap ¶
func NewRWMutexMap[K comparable, V any]() *RWMutexMap[K, V]
func (*RWMutexMap[K, V]) Delete ¶
func (sm *RWMutexMap[K, V]) Delete(key K)
func (*RWMutexMap[K, V]) Len ¶
func (sm *RWMutexMap[K, V]) Len() int
func (*RWMutexMap[K, V]) Load ¶
func (sm *RWMutexMap[K, V]) Load(key K) (value V, ok bool)
func (*RWMutexMap[K, V]) LoadOrStore ¶
func (sm *RWMutexMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
func (*RWMutexMap[K, V]) Range ¶
func (sm *RWMutexMap[K, V]) Range(f func(key K, value V) (shouldContinue bool))
func (*RWMutexMap[K, V]) Store ¶
func (sm *RWMutexMap[K, V]) Store(key K, value V)
type Slice ¶
type Slice[K comparable, V any] []V
Slice的拓展方法
func (Slice[K, V]) CopyReverse ¶
func (Slice[K, V]) ExtractValues ¶
func (s Slice[K, V]) ExtractValues(getVal func(V) K) (result []K)
ExtractValues 提取slice中的值 * 示例:
var userList dataTools.Slice[uint, User]
userList = []User{
{ID: 1, Name: "test1", Password: "test2"},
{ID: 2, Name: "test2", Password: "test3"},
} // 或者 global.GvaDb.Limit(2).Find(&userList)
userIds := userList.ExtractValues(func(user User) uint {
return user.ID
})
fmt.Println(userIds) //将得到 [1 2]
func (Slice[K, V]) ToMap ¶
func (s Slice[K, V]) ToMap(getKey func(V) K) (result map[K]V)
ToMap slice转map * 示例:
var userList dataTools.Slice[uint, User]
userList = []User{
{ID: 1, Name: "test1", Password: "test2"},
{ID: 2, Name: "test2", Password: "test3"},
{ID: 3, Name: "test3", Password: "test3"},
} // 或者 global.GvaDb.Limit(5).Find(&userList)
userMap := userList.ToMap(func(user User) uint {
return user.ID
})
fmt.Println(userMap) //将得到 map[1:{1 test1 test2} 2:{2 test2 test3}]
type SyncMap ¶
type SyncMap[K comparable, V any] struct { Map sync.Map }
SyncMap is type-safe sync.Map
func NewSyncMap ¶
func NewSyncMap[K comparable, V any]() *SyncMap[K, V]
func (*SyncMap[K, V]) CompareAndDelete ¶
func (*SyncMap[K, V]) CompareAndSwap ¶
func (*SyncMap[K, V]) LoadOrStore ¶
Click to show internal directories.
Click to hide internal directories.