diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-03 14:33:51 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-03 14:33:51 -0700 |
commit | 0cae98efc5fd76f0f5159b6615f29ccf8bf97aa8 (patch) | |
tree | 96120044d92bcfbcbf5258bdf9c334448fc55aa7 /rwtransaction.go | |
parent | Merge pull request #5 from benbjohnson/put (diff) | |
download | dedo-0cae98efc5fd76f0f5159b6615f29ccf8bf97aa8.tar.gz dedo-0cae98efc5fd76f0f5159b6615f29ccf8bf97aa8.tar.xz |
Add RWTransaction.Delete().
Diffstat (limited to 'rwtransaction.go')
-rw-r--r-- | rwtransaction.go | 20 |
1 files changed, 15 insertions, 5 deletions
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 } |