diff --git a/src/skip_list.rs b/src/skip_list.rs index f53a6b5..33d1cc7 100644 --- a/src/skip_list.rs +++ b/src/skip_list.rs @@ -34,11 +34,6 @@ fn random_level() -> usize { level } -pub trait Score: Copy + Clone + std::cmp::PartialOrd { - const INFINITY: Self; - const NEG_INFINITY: Self; -} - type NodePointer = Option>>; pub struct SkipList { @@ -210,7 +205,7 @@ impl SkipList { } } -impl SkipList { +impl SkipList { pub fn is_in_range>(&self, range: R) -> bool { if range.is_empty() { return false; @@ -536,7 +531,7 @@ trait ScoreRange { impl, S> ScoreRange for T where - S: Score, + S: internal::Score + PartialOrd, { fn is_empty(&self) -> bool { let infinity = S::INFINITY; @@ -571,27 +566,33 @@ where } } -macro_rules! impl_score_float { +mod internal { + pub trait Score: Copy + PartialOrd { + const INFINITY: Self; + const NEG_INFINITY: Self; + } + macro_rules! impl_score_float { ($($F:ident),*) => { $( impl Score for $F { - const INFINITY: Self = $F::INFINITY; - const NEG_INFINITY: Self = $F::NEG_INFINITY; + const INFINITY: Self = ::INFINITY; + const NEG_INFINITY: Self = ::NEG_INFINITY; } )* }; } -macro_rules! impl_score_int { + macro_rules! impl_score_int { ($($F:ident),*) => { $( impl Score for $F { - const INFINITY: Self = $F::MAX; - const NEG_INFINITY: Self = $F::MIN; + const INFINITY: Self = ::MAX; + const NEG_INFINITY: Self = ::MIN; } )* }; } -impl_score_float!(f32, f64); -impl_score_int!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128); + impl_score_float!(f32, f64); + impl_score_int!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128); +}