Skip to content

Commit

Permalink
Import some core Items
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed May 8, 2024
1 parent 9ce0fdd commit f032b61
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/seq/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// except according to those terms.

//! Low-level API for sampling indices
use core::{cmp::Ordering, hash::Hash, ops::AddAssign};

#[cfg(feature = "alloc")]
use core::slice;
Expand Down Expand Up @@ -337,23 +338,27 @@ where
index: N,
key: f64,
}

impl<N> PartialOrd for Element<N> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl<N> Ord for Element<N> {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
fn cmp(&self, other: &Self) -> Ordering {
// partial_cmp will always produce a value,
// because we check that the weights are not nan
self.key.partial_cmp(&other.key).unwrap()
}
}

impl<N> PartialEq for Element<N> {
fn eq(&self, other: &Self) -> bool {
self.key == other.key
}
}

impl<N> Eq for Element<N> {}

let mut candidates = Vec::with_capacity(length.as_usize());
Expand Down Expand Up @@ -442,13 +447,12 @@ where
IndexVec::from(indices)
}

trait UInt:
Copy + PartialOrd + Ord + PartialEq + Eq + SampleUniform + core::hash::Hash + core::ops::AddAssign
{
trait UInt: Copy + PartialOrd + Ord + PartialEq + Eq + SampleUniform + Hash + AddAssign {
fn zero() -> Self;
fn one() -> Self;
fn as_usize(self) -> usize;
}

impl UInt for u32 {
#[inline]
fn zero() -> Self {
Expand All @@ -465,6 +469,7 @@ impl UInt for u32 {
self as usize
}
}

impl UInt for usize {
#[inline]
fn zero() -> Self {
Expand Down

0 comments on commit f032b61

Please sign in to comment.