package two import "sync" type robotCache struct { mu *sync.RWMutex data map[string]map[int]int } func newRobotCache() robotCache { return robotCache{ mu: &sync.RWMutex{}, data: make(map[string]map[int]int), } } func (rc *robotCache) read(moves string, id int) (int, bool) { rc.mu.RLock() defer rc.mu.RUnlock() v, ok := rc.data[moves][id] return v, ok } func (rc *robotCache) contains(moves string) bool { rc.mu.RLock() defer rc.mu.RUnlock() _, ok := rc.data[moves] return ok } func (rc *robotCache) insert(moves string, id, val int) { rc.mu.Lock() defer rc.mu.Unlock() if _, ok := rc.data[moves]; !ok { rc.data[moves] = make(map[int]int) } rc.data[moves][id] = val }