From 0cae98efc5fd76f0f5159b6615f29ccf8bf97aa8 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Mon, 3 Feb 2014 14:33:51 -0700 Subject: Add RWTransaction.Delete(). --- rwtransaction.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'rwtransaction.go') diff --git a/rwtransaction.go b/rwtransaction.go index 2485c62..7911188 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 } -- cgit v1.2.3