-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.go
138 lines (118 loc) · 2.44 KB
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package po
import (
"sync"
)
type Map sync.Map
func (m *Map) Load(key interface{}) (value interface{}, ok bool) {
return (*sync.Map)(m).Load(key)
}
func (m *Map) Store(key, value interface{}) {
(*sync.Map)(m).Store(key, value)
}
func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) {
return (*sync.Map)(m).LoadOrStore(key, value)
}
func (m *Map) LoadAndDelete(key interface{}) (value interface{}, loaded bool) {
return (*sync.Map)(m).LoadAndDelete(key)
}
func (m *Map) Delete(key interface{}) {
(*sync.Map)(m).Delete(key)
}
func (m *Map) Range(f func(key, value interface{}) bool) {
(*sync.Map)(m).Range(f)
}
func (m *Map) Len() int {
i := 0
m.Range(func(_, _ interface{}) bool {
i++
return true
})
return i
}
func (m *Map) Keys() []interface{} {
mapLen := m.Len()
if mapLen == 0 {
return nil
}
keys := make([]interface{}, 0, mapLen)
m.Range(func(key, _ interface{}) bool {
keys = append(keys, key)
return true
})
return keys
}
func (m *Map) Values() []interface{} {
mapLen := m.Len()
if mapLen == 0 {
return nil
}
values := make([]interface{}, 0, mapLen)
m.Range(func(_, value interface{}) bool {
values = append(values, value)
return true
})
return values
}
func (m *Map) LoadString(key interface{}) (string, bool) {
v, ok := m.Load(key)
if !ok {
return "", false
}
return v.(string), true
}
func (m *Map) LoadInt(key interface{}) (int, bool) {
v, ok := m.Load(key)
if !ok {
return 0, false
}
return v.(int), true
}
func (m *Map) LoadUint16(key interface{}) (uint16, bool) {
v, ok := m.Load(key)
if !ok {
return 0, false
}
return v.(uint16), true
}
func (m *Map) LoadUint32(key interface{}) (uint32, bool) {
v, ok := m.Load(key)
if !ok {
return 0, false
}
return v.(uint32), true
}
func (m *Map) LoadUint64(key interface{}) (uint64, bool) {
v, ok := m.Load(key)
if !ok {
return 0, false
}
return v.(uint64), true
}
func (m *Map) LoadInt64(key interface{}) (int64, bool) {
v, ok := m.Load(key)
if !ok {
return 0, false
}
return v.(int64), true
}
func (m *Map) LoadBytes(key interface{}) ([]byte, bool) {
v, ok := m.Load(key)
if !ok {
return nil, false
}
return v.([]byte), true
}
func (m *Map) LoadFloat32(key interface{}) (float32, bool) {
v, ok := m.Load(key)
if !ok {
return 0, false
}
return v.(float32), true
}
func (m *Map) LoadFloat64(key interface{}) (float64, bool) {
v, ok := m.Load(key)
if !ok {
return 0, false
}
return v.(float64), true
}