1 // Copyright 2018 Developers of the Rand project.
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.
9 //! Weighted index sampling
11 //! This module is deprecated. Use [`crate::distributions::WeightedIndex`] and
12 //! [`crate::distributions::WeightedError`] instead.
14 pub use super::{WeightedIndex, WeightedError}
;
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
;
23 use super::WeightedError
;
26 pub struct WeightedIndex
<W
: Weight
> {
27 _phantom
: PhantomData
<W
>,
29 impl<W
: Weight
> WeightedIndex
<W
> {
30 pub fn new(_weights
: Vec
<W
>) -> Result
<Self, WeightedError
> {
31 Err(WeightedError
::NoItem
)
36 macro_rules
! impl_weight
{
38 ($T
:ident
, $
($more
:ident
,)*) => {
40 impl_weight
!($
($more
,)*);
43 impl_weight
!(f64, f32,);
44 impl_weight
!(u8, u16, u32, u64, usize,);
45 impl_weight
!(i8, i16, i32, i64, isize,);
46 #[cfg(not(target_os = "emscripten"))]
47 impl_weight
!(u128
, i128
,);