Skip to content

Commit

Permalink
make score trait internal instead of pub. see rust-lang/rust#34537
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-groble committed Jun 19, 2023
1 parent 95afaae commit e0ba10e
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/skip_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, S> = Option<NonNull<Node<T, S>>>;

pub struct SkipList<T, S> {
Expand Down Expand Up @@ -210,7 +205,7 @@ impl<T, S> SkipList<T, S> {
}
}

impl<T, S: Score> SkipList<T, S> {
impl<T, S: internal::Score> SkipList<T, S> {
pub fn is_in_range<R: RangeBounds<S>>(&self, range: R) -> bool {
if range.is_empty() {
return false;
Expand Down Expand Up @@ -536,7 +531,7 @@ trait ScoreRange<S> {

impl<T: RangeBounds<S>, S> ScoreRange<S> for T
where
S: Score,
S: internal::Score + PartialOrd,
{
fn is_empty(&self) -> bool {
let infinity = S::INFINITY;
Expand Down Expand Up @@ -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 = <Self>::INFINITY;
const NEG_INFINITY: Self = <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 = <Self>::MAX;
const NEG_INFINITY: Self = <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);
}

0 comments on commit e0ba10e

Please sign in to comment.