Skip to content

Commit

Permalink
update cause of update
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintWish committed Dec 26, 2023
1 parent c5c2d06 commit f9af0d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions kv1/shardmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (m *shard[K, V]) get(key K) (val V) {
func (m *shard[K, V]) getRenew(key K) (val V) {
m.Lock()

if v,ok := m.Map.GetHas(key); ok {
if ok,v := m.Map.GetHas(key); ok {
v.Expire = time.Now().Add(m.Expiration)
m.Map.Set(key, v)
val = v.Object
Expand All @@ -66,7 +66,7 @@ func (m *shard[K, V]) has(key K) (ok bool) {
func (m *shard[K, V]) getHas(key K) (val V, ok bool) {
m.RLock()

v,ok := m.Map.GetHas(key);
ok,v := m.Map.GetHas(key);
val = v.Object

m.RUnlock()
Expand All @@ -77,7 +77,7 @@ func (m *shard[K, V]) getHas(key K) (val V, ok bool) {
func (m *shard[K, V]) getHasRenew(key K) (val V, ok bool) {
m.Lock()

if v,ok := m.Map.GetHas(key); ok {
if ok,v := m.Map.GetHas(key); ok {
v.Expire = time.Now().Add(m.Expiration)
m.Map.Set(key, v)
val = v.Object
Expand Down Expand Up @@ -118,7 +118,7 @@ func (m *shard[K, V]) delete(key K) (ok bool) {
func (m *shard[K, V]) isExpired(key K) (ex bool) {
m.RLock()

if v, ok := m.Map.GetHas(key); ok {
if ok,v:= m.Map.GetHas(key); ok {
ex = time.Now().After(v.Expire)
}

Expand All @@ -131,7 +131,7 @@ func (m *shard[K, V]) evictItem(key K, cb func(K,V)) (ex bool) {
m.Lock()

ex = false
if v, ok := m.Map.GetHas(key); ok {
if ok,v := m.Map.GetHas(key); ok {
if time.Now().After(v.Expire) {
ex = true
cb(key, v.Object)
Expand Down Expand Up @@ -169,7 +169,7 @@ func (m *shard[K, V]) renew(key K) {

m.Lock()

if v, ok := m.Map.GetHas(key); ok {
if ok,v := m.Map.GetHas(key); ok {
v.Expire = expire
}

Expand Down
8 changes: 4 additions & 4 deletions kv1s/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func (m *shard[K, V]) has(key K) bool {
return ok
}

func (m *shard[K, V]) getHas(key K) (V, bool) {
func (m *shard[K, V]) getHas(key K) (val V, ok bool) {
m.RLock()

val, ok := m.Map.GetHas(key)
ok, val = m.Map.GetHas(key)

m.RUnlock()

return val, ok
return
}

func (m *shard[K, V]) getHasRenew(key K) (V, bool) {
Expand Down Expand Up @@ -72,7 +72,7 @@ func (m *shard[K, V]) set(key K, val V, callback func(K, V)) {
func (m *shard[K, V]) update(key K, val V) {
m.Lock()

if val, ok := m.Map.GetHas(key); ok {
if ok, val := m.Map.GetHas(key); ok {
m.Map.Set(key, val)
}

Expand Down
6 changes: 3 additions & 3 deletions kv2/shardcapcity.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (m *shardCapacity[K, V]) has(key K) bool {
func (m *shardCapacity[K, V]) getHasRenew(key K) (V, bool) {
m.Lock()

val, ok := m.Map.GetHas(key)
ok,val := m.Map.GetHas(key)
val.Index = m.Stack.MoveToBack(val.Index)
m.Map.Set(key, val)

Expand All @@ -51,7 +51,7 @@ func (m *shardCapacity[K, V]) getHasRenew(key K) (V, bool) {
func (m *shardCapacity[K, V]) getHas(key K) (V, bool) {
m.RLock()

val, ok := m.Map.GetHas(key)
ok,val := m.Map.GetHas(key)

m.RUnlock()

Expand Down Expand Up @@ -111,7 +111,7 @@ func (m *shardCapacity[K, V]) set(key K, val V, callback func(K, V)) {
func (m *shardCapacity[K, V]) update(key K, val V) {
m.Lock()

if v, ok := m.Map.GetHas(key); ok {
if ok,v := m.Map.GetHas(key); ok {
v.Object = val
v.Index = m.Stack.MoveToBack(v.Index)
m.Map.Set(key, v)
Expand Down

0 comments on commit f9af0d5

Please sign in to comment.