Fix feature flags and use core for nostd compatibility
This commit is contained in:
committed by
Vinzent Steinberg
parent
8890183f13
commit
a310f9720c
+6
-3
@@ -295,14 +295,14 @@ where
|
||||
key: f64,
|
||||
}
|
||||
impl PartialOrd for Element {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
|
||||
self.key
|
||||
.partial_cmp(&other.key)
|
||||
.or(Some(std::cmp::Ordering::Less))
|
||||
.or(Some(core::cmp::Ordering::Less))
|
||||
}
|
||||
}
|
||||
impl Ord for Element {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
|
||||
self.partial_cmp(other).unwrap() // partial_cmp will always produce a value
|
||||
}
|
||||
}
|
||||
@@ -346,6 +346,9 @@ where
|
||||
|
||||
#[cfg(not(feature = "partition_at_index"))]
|
||||
{
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
use crate::alloc::collections::BinaryHeap;
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::BinaryHeap;
|
||||
|
||||
// Partially sort the array such that the `amount` elements with the largest
|
||||
|
||||
+3
-3
@@ -1062,14 +1062,14 @@ mod test {
|
||||
assert_eq!(result.len(), 0);
|
||||
|
||||
// Case 5: NaN weights
|
||||
let choices = [('a', std::f64::NAN), ('b', 1.0), ('c', 1.0)];
|
||||
let choices = [('a', core::f64::NAN), ('b', 1.0), ('c', 1.0)];
|
||||
assert!(matches!(
|
||||
choices.choose_multiple_weighted(&mut rng, 2, |item| item.1),
|
||||
Err(WeightedError::InvalidWeight)
|
||||
));
|
||||
|
||||
// Case 6: +infinity weights
|
||||
let choices = [('a', std::f64::INFINITY), ('b', 1.0), ('c', 1.0)];
|
||||
let choices = [('a', core::f64::INFINITY), ('b', 1.0), ('c', 1.0)];
|
||||
for _ in 0..100 {
|
||||
let result = choices
|
||||
.choose_multiple_weighted(&mut rng, 2, |item| item.1)
|
||||
@@ -1080,7 +1080,7 @@ mod test {
|
||||
}
|
||||
|
||||
// Case 7: -infinity weights
|
||||
let choices = [('a', std::f64::NEG_INFINITY), ('b', 1.0), ('c', 1.0)];
|
||||
let choices = [('a', core::f64::NEG_INFINITY), ('b', 1.0), ('c', 1.0)];
|
||||
assert!(matches!(
|
||||
choices.choose_multiple_weighted(&mut rng, 2, |item| item.1),
|
||||
Err(WeightedError::InvalidWeight)
|
||||
|
||||
Reference in New Issue
Block a user