Skip to content

Commit

Permalink
feat: Make get_next/get_prev mor generic such that borrowed forms of …
Browse files Browse the repository at this point in the history
…keys can be used. (#77)
  • Loading branch information
mlgiraud committed Apr 16, 2024
1 parent 2398556 commit fd4e350
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/ord/set.rs
Expand Up @@ -449,8 +449,12 @@ where
/// assert_eq!(Some(&5), set.get_prev(&6));
/// ```
#[must_use]
pub fn get_prev(&self, key: &A) -> Option<&A> {
self.root.lookup_prev(key).map(|v| &v.0)
pub fn get_prev<BK>(&self, k: &BK) -> Option<&A>
where
BK: Ord + ?Sized,
A: Borrow<BK>,
{
self.root.lookup_prev(k).map(|v| &v.0)
}

/// Get the closest larger value in a set to a given value.
Expand All @@ -469,8 +473,12 @@ where
/// assert_eq!(Some(&5), set.get_next(&4));
/// ```
#[must_use]
pub fn get_next(&self, key: &A) -> Option<&A> {
self.root.lookup_next(key).map(|v| &v.0)
pub fn get_next<BK>(&self, k: &BK) -> Option<&A>
where
BK: Ord + ?Sized,
A: Borrow<BK>,
{
self.root.lookup_next(k).map(|v| &v.0)
}

/// Test whether a set is a subset of another set, meaning that
Expand Down

0 comments on commit fd4e350

Please sign in to comment.