bucket,cursor: clarify sort order and seek algorithm

The sort order isn't mentioned anywhere except one sentence in the
readme. So is seek. Although it can be inferred from B+tree and other
hints, it is important to be able to confirm from just reading doc
comments. So, make it explicit.
pull/250/head
alex 2020-10-22 19:07:54 +02:00
parent f6be823028
commit 12fd02b542
2 changed files with 4 additions and 2 deletions

View File

@ -378,6 +378,7 @@ func (b *Bucket) NextSequence() (uint64, error) {
}
// ForEach executes a function for each key/value pair in a bucket.
// Because ForEach uses a Cursor, the iteration over keys is in lexicographical order.
// If the provided function returns an error then the iteration is stopped and
// the error is returned to the caller. The provided function must not modify
// the bucket; this will result in undefined behavior.

View File

@ -6,7 +6,8 @@ import (
"sort"
)
// Cursor represents an iterator that can traverse over all key/value pairs in a bucket in sorted order.
// Cursor represents an iterator that can traverse over all key/value pairs in a bucket
// in lexicographical order.
// Cursors see nested buckets with value == nil.
// Cursors can be obtained from a transaction and are valid as long as the transaction is open.
//
@ -110,7 +111,7 @@ func (c *Cursor) Prev() (key []byte, value []byte) {
return k, v
}
// Seek moves the cursor to a given key and returns it.
// 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.