diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-20 13:24:55 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-20 13:24:55 -0700 |
commit | b9ec84552bf97db7d55180af513dce26f4539b22 (patch) | |
tree | 0b0c2119fbcf0296631f996c68e2e86b86df60e5 /cursor.go | |
parent | Merge pull request #43 from benbjohnson/cursor-godoc-fix (diff) | |
parent | Cursor.Get is now Cursor.Seek, and returns the first possible key. (diff) | |
download | dedo-b9ec84552bf97db7d55180af513dce26f4539b22.tar.gz dedo-b9ec84552bf97db7d55180af513dce26f4539b22.tar.xz |
Merge pull request #45 from benbjohnson/seek
Cursor.Get is now Cursor.Seek, and returns the first possible key.
Diffstat (limited to 'cursor.go')
-rw-r--r-- | cursor.go | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -48,32 +48,28 @@ func (c *Cursor) Next() (key []byte, value []byte) { return c.keyValue() } -// Get moves the cursor to a given key and returns its value. -// If the key does not exist then the cursor is left at the closest key and a nil value is returned. -func (c *Cursor) Get(key []byte) (value []byte) { +// Seek moves the cursor to a given key and returns it. +// If the key does not exist then the next key is used. If no keys +// follow, a nil value is returned. +func (c *Cursor) Seek(seek []byte) (key []byte, value []byte) { // Start from root page and traverse to correct page. c.stack = c.stack[:0] - c.search(key, c.transaction.page(c.root)) + c.search(seek, c.transaction.page(c.root)) p, index := c.top() // If the cursor is pointing to the end of page then return nil. if index == p.count { - return nil - } - - // If our target node isn't the same key as what's passed in then return nil. - if !bytes.Equal(key, c.element().key()) { - return nil + return nil, nil } - return c.element().value() + return c.element().key(), c.element().value() } // first moves the cursor to the first leaf element under the last page in the stack. func (c *Cursor) first() { p := c.stack[len(c.stack)-1].page for { - // Exit when we hit a leaf page. + // Exit when we hit a leaf page. if (p.flags & leafPageFlag) != 0 { break } |