-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathregular.go
65 lines (54 loc) · 1.07 KB
/
regular.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
package main
import (
"sync"
)
type RegularStringMap struct {
sync.RWMutex
internal map[string]string
}
func NewRegularStringMap() *RegularStringMap {
return &RegularStringMap{
internal: make(map[string]string),
}
}
func (rm *RegularStringMap) Load(key string) (value string, ok bool) {
rm.RLock()
result, ok := rm.internal[key]
rm.RUnlock()
return result, ok
}
func (rm *RegularStringMap) Delete(key string) {
rm.Lock()
delete(rm.internal, key)
rm.Unlock()
}
func (rm *RegularStringMap) Store(key, value string) {
rm.Lock()
rm.internal[key] = value
rm.Unlock()
}
type RegularIntMap struct {
sync.RWMutex
internal map[int]int
}
func NewRegularIntMap() *RegularIntMap {
return &RegularIntMap{
internal: make(map[int]int),
}
}
func (rm *RegularIntMap) Load(key int) (value int, ok bool) {
rm.RLock()
result, ok := rm.internal[key]
rm.RUnlock()
return result, ok
}
func (rm *RegularIntMap) Delete(key int) {
rm.Lock()
delete(rm.internal, key)
rm.Unlock()
}
func (rm *RegularIntMap) Store(key, value int) {
rm.Lock()
rm.internal[key] = value
rm.Unlock()
}