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

support for comparators as closures #765

Merged
merged 5 commits into from
Apr 26, 2023
Merged

Conversation

pegesund
Copy link
Contributor

@pegesund pegesund commented Apr 7, 2023

I have updated the code for supporting comparators as closures.

Reason for this is that moving from functions to closures makes it possible to add more information into the comparator function. Let us for example say one is creating a sql-base and then would like to add a compound index, based on the create index statement. The sort order in the comparator should then depend on the directions of the sorting fields, for example first sort on a float and then an int.

The old solution did not support a way to add meta-info like this into the compare function in a dynamical way and this is currently solved by allowing the comparator to be a closure. By using the move-functionality with closures we can add extra context to the compare function.

The solution is backwards compatible, as it still supports functions as these can be casted to closures in Rust.

I have also added a test-file for comparators where I test backwards compatiblity, and the new solution with support for closures.

Feel free to drop a line to me on petter.egesund@gmail.com if you would like to discuss.

@Congyuwang
Copy link
Contributor

Don't know if this will incur performance overhead.

@pegesund
Copy link
Contributor Author

Hi @Congyuwang

I do not think there should be a performance overhead, it will still only be a single function call after the rust compiler has done its job. It will however be a speed gain when having compound comparators. In my old solution I had to keep types before every value in my bytearray so be able to acomplish this - this took much disk space, cpu and memory.

@pegesund
Copy link
Contributor Author

Hi @aleksuss and/or @stanislav-tkach

Anything I could/should do to get this merged this into the main branch?

Petter

@aleksuss aleksuss merged commit c14532d into rust-rocksdb:master Apr 26, 2023
7 checks passed
Shylock-Hg pushed a commit to Shylock-Hg/rust-rocksdb that referenced this pull request Mar 29, 2024
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

4 participants