diff --git a/crossbeam-skiplist/Cargo.toml b/crossbeam-skiplist/Cargo.toml index 75a0df46b..a164020f1 100644 --- a/crossbeam-skiplist/Cargo.toml +++ b/crossbeam-skiplist/Cargo.toml @@ -30,6 +30,7 @@ alloc = ["crossbeam-epoch/alloc"] [dependencies] crossbeam-epoch = { version = "0.9.17", path = "../crossbeam-epoch", default-features = false } crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false } +equivalent-flipped = "0.1" [dev-dependencies] rand = "0.8" diff --git a/crossbeam-skiplist/src/equivalent.rs b/crossbeam-skiplist/src/equivalent.rs index 0a1577256..5ee5e8abd 100644 --- a/crossbeam-skiplist/src/equivalent.rs +++ b/crossbeam-skiplist/src/equivalent.rs @@ -3,52 +3,4 @@ //! Traits for key comparison in maps. -use core::{borrow::Borrow, cmp::Ordering}; - -/// Key equivalence trait. -/// -/// This trait allows hash table lookup to be customized. It has one blanket -/// implementation that uses the regular solution with `Borrow` and `Eq`, just -/// like `HashMap` does, so that you can pass `&str` to lookup into a map with -/// `String` keys and so on. -/// -/// # Contract -/// -/// The implementor **must** hash like `Q`, if it is hashable. -pub trait Equivalent { - /// Compare self to `key` and return `true` if they are equal. - fn equivalent(&self, key: &Q) -> bool; -} - -impl Equivalent for K -where - K: Borrow, - Q: Eq, -{ - #[inline] - fn equivalent(&self, key: &Q) -> bool { - PartialEq::eq(self.borrow(), key) - } -} - -/// Key ordering trait. -/// -/// This trait allows ordered map lookup to be customized. It has one blanket -/// implementation that uses the regular solution with `Borrow` and `Ord`, just -/// like `BTreeMap` does, so that you can pass `&str` to lookup into a map with -/// `String` keys and so on. -pub trait Comparable: Equivalent { - /// Compare self to `key` and return their ordering. - fn compare(&self, key: &Q) -> Ordering; -} - -impl Comparable for K -where - K: Borrow, - Q: Ord, -{ - #[inline] - fn compare(&self, key: &Q) -> Ordering { - Ord::cmp(self.borrow(), key) - } -} +pub use equivalent_flipped::*;