diff --git a/Cargo.toml b/Cargo.toml index 5d8931d4..63376f89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "skl" -version = "0.13.0" +version = "0.13.1" edition = "2021" rust-version = "1.56.0" repository = "https://github.com/al8n/skl" diff --git a/README.md b/README.md index 7a780d06..8a4ba928 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,14 @@ ```toml [dependencies] - skl = "0.12" + skl = "0.13" ``` - Enable memory map backend ```toml [dependencies] - skl = { version = "0.12", features = ["memmap"] } + skl = { version = "0.13", features = ["memmap"] } ``` ## Features diff --git a/src/lib.rs b/src/lib.rs index d2cf5293..2b2da54c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,6 +97,54 @@ pub trait Comparator: core::fmt::Debug { Q: ?Sized + PartialOrd<&'a [u8]>; } +impl Comparator for std::sync::Arc { + #[inline] + fn compare(&self, a: &[u8], b: &[u8]) -> cmp::Ordering { + (**self).compare(a, b) + } + + #[inline] + fn contains<'a, Q>(&self, range: &impl RangeBounds, key: &'a [u8]) -> bool + where + &'a [u8]: PartialOrd, + Q: ?Sized + PartialOrd<&'a [u8]>, + { + (**self).contains(range, key) + } +} + +impl Comparator for std::rc::Rc { + #[inline] + fn compare(&self, a: &[u8], b: &[u8]) -> cmp::Ordering { + (**self).compare(a, b) + } + + #[inline] + fn contains<'a, Q>(&self, range: &impl RangeBounds, key: &'a [u8]) -> bool + where + &'a [u8]: PartialOrd, + Q: ?Sized + PartialOrd<&'a [u8]>, + { + (**self).contains(range, key) + } +} + +impl Comparator for std::boxed::Box { + #[inline] + fn compare(&self, a: &[u8], b: &[u8]) -> cmp::Ordering { + (**self).compare(a, b) + } + + #[inline] + fn contains<'a, Q>(&self, range: &impl RangeBounds, key: &'a [u8]) -> bool + where + &'a [u8]: PartialOrd, + Q: ?Sized + PartialOrd<&'a [u8]>, + { + (**self).contains(range, key) + } +} + /// Ascend is a comparator that compares byte slices in ascending order. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct Ascend;