Skip to content

Commit

Permalink
bucket,cursor: clarify sort order and seek algorithm
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
x1ddos committed Oct 22, 2020
1 parent f6be823 commit 12fd02b
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 @@ -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.
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 @@ -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.
Expand Down

0 comments on commit 12fd02b

Please sign in to comment.