From 12fd02b542049b865f9ec9b4f6954fd6c1936f7d Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 22 Oct 2020 19:07:54 +0200 Subject: [PATCH] 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. --- bucket.go | 1 + cursor.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bucket.go b/bucket.go index d8750b148..d0ea54127 100644 --- a/bucket.go +++ b/bucket.go @@ -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. diff --git a/cursor.go b/cursor.go index 98aeb449a..0e5f907c6 100644 --- a/cursor.go +++ b/cursor.go @@ -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.