Skip to content

Commit

Permalink
*: maps.DeleteFunc
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Aug 30, 2024
1 parent 5b5f919 commit fe797eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
9 changes: 4 additions & 5 deletions pkg/local_object_storage/pilorama/forest.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pilorama

import (
"maps"
"slices"
"sort"
"strings"
Expand Down Expand Up @@ -185,11 +186,9 @@ func (f *memoryForest) TreeGetOpLog(cid cidSDK.ID, treeID string, height uint64)
func (f *memoryForest) TreeDrop(cid cidSDK.ID, treeID string) error {
cidStr := cid.String()
if treeID == "" {
for k := range f.treeMap {
if strings.HasPrefix(k, cidStr) {
delete(f.treeMap, k)
}
}
maps.DeleteFunc(f.treeMap, func(k string, _ *state) bool {
return strings.HasPrefix(k, cidStr)
})
} else {
fullID := cidStr + "/" + treeID
_, ok := f.treeMap[fullID]
Expand Down
9 changes: 4 additions & 5 deletions pkg/services/container/announcement/load/storage/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loadstorage

import (
"maps"
"slices"
"sync"

Expand Down Expand Up @@ -126,11 +127,9 @@ func (s *Storage) EpochEvent(e uint64) {
s.mtx.Lock()
defer s.mtx.Unlock()

for k := range s.mItems {
if k.epoch+s.estLifeCycle < e {
delete(s.mItems, k)
}
}
maps.DeleteFunc(s.mItems, func(k storageKey, _ *usedSpaceEstimations) bool {
return k.epoch+s.estLifeCycle < e
})
}

func finalEstimation(vals []uint64) uint64 {
Expand Down
9 changes: 4 additions & 5 deletions pkg/services/session/storage/temporary/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package temporary

import (
"maps"
"sync"

"github.com/mr-tron/base58"
Expand Down Expand Up @@ -52,9 +53,7 @@ func (s *TokenStore) RemoveOld(epoch uint64) {
s.mtx.Lock()
defer s.mtx.Unlock()

for k, tok := range s.tokens {
if tok.ExpiredAt() <= epoch {
delete(s.tokens, k)
}
}
maps.DeleteFunc(s.tokens, func(_ key, tok *storage.PrivateToken) bool {
return tok.ExpiredAt() <= epoch
})
}

0 comments on commit fe797eb

Please sign in to comment.