rand_distr/weighted/mod.rs
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 a superset of [`rand::distr::weighted`].
12//!
13//! Multiple implementations of weighted index sampling are provided:
14//!
15//! - [`WeightedIndex`] (a re-export from [`rand`]) supports fast construction
16//! and `O(log N)` sampling over `N` weights.
17//! It also supports updating weights with `O(N)` time.
18//! - [`WeightedAliasIndex`] supports `O(1)` sampling, but due to high
19//! construction time many samples are required to outperform [`WeightedIndex`].
20//! - [`WeightedTreeIndex`] supports `O(log N)` sampling and
21//! update/insertion/removal of weights with `O(log N)` time.
22
23mod weighted_alias;
24mod weighted_tree;
25
26pub use rand::distr::weighted::*;
27pub use weighted_alias::*;
28pub use weighted_tree::*;