1//go:build !go1.9
2// +build !go1.9
3
4package crr
5
6import (
7	"sync"
8)
9
10type syncMap struct {
11	container map[interface{}]interface{}
12	lock      sync.RWMutex
13}
14
15func newSyncMap() syncMap {
16	return syncMap{
17		container: map[interface{}]interface{}{},
18	}
19}
20
21func (m *syncMap) Load(key interface{}) (interface{}, bool) {
22	m.lock.RLock()
23	defer m.lock.RUnlock()
24
25	v, ok := m.container[key]
26	return v, ok
27}
28
29func (m *syncMap) Store(key interface{}, value interface{}) {
30	m.lock.Lock()
31	defer m.lock.Unlock()
32
33	m.container[key] = value
34}
35
36func (m *syncMap) Delete(key interface{}) {
37	m.lock.Lock()
38	defer m.lock.Unlock()
39
40	delete(m.container, key)
41}
42
43func (m *syncMap) Range(f func(interface{}, interface{}) bool) {
44	for k, v := range m.container {
45		if !f(k, v) {
46			return
47		}
48	}
49}
50