Skip to content

Commit

Permalink
Add Comparator blanking implementation for smart pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Jul 13, 2024
1 parent b54aa7f commit 4414f46
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,54 @@ pub trait Comparator: core::fmt::Debug {
Q: ?Sized + PartialOrd<&'a [u8]>;
}

impl<C: Comparator> Comparator for std::sync::Arc<C> {
#[inline]
fn compare(&self, a: &[u8], b: &[u8]) -> cmp::Ordering {
(**self).compare(a, b)
}

#[inline]
fn contains<'a, Q>(&self, range: &impl RangeBounds<Q>, key: &'a [u8]) -> bool
where
&'a [u8]: PartialOrd<Q>,
Q: ?Sized + PartialOrd<&'a [u8]>,
{
(**self).contains(range, key)
}
}

impl<C: Comparator> Comparator for std::rc::Rc<C> {
#[inline]
fn compare(&self, a: &[u8], b: &[u8]) -> cmp::Ordering {
(**self).compare(a, b)
}

#[inline]
fn contains<'a, Q>(&self, range: &impl RangeBounds<Q>, key: &'a [u8]) -> bool
where
&'a [u8]: PartialOrd<Q>,
Q: ?Sized + PartialOrd<&'a [u8]>,
{
(**self).contains(range, key)
}
}

impl<C: Comparator> Comparator for std::boxed::Box<C> {
#[inline]
fn compare(&self, a: &[u8], b: &[u8]) -> cmp::Ordering {
(**self).compare(a, b)
}

#[inline]
fn contains<'a, Q>(&self, range: &impl RangeBounds<Q>, key: &'a [u8]) -> bool
where
&'a [u8]: PartialOrd<Q>,
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;
Expand Down

0 comments on commit 4414f46

Please sign in to comment.