Merge pull request #743 from ahrtr/cursor_doc_20240502

Update readme to clearly clarify the behaviour of Next and Prev
pull/747/head
Benjamin Wang 2024-05-02 17:55:09 +01:00 committed by GitHub
commit 5192661398
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

View File

@ -441,10 +441,14 @@ Prev() Move to the previous key.
```
Each of those functions has a return signature of `(key []byte, value []byte)`.
When you have iterated to the end of the cursor then `Next()` will return a
`nil` key. You must seek to a position using `First()`, `Last()`, or `Seek()`
before calling `Next()` or `Prev()`. If you do not seek to a position then
these functions will return a `nil` key.
You must seek to a position using `First()`, `Last()`, or `Seek()` before calling
`Next()` or `Prev()`. If you do not seek to a position then these functions will
return a `nil` key.
When you have iterated to the end of the cursor, then `Next()` will return a
`nil` key and the cursor still points to the last element if present. When you
have iterated to the beginning of the cursor, then `Prev()` will return a `nil`
key and the cursor still points to the first element if present.
If you remove key/value pairs during iteration, the cursor may automatically
move to the next position if present in current node each time removing a key.