1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-19 09:02:39 +08:00
This commit is contained in:
2022-05-12 10:33:35 +08:00
parent 3dc3fbb0f2
commit 7930a64e59
5 changed files with 43 additions and 18 deletions

View File

@ -8,12 +8,13 @@ type hashMap[K constraints.Ordered, V any] struct {
m map[K]V
}
func NewHashMap[K constraints.Ordered, V any]() *hashMap[K, V] {
func NewHashMap[K constraints.Ordered, V any](maps ...map[K]V) *hashMap[K, V] {
return &hashMap[K, V]{m: make(map[K]V)}
}
func newHashMap[K constraints.Ordered, V any](maps ...map[K]V) *hashMap[K, V] {
return &hashMap[K, V]{m: Merge(maps...)}
// synchronized
func (m *hashMap[K, V]) Synchronized() *hashMap[K, V] {
return m
}
func (m *hashMap[K, V]) Set(key K, value V) {
@ -92,10 +93,5 @@ func (m *hashMap[K, V]) Count() int {
}
func (m *hashMap[K, V]) Clone() Map[K, V] {
r := make(map[K]V, len(m.m))
for k, v := range m.m {
r[k] = v
}
return newHashMap(r)
return NewHashMap(m.ToMap())
}