-
Notifications
You must be signed in to change notification settings - Fork 480
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 comparators for SkipList #1180
Comments
Is this the same as the already merged #1132? Or are you requesting something different? |
Different. The idea is essentially to add a type parameter trait Comparator<K> {
fn compare(&self, left: &K, right: &K) -> std::cmp::Ordering;
} When comparing keys, instead of impl<K: Ord> Comparator<K> for DefaultComparator {
fn compare(&self, left: &K, right: &K) -> Ordering {
Ord::cmp(left, right)
}
} But the use case I had in mind was to use That said, fjall seems to be moving towards a custom skiplist implementation, at which point the feature could be implemented without support from crossbeam. |
If you want to use a skiplist that supports custom comparators, then |
@matthew-mcallister I think if we do this before (unreleased) #1132 is released, we can put in this without a breaking change using the default type parameter, I honestly don't have a strong opinion on whether we want this or not. For simple cases, I think just using a wrapper like std::cmp::Reverse would be sufficient, though.... |
I think this is useful because currently, the comparison is stateless, which means users cannot provide some extra information for comparison, e.g., strip prefixes, or ignore suffixes. Although users can use a key wrapper, the problem is it will bring a bunch of traits to implement. |
I also forked a version of |
FWIW, if fjall were the only consumer of this feature, I would probably lean towards shelving it, since that crate is officially looking to implement a custom skiplist anyways. But it looks like there will be others who would like to use their own comparators as well. The feature should be straightforward to implement and test, and I wouldn't mind doing it myself either. I think the main challenge is getting the design right for the |
Um, that crate has 9 traits in comparison related...? If they are really needed for this functionality, so I feel this functionality is quite complicated. |
Yeah, it is complicated in that crate because it was originally just for a POC. The comparison-related traits can be simplified in a production implementation (only need one trait for sure) |
It would be useful to be able to specify a custom C++-style comparator function to override
SkipList
key order at runtime, specifically for an ordered K/V store like fjall (issue here).The implementation would be easy. Unfortunately, Rust has no standard API for custom comparators, so there's no obvious, future-proof design to go with. The closest reference points I'm aware of are the
compare
crate and C++std::map
.The text was updated successfully, but these errors were encountered: