You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
540 B

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package db
  2. import (
  3. "fmt"
  4. )
  5. type MemDB struct {
  6. db map[string][]byte
  7. }
  8. func NewMemDB() (*MemDB) {
  9. database := &MemDB{db:make(map[string][]byte)}
  10. return database
  11. }
  12. func (db *MemDB) Put(key []byte, value []byte) {
  13. db.db[string(key)] = value
  14. }
  15. func (db *MemDB) Get(key []byte) ([]byte) {
  16. return db.db[string(key)]
  17. }
  18. func (db *MemDB) Delete(key []byte) {
  19. delete(db.db, string(key))
  20. }
  21. func (db *MemDB) Print() {
  22. for key, value := range db.db {
  23. fmt.Printf("[%x]:\t[%x]", []byte(key), value)
  24. }
  25. }