From d2690dc8a3ce794e1034ffdcbb82b080d3e81d9e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 22 Nov 2021 13:58:59 +0100 Subject: adjust interface --- btree/btree.go | 36 ++++++++++++++++++++---------------- hash/hash.go | 36 ++++++++++++++++++++---------------- hash/hash_test.go | 8 ++++---- recno/recno.go | 32 ++++++++++++++++++-------------- 4 files changed, 62 insertions(+), 50 deletions(-) diff --git a/btree/btree.go b/btree/btree.go index 9936325..faeec51 100644 --- a/btree/btree.go +++ b/btree/btree.go @@ -1,44 +1,48 @@ package btree -import "os" +import ( + "os" + + "dim13.org/db" +) const ( - Magic = 0x053162 - Version = 3 + magic = 0x053162 + version = 3 ) type BTree struct { file *os.File } -func New(file *os.File) *BTree { +func New(file *os.File) db.DB { return &BTree{file: file} } -func (b *BTree) Close() error { +func (b *BTree) Close() (err error) { return b.file.Close() } -func (b *BTree) Del(key []byte, flags uint) error { - panic("not implemented") +func (b *BTree) Del(key []byte, flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (b *BTree) Fd() uintptr { +func (b *BTree) Fd() (fd uintptr) { return b.file.Fd() } -func (b *BTree) Get(key []byte, flags uint) ([]byte, error) { - panic("not implemented") +func (b *BTree) Get(key []byte, flag uint) (data []byte, err error) { + panic("not implemented") // TODO: Implement } -func (b *BTree) Put(key []byte, data []byte, flags uint) error { - panic("not implemented") +func (b *BTree) Put(key []byte, data []byte, flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (b *BTree) Sync(flags uint) error { - panic("not implemented") +func (b *BTree) Sync(flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (b *BTree) Seq(key []byte, flags uint) ([]byte, error) { - panic("not implemented") +func (b *BTree) Seq(flag uint) (key []byte, data []byte, err error) { + panic("not implemented") // TODO: Implement } diff --git a/hash/hash.go b/hash/hash.go index 861dd90..3d6392a 100644 --- a/hash/hash.go +++ b/hash/hash.go @@ -1,10 +1,14 @@ package hash -import "os" +import ( + "os" + + "dim13.org/db" +) const ( - Magic = 0x061561 - Version = 2 + magic = 0x061561 + version = 2 ) type Hash struct { @@ -16,37 +20,37 @@ type Hash struct { Hash func([]byte) uint32 // user defined hash function } -func New(file *os.File) *Hash { +func New(file *os.File) db.DB { return &Hash{ file: file, Hash: defaultHash, } } -func (h *Hash) Close() error { +func (h *Hash) Close() (err error) { return h.file.Close() } -func (h *Hash) Del(key []byte, flags uint) error { - panic("not implemented") +func (h *Hash) Del(key []byte, flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (h *Hash) Fd() uintptr { +func (h *Hash) Fd() (fd uintptr) { return h.file.Fd() } -func (h *Hash) Get(key []byte, flags uint) ([]byte, error) { - panic("not implemented") +func (h *Hash) Get(key []byte, flag uint) (data []byte, err error) { + panic("not implemented") // TODO: Implement } -func (h *Hash) Put(key []byte, data []byte, flags uint) error { - panic("not implemented") +func (h *Hash) Put(key []byte, data []byte, flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (h *Hash) Sync(flags uint) error { - panic("not implemented") +func (h *Hash) Sync(flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (h *Hash) Seq(key []byte, flags uint) ([]byte, error) { - panic("not implemented") +func (h *Hash) Seq(flag uint) (key []byte, data []byte, err error) { + panic("not implemented") // TODO: Implement } diff --git a/hash/hash_test.go b/hash/hash_test.go index da3a4a6..66eca95 100644 --- a/hash/hash_test.go +++ b/hash/hash_test.go @@ -16,11 +16,11 @@ func TestOpen(t *testing.T) { if err := binary.Read(fd, binary.BigEndian, &hdr); err != nil { t.Fatal(err) } - if hdr.Magic != Magic { - t.Errorf("got %x, want %x", hdr.Magic, Magic) + if hdr.Magic != magic { + t.Errorf("got %x, want %x", hdr.Magic, magic) } - if hdr.Version != Version { - t.Errorf("got %x, want %x", hdr.Version, Version) + if hdr.Version != version { + t.Errorf("got %x, want %x", hdr.Version, version) } t.Logf("%+v", hdr) } diff --git a/recno/recno.go b/recno/recno.go index 07a2050..09aef31 100644 --- a/recno/recno.go +++ b/recno/recno.go @@ -1,39 +1,43 @@ package recno -import "os" +import ( + "os" + + "dim13.org/db" +) type RecNo struct { file *os.File } -func New(file *os.File) *RecNo { +func New(file *os.File) db.DB { return &RecNo{file: file} } -func (r *RecNo) Close() error { +func (r *RecNo) Close() (err error) { return r.file.Close() } -func (r *RecNo) Del(key []byte, flags uint) error { - panic("not implemented") +func (r *RecNo) Del(key []byte, flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (r *RecNo) Fd() uintptr { +func (r *RecNo) Fd() (fd uintptr) { return r.file.Fd() } -func (r *RecNo) Get(key []byte, flags uint) ([]byte, error) { - panic("not implemented") +func (r *RecNo) Get(key []byte, flag uint) (data []byte, err error) { + panic("not implemented") // TODO: Implement } -func (r *RecNo) Put(key []byte, data []byte, flags uint) error { - panic("not implemented") +func (r *RecNo) Put(key []byte, data []byte, flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (r *RecNo) Sync(flags uint) error { - panic("not implemented") +func (r *RecNo) Sync(flag uint) (err error) { + panic("not implemented") // TODO: Implement } -func (r *RecNo) Seq(key []byte, flags uint) ([]byte, error) { - panic("not implemented") +func (r *RecNo) Seq(flag uint) (key []byte, data []byte, err error) { + panic("not implemented") // TODO: Implement } -- cgit v1.2.3