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

Suggestion: better custom comparison functions #129

Open
mdorier opened this issue Jun 17, 2021 · 2 comments
Open

Suggestion: better custom comparison functions #129

mdorier opened this issue Jun 17, 2021 · 2 comments
Assignees

Comments

@mdorier
Copy link
Contributor

mdorier commented Jun 17, 2021

I was trying to install a custom comparison function for an unqlite kv store and noticed that the current implementation is pretty limited in that regard:

  • It's taking only one "length" parameter, which I assume is the minimum length of both keys. This is problematic as one could imagine some comparison functions that need to know both lengths;
  • It could use an additional void* parameter to pass user-provided data;

I would suggest adding an UNQLITE_KV_CONFIG_CMP2_FUNC key for unqlite_kv_config(), accepting two arguments:

  • a comparison function with signature int (*xCmp)(const void*, const void*, unsigned int, unsigned int, void*);
  • a void* context for user-provided data (which will be passed as last argument to the comparison function whenever it is called).
@symisc symisc self-assigned this Jun 17, 2021
@symisc
Copy link
Owner

symisc commented Jun 17, 2021

Note however that the comparison function works only with binary blobs and not nil terminated strings. This is why the signature looks like memcmp() or bzero() of the C standard library.

@mdorier
Copy link
Contributor Author

mdorier commented Jun 17, 2021

Actually I wonder how unqlite distinguished a key and a prefix of that key, right now? Unless unqlite checks if the sizes are different outside of the comparison function and implicitly assumes, should the comparison return 0, that the shortest key is lower? (Which isn't necessarily a good assumption outside of lexicographical order)

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

No branches or pull requests

2 participants