File: mem_db.go

package info (click to toggle)
tendermint-go-db 0.0~git20160508.0.31fdd21-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 96 kB
  • ctags: 30
  • sloc: makefile: 2
file content (44 lines) | stat: -rw-r--r-- 703 bytes parent folder | download
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
39
40
41
42
43
44
package db

import (
	"fmt"
)

type MemDB struct {
	db map[string][]byte
}

func NewMemDB() *MemDB {
	database := &MemDB{db: make(map[string][]byte)}
	return database
}

func (db *MemDB) Get(key []byte) []byte {
	return db.db[string(key)]
}

func (db *MemDB) Set(key []byte, value []byte) {
	db.db[string(key)] = value
}

func (db *MemDB) SetSync(key []byte, value []byte) {
	db.db[string(key)] = value
}

func (db *MemDB) Delete(key []byte) {
	delete(db.db, string(key))
}

func (db *MemDB) DeleteSync(key []byte) {
	delete(db.db, string(key))
}

func (db *MemDB) Close() {
	db = nil
}

func (db *MemDB) Print() {
	for key, value := range db.db {
		fmt.Printf("[%X]:\t[%X]\n", []byte(key), value)
	}
}