2 Star 2 Fork 6

王布衣 / gox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hashmap.go 519 Bytes
一键复制 编辑 原始数据 按行查看 历史
package concurrent
import "sync"
type v1HashMap[K comparable, V any] struct {
mutex sync.RWMutex
m map[K]V
once sync.Once
}
func v1NewHashmap[K comparable, V any]() *v1HashMap[K, V] {
hashmap := v1HashMap[K, V]{}
hashmap.m = make(map[K]V)
return &hashmap
}
func (this *v1HashMap[K, V]) Get(key K) (V, bool) {
this.mutex.RLock()
v, ok := this.m[key]
this.mutex.RUnlock()
return v, ok
}
func (this *v1HashMap[K, V]) Put(key K, value V) {
this.mutex.Lock()
this.m[key] = value
this.mutex.Unlock()
}
Go
1
https://gitee.com/quant1x/gox.git
git@gitee.com:quant1x/gox.git
quant1x
gox
gox
v1.21.1

搜索帮助