MCPcopy
hub / github.com/etcd-io/bbolt / Seek

Method Seek

cursor.go:120–136  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

118// follow, a nil key is returned.
119// The returned key and value are only valid for the life of the transaction.
120func (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.

Callers 5

TestCursor_SeekFunction · 0.80
TestCursor_DeleteFunction · 0.80
TestCursor_Seek_LargeFunction · 0.80

Calls 4

seekMethod · 0.95
nextMethod · 0.95
AssertFunction · 0.92
countMethod · 0.80

Tested by 5

TestCursor_SeekFunction · 0.64
TestCursor_DeleteFunction · 0.64
TestCursor_Seek_LargeFunction · 0.64