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.

40 lines
663 B

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 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) Get(key []byte) []byte {
  13. return db.db[string(key)]
  14. }
  15. func (db *MemDB) Set(key []byte, value []byte) {
  16. db.db[string(key)] = value
  17. }
  18. func (db *MemDB) SetSync(key []byte, value []byte) {
  19. db.db[string(key)] = value
  20. }
  21. func (db *MemDB) Delete(key []byte) {
  22. delete(db.db, string(key))
  23. }
  24. func (db *MemDB) DeleteSync(key []byte) {
  25. delete(db.db, string(key))
  26. }
  27. func (db *MemDB) Print() {
  28. for key, value := range db.db {
  29. fmt.Printf("[%X]:\t[%X]\n", []byte(key), value)
  30. }
  31. }