kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

commit 22c963d406978263f6ecdd6aadc9f8419b0fbb3f
parent cb3f7d37ccb4faf91a0352093c2d701b8170961c
Author: sin <sin@2f30.org>
Date:   Wed,  1 May 2013 11:27:27 +0100

rename `dict' to `cache'

Diffstat:
Msrc/mapfs/mapfs.go | 50+++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/mapfs/mapfs.go b/src/mapfs/mapfs.go @@ -18,7 +18,7 @@ type Mapfs struct { name string path string prefix string - dict map[int]mapfsVal + cache map[int]mapfsVal cacheOnly bool encrypt bool cipher *blowfish.Cipher @@ -37,8 +37,8 @@ func MakeMapIter(m *Mapfs) MapIter { return func() (key int, data []byte, ok bool) { m.Lock() defer m.Unlock() - for i < len(m.dict) { - v, ok := m.dict[i] + for i < len(m.cache) { + v, ok := m.cache[i] if ok { i++ if m.encrypt { @@ -60,7 +60,7 @@ func NewMapfs(name string, path string, prefix string) *Mapfs { name: name, path: path, prefix: prefix, - dict: make(map[int]mapfsVal), + cache: make(map[int]mapfsVal), cacheOnly: false, encrypt: false, cipher: nil, @@ -77,7 +77,7 @@ func NewEncryptedMapfs(name string, path string, prefix string, key string) *Map name: name, path: path, prefix: prefix, - dict: make(map[int]mapfsVal), + cache: make(map[int]mapfsVal), cacheOnly: false, encrypt: true, cipher: c, @@ -91,13 +91,13 @@ func (m *Mapfs) Sync() error { if m.cacheOnly { return nil } - for k, v := range m.dict { + for k, v := range m.cache { if v.dirty { err := m.fsWrite(k, v.data) if err != nil { return err } - m.dict[k] = mapfsVal{false, v.data} + m.cache[k] = mapfsVal{false, v.data} if !m.encrypt { fmt.Printf("Synced entry (%d, %v)\n", k, v.data) @@ -121,7 +121,7 @@ func (m *Mapfs) String() string { m.Lock() defer m.Unlock() s := fmt.Sprintf("*** %s MAP DUMP ***\n", m.name) - for k, v := range m.dict { + for k, v := range m.cache { dirty := "" if v.dirty { dirty = "yes" @@ -138,8 +138,8 @@ func (m *Mapfs) String() string { func (m *Mapfs) virtSync() { m.Lock() defer m.Unlock() - for k, v := range m.dict { - m.dict[k] = mapfsVal{false, v.data} + for k, v := range m.cache { + m.cache[k] = mapfsVal{false, v.data} } } @@ -190,7 +190,7 @@ func (m *Mapfs) CountMatches(buf []byte) int { ct := m.encryptBuf(buf) raw = ct } - for _, v := range m.dict { + for _, v := range m.cache { if bytes.Equal(v.data, raw) { i++ } @@ -204,16 +204,16 @@ func (m *Mapfs) Put(key int, buf []byte) error { if key < 0 { return fmt.Errorf("Invalid key: %d", key) } - _, ok := m.dict[key] + _, ok := m.cache[key] if ok { return fmt.Errorf("Key %d already in use", key) } if m.encrypt { ct := m.encryptBuf(buf) - m.dict[key] = mapfsVal{true, ct} + m.cache[key] = mapfsVal{true, ct} return nil } - m.dict[key] = mapfsVal{true, buf} + m.cache[key] = mapfsVal{true, buf} return nil } @@ -223,12 +223,12 @@ func (m *Mapfs) Append(buf []byte) (int, error) { defer m.Unlock() if m.encrypt { ct := m.encryptBuf(buf) - key := len(m.dict) - m.dict[key] = mapfsVal{true, ct} + key := len(m.cache) + m.cache[key] = mapfsVal{true, ct} return key, nil } - key := len(m.dict) - m.dict[key] = mapfsVal{true, buf} + key := len(m.cache) + m.cache[key] = mapfsVal{true, buf} return key, nil } @@ -236,10 +236,10 @@ func (m *Mapfs) Append(buf []byte) (int, error) { func (m *Mapfs) Get(key int) ([]byte, error) { m.Lock() defer m.Unlock() - if len(m.dict) == 0 { + if len(m.cache) == 0 { return nil, fmt.Errorf("Empty map, can't fetch entry") } - val, ok := m.dict[key] + val, ok := m.cache[key] if !ok { return nil, fmt.Errorf("No entry with key: %d", key) } @@ -253,11 +253,11 @@ func (m *Mapfs) Get(key int) ([]byte, error) { func (m *Mapfs) Rand() ([]byte, int) { m.Lock() defer m.Unlock() - idx := rand.Intn(len(m.dict)) + idx := rand.Intn(len(m.cache)) i := 0 - for k, _ := range m.dict { + for k, _ := range m.cache { if i == idx { - val := m.dict[k] + val := m.cache[k] if m.encrypt { pt := m.decryptBuf(val.data) return pt, k @@ -272,7 +272,7 @@ func (m *Mapfs) Rand() ([]byte, int) { func (m *Mapfs) Empty() bool { m.Lock() defer m.Unlock() - if len(m.dict) == 0 { + if len(m.cache) == 0 { return true } return false @@ -281,7 +281,7 @@ func (m *Mapfs) Empty() bool { func (m *Mapfs) Len() int { m.Lock() defer m.Unlock() - return len(m.dict) + return len(m.cache) } func (m *Mapfs) encryptBuf(a []byte) []byte {