aboutsummaryrefslogtreecommitdiff
path: root/rwtransaction.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-05 21:50:15 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-05 21:50:15 -0700
commit4820312de29f446152fce216c17a696576e89d78 (patch)
tree31e748c7f977071af779aaa42a80ff728b495da6 /rwtransaction.go
parentAdd pre-alpha badge. (diff)
parentFix quick tests. (diff)
downloaddedo-4820312de29f446152fce216c17a696576e89d78.tar.gz
dedo-4820312de29f446152fce216c17a696576e89d78.tar.xz
Merge pull request #7 from benbjohnson/delete
RWTransaction.Delete()
Diffstat (limited to 'rwtransaction.go')
-rw-r--r--rwtransaction.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/rwtransaction.go b/rwtransaction.go
index 2485c62..93e544b 100644
--- a/rwtransaction.go
+++ b/rwtransaction.go
@@ -70,19 +70,29 @@ func (t *RWTransaction) Put(name string, key []byte, value []byte) error {
return &Error{"data too large", nil}
}
- // Insert a new node.
+ // Move cursor to correct position.
c := b.cursor()
c.Get(key)
+
+ // Insert the key/value.
t.node(c.stack).put(key, key, value, 0)
return nil
}
func (t *RWTransaction) Delete(name string, key []byte) error {
- // TODO: Traverse to the correct node.
- // TODO: If missing, exit.
- // TODO: Remove node from page.
- // TODO: If page is empty then add it to the freelist.
+ b := t.Bucket(name)
+ if b == nil {
+ return &Error{"bucket not found", nil}
+ }
+
+ // Move cursor to correct position.
+ c := b.cursor()
+ c.Get(key)
+
+ // Delete the node if we have a matching key.
+ t.node(c.stack).del(key)
+
return nil
}
@@ -237,7 +247,10 @@ func (t *RWTransaction) write() error {
for _, p := range pages {
size := (int(p.overflow) + 1) * t.db.pageSize
buf := (*[maxAllocSize]byte)(unsafe.Pointer(p))[:size]
- t.db.file.WriteAt(buf, int64(p.id)*int64(t.db.pageSize))
+ offset := int64(p.id) * int64(t.db.pageSize)
+ if _, err := t.db.file.WriteAt(buf, offset); err != nil {
+ return err
+ }
}
return nil