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

Generic sort functions to be used with set_dupsort() or set_compare(). #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mneumann
Copy link
Contributor

Use it like this (for every type that implement FromMdbValue and Ord):

db.set_compare(lmdb::sort::<u64>);
db.set_dupsort(lmdb::sort_reverse::<u64>);

Use it like this (for every type that implement FromMdbValue and Ord):

    db.set_compare(lmdb::sort::<u64>);
    db.set_dupsort(lmdb::sort_reverse::<u64>);
@vhbit
Copy link
Owner

vhbit commented Sep 30, 2015

It would be great to have a test case for it as there is a unsafe conversion from Ordering to u8, even though it's very unlikely will change soon

@mneumann
Copy link
Contributor Author

mneumann commented Oct 1, 2015

Please see my second commit. There, I assert that the ordering conversion is as expected.

@vhbit
Copy link
Owner

vhbit commented Oct 1, 2015

As you use u64 as an example how to use those functions may I also ask you to add a doc comment for them with a note that LMDB has a smart internal integer sorting (it doesn't depends on size of integer), which means if the key has a fixed size it's preferred to set DbIntKey flag instead of setting a custom sort function?

I apologize I haven't though of it earlier.

@mneumann
Copy link
Contributor Author

mneumann commented Oct 1, 2015

I will add a doc comment, but I don't know much about LMDB's internal integer sorting. I only expect it to work for usize and probably u32. Would it work for u16 or u8, too? Where is this documented in LMDB?

Btw, I found out that when you want to sort keys that are > u64 (for example a (u64, u64) tuple), you can do that by encoding it as big-endian and use the string sort of LMDB. This was before you added set_cmp() and set_dupsort() functions, which would be the prefered way.

@vhbit
Copy link
Owner

vhbit commented Oct 1, 2015

I've actually expected it to work only with u32/u64 depending on system but here is a clarification, see MDB_INTEGER section

which would be the preferred way

Tuples are interesting case, I'd try to go with LMDB builtin int comparison

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.

2 participants