Skip to content

Commit

Permalink
Merge pull request #250 from x1ddos/sort-order-docs
Browse files Browse the repository at this point in the history
bucket,cursor: clarify sort order and seek algorithm
  • Loading branch information
ptabor committed Dec 21, 2022
2 parents 1231aef + 12fd02b commit 4b8c533
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,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.
Expand Down
5 changes: 3 additions & 2 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -109,7 +110,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.
Expand Down

0 comments on commit 4b8c533

Please sign in to comment.