1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
This commit is contained in:
2022-05-12 09:35:20 +08:00
parent ffaf129ddb
commit 6731e53d7c
6 changed files with 126 additions and 20 deletions

View File

@ -13,8 +13,9 @@ type rw_map[K constraints.Ordered, V any] struct {
mu sync.RWMutex
}
func NewRWMap[K constraints.Ordered, V any]() *rw_map[K, V] {
return &rw_map[K, V]{}
func NewRWMap[K constraints.Ordered, V any](maps ...map[K]V) *rw_map[K, V] {
merged := Merge(maps...)
return &rw_map[K, V]{m: newHashMap(merged)}
}
func newRWMap[K constraints.Ordered, V any](m Map[K, V]) *rw_map[K, V] {
@ -41,6 +42,26 @@ func (m *rw_map[K, V]) Delete(key K) {
m.m.Delete(key)
}
func (m *rw_map[K, V]) Keys() []K {
m.mu.RLock()
defer m.mu.RUnlock()
return m.m.Keys()
}
func (m *rw_map[K, V]) Values() []V {
m.mu.RLock()
defer m.mu.RUnlock()
return m.m.Values()
}
func (m *rw_map[K, V]) ToMap() map[K]V {
m.mu.RLock()
defer m.mu.RUnlock()
return m.m.ToMap()
}
func (m *rw_map[K, V]) Exist(key K) bool {
return m.m.Exist(key)
}