Seek moves the cursor to a given key using a b-tree search and returns it. If the key does not exist then the next key is used. If no keys follow, a nil key is returned. The returned key and value are only valid for the life of the transaction.
(seek []byte)
| 118 | // follow, a nil key is returned. |
| 119 | // The returned key and value are only valid for the life of the transaction. |
| 120 | func (c *Cursor) Seek(seek []byte) (key []byte, value []byte) { |
| 121 | common.Assert(c.bucket.tx.db != nil, "tx closed") |
| 122 | |
| 123 | k, v, flags := c.seek(seek) |
| 124 | |
| 125 | // If we ended up after the last element of a page then move to the next one. |
| 126 | if ref := &c.stack[len(c.stack)-1]; ref.index >= ref.count() { |
| 127 | k, v, flags = c.next() |
| 128 | } |
| 129 | |
| 130 | if k == nil { |
| 131 | return nil, nil |
| 132 | } else if (flags & uint32(common.BucketLeafFlag)) != 0 { |
| 133 | return k, nil |
| 134 | } |
| 135 | return k, v |
| 136 | } |
| 137 | |
| 138 | // Delete removes the current key/value under the cursor from the bucket. |
| 139 | // Delete fails if current key/value is a bucket or if the transaction is not writable. |