diff --git a/go.mod b/go.mod index 61ae965..feea5cd 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,3 @@ -module github.com/goombaio/orderedmap +module github.com/shiyuleixia/orderedmap + +go 1.15 diff --git a/orderedmap.go b/orderedmap.go index 05736bb..c64bc6b 100644 --- a/orderedmap.go +++ b/orderedmap.go @@ -25,7 +25,7 @@ import ( // OrderedMap represents an associative array or map abstract data type. type OrderedMap struct { // mu Mutex protects data structures below. - mu sync.Mutex + mu sync.RWMutex // keys is the Set list of keys. keys []interface{} @@ -60,8 +60,8 @@ func (m *OrderedMap) Put(key interface{}, value interface{}) { // Get returns the value of a key from the OrderedMap. func (m *OrderedMap) Get(key interface{}) (value interface{}, found bool) { - m.mu.Lock() - defer m.mu.Unlock() + m.mu.RLock() + defer m.mu.RUnlock() value, found = m.store[key] return value, found