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

Custom comparison function #156

Closed
achille-roussel opened this issue Apr 22, 2019 · 1 comment
Closed

Custom comparison function #156

achille-roussel opened this issue Apr 22, 2019 · 1 comment

Comments

@achille-roussel
Copy link

Hello,

Today the key comparison function used by the database is bytes.Compare. In cases where we're dealing with fixed-size integer or ascii keys this makes a lot of sense, but I have a use case for using variable size integers as keys (similar to big.Int), and the order of the keys as defined by bytes.Compare is not the natural order of the integer values.

I'd like to explore modifying the package to make the comparison function configurable on a per-bucket basis, but I wanted to get feedback from someone more familiar with the implementation in case there were any major concerns.

@pixelrazor
Copy link

pixelrazor commented Jun 17, 2019

Gonna spitball some stuff here and maybe try to test it, but it seems like it would be as simple as having the bucket struct have a new member (func(a, b []byte)int) that will default to bytes.Compare, but setable with a new CreateBucket func, then passing that func into the cursor struct when you make a cursor. cursor will then reference its stored comparison func instead of always using bytes.compare. Does anyone think there's something missing with all that?

EDIT: Persisting the comparison function will be an issue. the responsibility COULD be placed on the user, and they would have to keep track of which buckets use which comparison function and pass it in each time they open the bucket. I think a better way, though unsure how to do it, would be to copy the comparison function to the disk with the bucket and load it from there when the bucket is opened. Currently unaware of any way to do that though

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

No branches or pull requests

4 participants