Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Cursor().Seek() in LastN method of the List datatype instead of manually getting to the desired position #6

Merged
merged 1 commit into from
Jan 1, 2020

Conversation

luisguve
Copy link
Contributor

With bucket.Cursor().Last(), you get the last key and value pair in a []byte. The key is convertible to uint64 with binary.BigEndian.Uint64([]byte) since it has been saved as a []byte representation of the uint64 returned from bucket.NextSequence() in the Add method.

The number returned by the last key is then used to get to the starting position from which to fetch the last N elements of the list using bucket.Cursor().Seek(startPos). bucket.Cursor().Next() returns either the next key and value pair or a nil key if the last k/v pair has been reached.

…ch to get to the n element and fetch the n last elements
@xyproto
Copy link
Owner

xyproto commented Dec 31, 2019

Thank you! I'll test and then merge this.

@xyproto xyproto merged commit dbcca43 into xyproto:master Jan 1, 2020
@xyproto
Copy link
Owner

xyproto commented Jan 1, 2020

Tested and merged. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants