From 70d909be50b8275613e73488cadd9271d5ea903c Mon Sep 17 00:00:00 2001 From: al8n Date: Wed, 11 Dec 2024 21:16:52 +0800 Subject: [PATCH 1/2] skiplist: extract `equivalent` mod to a crate --- crossbeam-skiplist/Cargo.toml | 1 + crossbeam-skiplist/src/equivalent.rs | 50 +--------------------------- 2 files changed, 2 insertions(+), 49 deletions(-) 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::*; From ab845d5cb34166c56a26d88d5dd8b7f579c449d2 Mon Sep 17 00:00:00 2001 From: al8n Date: Wed, 18 Dec 2024 17:34:22 +0800 Subject: [PATCH 2/2] bumpup `equivalent-flipped` version --- crossbeam-skiplist/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crossbeam-skiplist/Cargo.toml b/crossbeam-skiplist/Cargo.toml index a164020f1..33cf3cd4f 100644 --- a/crossbeam-skiplist/Cargo.toml +++ b/crossbeam-skiplist/Cargo.toml @@ -30,7 +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" +equivalent-flipped = "1" [dev-dependencies] rand = "0.8"