|
@@ -4,11 +4,11 @@ import (
|
|
|
"sync"
|
|
|
)
|
|
|
|
|
|
-type CallCreate func(key interface{}) (value interface{}, created bool)
|
|
|
-type CallCreateMulti func(key interface{}) (m map[interface{}]interface{}, created bool)
|
|
|
-type CallCheck func(key, value interface{}, exists bool) (rKey, rValue interface{}, created bool)
|
|
|
+type CallCreate func(key any) (value any, created bool)
|
|
|
+type CallCreateMulti func(key any) (m map[any]any, created bool)
|
|
|
+type CallCheck func(key, value any, exists bool) (rKey, rValue any, created bool)
|
|
|
|
|
|
-func FromMap(m map[interface{}]interface{}) *Store {
|
|
|
+func FromMap(m map[any]any) *Store {
|
|
|
return &Store{
|
|
|
locker: new(sync.RWMutex),
|
|
|
items: m,
|
|
@@ -18,26 +18,26 @@ func FromMap(m map[interface{}]interface{}) *Store {
|
|
|
func New() *Store {
|
|
|
return &Store{
|
|
|
locker: new(sync.RWMutex),
|
|
|
- items: make(map[interface{}]interface{}),
|
|
|
+ items: make(map[any]any),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
type Store struct {
|
|
|
locker *sync.RWMutex
|
|
|
- items map[interface{}]interface{}
|
|
|
+ items map[any]any
|
|
|
}
|
|
|
|
|
|
-func (s *Store) delete(key interface{}) {
|
|
|
+func (s *Store) delete(key any) {
|
|
|
delete(s.items, key)
|
|
|
}
|
|
|
|
|
|
-func (s *Store) Delete(key interface{}) {
|
|
|
+func (s *Store) Delete(key any) {
|
|
|
s.locker.Lock()
|
|
|
delete(s.items, key)
|
|
|
s.locker.Unlock()
|
|
|
}
|
|
|
|
|
|
-func (s *Store) DeleteMulti(keys []interface{}) {
|
|
|
+func (s *Store) DeleteMulti(keys []any) {
|
|
|
s.locker.Lock()
|
|
|
for _, key := range keys {
|
|
|
delete(s.items, key)
|
|
@@ -45,41 +45,41 @@ func (s *Store) DeleteMulti(keys []interface{}) {
|
|
|
s.locker.Unlock()
|
|
|
}
|
|
|
|
|
|
-func (s *Store) set(key, val interface{}) {
|
|
|
+func (s *Store) set(key, val any) {
|
|
|
s.items[key] = val
|
|
|
}
|
|
|
|
|
|
-func (s *Store) setMulti(m map[interface{}]interface{}) {
|
|
|
+func (s *Store) setMulti(m map[any]any) {
|
|
|
for key, val := range m {
|
|
|
s.items[key] = val
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (s *Store) Set(key, val interface{}) {
|
|
|
+func (s *Store) Set(key, val any) {
|
|
|
s.locker.Lock()
|
|
|
s.set(key, val)
|
|
|
s.locker.Unlock()
|
|
|
}
|
|
|
|
|
|
-func (s *Store) SetMulti(m map[interface{}]interface{}) {
|
|
|
+func (s *Store) SetMulti(m map[any]any) {
|
|
|
s.locker.Lock()
|
|
|
s.setMulti(m)
|
|
|
s.locker.Unlock()
|
|
|
}
|
|
|
|
|
|
-func (s *Store) get(key interface{}) (val interface{}, check bool) {
|
|
|
+func (s *Store) get(key any) (val any, check bool) {
|
|
|
val, check = s.items[key]
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (s *Store) Get(key interface{}) (val interface{}, check bool) {
|
|
|
+func (s *Store) Get(key any) (val any, check bool) {
|
|
|
s.locker.RLock()
|
|
|
val, check = s.get(key)
|
|
|
s.locker.RUnlock()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (s *Store) GetCreate(key interface{}, mCreate CallCreate) (res interface{}, check bool) {
|
|
|
+func (s *Store) GetCreate(key any, mCreate CallCreate) (res any, check bool) {
|
|
|
if res, check = s.Get(key); !check {
|
|
|
s.locker.Lock()
|
|
|
if res, check = s.get(key); check {
|
|
@@ -95,7 +95,7 @@ func (s *Store) GetCreate(key interface{}, mCreate CallCreate) (res interface{},
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (s *Store) GetCreateMulti(key interface{}, mCreateMulti CallCreateMulti) (res interface{}, check bool) {
|
|
|
+func (s *Store) GetCreateMulti(key any, mCreateMulti CallCreateMulti) (res any, check bool) {
|
|
|
if res, check = s.Get(key); !check {
|
|
|
s.locker.Lock()
|
|
|
if res, check = s.get(key); check {
|
|
@@ -103,7 +103,7 @@ func (s *Store) GetCreateMulti(key interface{}, mCreateMulti CallCreateMulti) (r
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- var m map[interface{}]interface{}
|
|
|
+ var m map[any]any
|
|
|
if m, check = mCreateMulti(key); check {
|
|
|
s.setMulti(m)
|
|
|
res, check = s.items[key]
|
|
@@ -113,7 +113,7 @@ func (s *Store) GetCreateMulti(key interface{}, mCreateMulti CallCreateMulti) (r
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (s *Store) GetCheck(key interface{}, mCheck CallCheck) (res interface{}, check bool) {
|
|
|
+func (s *Store) GetCheck(key any, mCheck CallCheck) (res any, check bool) {
|
|
|
s.locker.Lock()
|
|
|
res, check = s.get(key)
|
|
|
if rKey, rVal, rCheck := mCheck(key, res, check); rCheck {
|
|
@@ -125,7 +125,7 @@ func (s *Store) GetCheck(key interface{}, mCheck CallCheck) (res interface{}, ch
|
|
|
}
|
|
|
|
|
|
// Each implements a map bypass for each key using the callback function. If the callback function returns false, then the cycle stops
|
|
|
-func (s *Store) Each(callback func(interface{}, interface{}) bool) {
|
|
|
+func (s *Store) Each(callback func(any, any) bool) {
|
|
|
s.locker.RLock()
|
|
|
for key, val := range s.items {
|
|
|
if !callback(key, val) {
|
|
@@ -143,9 +143,9 @@ func (s *Store) Len() (res int) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (s *Store) Keys() (res []interface{}) {
|
|
|
+func (s *Store) Keys() (res []any) {
|
|
|
s.locker.RLock()
|
|
|
- res = make([]interface{}, 0, len(s.items))
|
|
|
+ res = make([]any, 0, len(s.items))
|
|
|
for key := range s.items {
|
|
|
res = append(res, key)
|
|
|
}
|
|
@@ -155,12 +155,12 @@ func (s *Store) Keys() (res []interface{}) {
|
|
|
|
|
|
func (s *Store) Clear() {
|
|
|
s.locker.Lock()
|
|
|
- s.items = make(map[interface{}]interface{})
|
|
|
+ s.items = make(map[any]any)
|
|
|
s.locker.Unlock()
|
|
|
}
|
|
|
|
|
|
-func (s *Store) Map() (res map[interface{}]interface{}) {
|
|
|
- res = make(map[interface{}]interface{})
|
|
|
+func (s *Store) Map() (res map[any]any) {
|
|
|
+ res = make(map[any]any)
|
|
|
s.locker.RLock()
|
|
|
for key, val := range s.items {
|
|
|
res[key] = val
|