[WIP] Update linter config + speed optimizations
This commit is contained in:
@@ -4,16 +4,18 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Collection is sync.Map, that stores arbitrary data.
|
||||
type Collection struct {
|
||||
items sync.Map
|
||||
close chan struct{}
|
||||
}
|
||||
type (
|
||||
// Collection is sync.Map, that stores arbitrary data.
|
||||
Collection struct {
|
||||
close chan struct{}
|
||||
items sync.Map
|
||||
}
|
||||
|
||||
// Item just interface for stoing any data.
|
||||
type item struct {
|
||||
data any
|
||||
}
|
||||
// Item just interface for stoing any data.
|
||||
item struct {
|
||||
data any
|
||||
}
|
||||
)
|
||||
|
||||
// NewCollection creates new instance of "collection".
|
||||
func NewCollection() *Collection {
|
||||
@@ -44,7 +46,7 @@ func (collection *Collection) Set(key any, value any) {
|
||||
})
|
||||
}
|
||||
|
||||
// Range apply function f to all keys/values in collection. Retuns immediatly on first error.
|
||||
// Range apply function f to all keys/values in collection. Returns immediately on first error.
|
||||
func (collection *Collection) Range(f func(key, value any) bool) {
|
||||
fn := func(key, value any) bool {
|
||||
item := value.(item)
|
||||
@@ -63,6 +65,7 @@ func (collection *Collection) Delete(key any) {
|
||||
// Close frees memory occupied by collection and deletes collection itself.
|
||||
func (collection *Collection) Close() {
|
||||
collection.close <- struct{}{}
|
||||
|
||||
collection.items = sync.Map{}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user