| 1 |
// Copyright 2018 Developers of the Rand project. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 |
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 |
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 6 |
// option. This file may not be copied, modified, or distributed |
| 7 |
// except according to those terms. |
| 8 |
|
| 9 |
//! Weighted index sampling |
| 10 |
//! |
| 11 |
//! This module is deprecated. Use [`crate::distributions::WeightedIndex`] and |
| 12 |
//! [`crate::distributions::WeightedError`] instead. |
| 13 |
|
| 14 |
pub use super::{WeightedIndex, WeightedError}; |
| 15 |
|
| 16 |
#[allow(missing_docs)] |
| 17 |
#[deprecated(since = "0.8.0", note = "moved to rand_distr crate")] |
| 18 |
pub mod alias_method { |
| 19 |
// This module exists to provide a deprecation warning which minimises |
| 20 |
// compile errors, but still fails to compile if ever used. |
| 21 |
use core::marker::PhantomData; |
| 22 |
use alloc::vec::Vec; |
| 23 |
use super::WeightedError; |
| 24 |
|
| 25 |
#[derive(Debug)] |
| 26 |
pub struct WeightedIndex<W: Weight> { |
| 27 |
_phantom: PhantomData<W>, |
| 28 |
} |
| 29 |
impl<W: Weight> WeightedIndex<W> { |
| 30 |
pub fn new(_weights: Vec<W>) -> Result<Self, WeightedError> { |
| 31 |
Err(WeightedError::NoItem) |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
pub trait Weight {} |
| 36 |
macro_rules! impl_weight { |
| 37 |
() => {}; |
| 38 |
($T:ident, $($more:ident,)*) => { |
| 39 |
impl Weight for $T {} |
| 40 |
impl_weight!($($more,)*); |
| 41 |
}; |
| 42 |
} |
| 43 |
impl_weight!(f64, f32,); |
| 44 |
impl_weight!(u8, u16, u32, u64, usize,); |
| 45 |
impl_weight!(i8, i16, i32, i64, isize,); |
| 46 |
impl_weight!(u128, i128,); |
| 47 |
} |