~rbn/neinp

ref: 280ca11dc4f314d4bb506de2f219eb70dd959227 neinp/fid/map.go -rw-r--r-- 470 bytes
280ca11dRuben Schuller update go.mod 1 year, 2 months ago
                                                                                
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
package fid

import (
	"sync"
)

type Map struct {
	fids map[Fid]interface{}
	sync.RWMutex
}

func New() *Map {
	return &Map{fids: make(map[Fid]interface{})}
}

func (f *Map) Get(fid Fid) interface{} {
	f.RLock()
	defer f.RUnlock()

	v, ok := f.fids[fid]
	if !ok {
		return nil
	}

	return v
}

func (f *Map) Set(fid Fid, v interface{}) {
	f.Lock()
	defer f.Unlock()
	f.fids[fid] = v
}

func (f *Map) Delete(fid Fid) {
	f.Lock()
	defer f.Unlock()
	delete(f.fids, fid)
}