aboutsummaryrefslogtreecommitdiff
path: root/cursor.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-01-27 10:11:54 -0500
committerBen Johnson <benbjohnson@yahoo.com>2014-01-27 10:11:54 -0500
commit192649f453af1f1fa79f41f1cfeed296ec51b545 (patch)
tree1195cb6ca23a6c8a576a8c24d10295ddc1515df6 /cursor.go
parentInitialize transaction/rwtransaction. (diff)
downloaddedo-192649f453af1f1fa79f41f1cfeed296ec51b545.tar.gz
dedo-192649f453af1f1fa79f41f1cfeed296ec51b545.tar.xz
Intermediate.
Diffstat (limited to 'cursor.go')
-rw-r--r--cursor.go37
1 files changed, 29 insertions, 8 deletions
diff --git a/cursor.go b/cursor.go
index b93178e..2f75677 100644
--- a/cursor.go
+++ b/cursor.go
@@ -1,8 +1,8 @@
package bolt
type Cursor struct {
- bucket *Bucket
- stack []elem
+ bucket *Bucket
+ stack []elem
}
// elem represents a node on a page that's on the cursor's stack.
@@ -16,22 +16,43 @@ func (c *Cursor) Bucket() *Bucket {
}
// First moves the cursor to the first item in the bucket and returns its key and data.
-func (c *Cursor) First() ([]byte, []byte, error) {
+func (c *Cursor) First() ([]byte, []byte) {
// TODO: Traverse to the first key.
- return nil, nil, nil
+ return nil, nil
}
// Move the cursor to the next key/value.
-func (c *Cursor) Next() ([]byte, []byte, error) {
- return nil, nil, nil
+func (c *Cursor) Next() ([]byte, []byte) {
+ return nil, nil
+}
+
+// Get positions the cursor at a specific key and returns the its value.
+func (c *Cursor) Get(key []byte) []byte {
+ if c.Goto(key) {
+ return c.node().value()
+ }
+ return nil
}
// Goto positions the cursor at a specific key.
-func (c *Cursor) Goto(key []byte) ([]byte, error) {
+// Returns true if an exact match or false if positioned after the closest match.
+func (c *Cursor) Goto(key []byte) bool {
// TODO(benbjohnson): Optimize for specific use cases.
// TODO: Check if len(key) > 0.
// TODO: Start from root page and traverse to correct page.
- return nil, nil
+ return false
+}
+
+// current the page and leaf node that the cursor is currently pointing at.
+func (c *Cursor) current() (*page, *lnode) {
+ elem := c.stack[len(c.stack)-1]
+ return elem.page, elem.page.lnode(elem.index)
+}
+
+// node returns the leaf node that the cursor is currently positioned on.
+func (c *Cursor) node() *lnode {
+ elem := c.stack[len(c.stack)-1]
+ return elem.page.lnode(elem.index)
}