Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_text/tests/detect_corpus/go/canonical.txt

923 bytes, 1 run

created by r1870400018:11972, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1package main
2
3import (
4 "fmt"
5 "os"
6 "strings"
7 "sync"
8)
9
10type Cache struct {
11 mu sync.RWMutex
12 items map[string]string
13}
14
15func NewCache() *Cache {
16 return &Cache{
17 items: make(map[string]string),
18 }
19}
20
21func (c *Cache) Get(key string) (string, bool) {
22 c.mu.RLock()
23 defer c.mu.RUnlock()
24 val, ok := c.items[key]
25 return val, ok
26}
27
28func (c *Cache) Set(key, value string) {
29 c.mu.Lock()
30 defer c.mu.Unlock()
31 c.items[key] = value
32}
33
34func (c *Cache) Delete(key string) {
35 c.mu.Lock()
36 defer c.mu.Unlock()
37 delete(c.items, key)
38}
39
40func (c *Cache) Len() int {
41 c.mu.RLock()
42 defer c.mu.RUnlock()
43 return len(c.items)
44}
45
46func main() {
47 cache := NewCache()
48
49 for _, arg := range os.Args[1:] {
50 parts := strings.SplitN(arg, "=", 2)
51 if len(parts) == 2 {
52 cache.Set(parts[0], parts[1])
53 }
54 }
55
56 fmt.Printf("cache has %d entries\n", cache.Len())
57
58 if val, ok := cache.Get("name"); ok {
59 fmt.Printf("name = %s\n", val)
60 }
61}