Neur0toxine
28f057e7b2
Some checks reported errors
continuous-integration/drone/push Build was killed
28 lines
391 B
Go
28 lines
391 B
Go
package types
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type Map[K comparable, V any] struct {
|
|
rw sync.RWMutex
|
|
m map[K]V
|
|
}
|
|
|
|
func NewMap[K comparable, V any]() *Map[K, V] {
|
|
return &Map[K, V]{m: make(map[K]V)}
|
|
}
|
|
|
|
func (t *Map[K, V]) Set(k K, v V) {
|
|
defer t.rw.Unlock()
|
|
t.rw.Lock()
|
|
t.m[k] = v
|
|
}
|
|
|
|
func (t *Map[K, V]) Get(k K) (val V, ok bool) {
|
|
defer t.rw.RUnlock()
|
|
t.rw.RLock()
|
|
val, ok = t.m[k]
|
|
return
|
|
}
|