Compare commits
No commits in common. "main" and "v0.0.2" have entirely different histories.
21
map.go
21
map.go
@ -101,24 +101,3 @@ func (m *Map[K, V]) Do(f func(m map[K]V)) {
|
|||||||
defer m.mutex.Unlock()
|
defer m.mutex.Unlock()
|
||||||
f(m.data)
|
f(m.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoWithError calls f with the underlying primitive map and returns its error.
|
|
||||||
// Be aware that this locks m for write access
|
|
||||||
// so Do can be used for reading as well as modifiying m.
|
|
||||||
func (m *Map[K, V]) DoWithError(f func(m map[K]V) error) error {
|
|
||||||
m.mutex.Lock()
|
|
||||||
defer m.mutex.Unlock()
|
|
||||||
return f(m.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone returns a copy of the underlying map data
|
|
||||||
func (m *Map[K, V]) Clone() map[K]V {
|
|
||||||
m.mutex.RLock()
|
|
||||||
defer m.mutex.RUnlock()
|
|
||||||
|
|
||||||
c := map[K]V{}
|
|
||||||
for key, value := range m.data {
|
|
||||||
c[key] = value
|
|
||||||
}
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user