weighted-sampling

Crates.ioweighted-sampling
lib.rsweighted-sampling
version0.1.0
created_at2025-11-25 09:11:04.894167+00
updated_at2025-11-25 09:11:04.894167+00
descriptionWeighted reservoir sampling using Algorithm A-Chao
homepage
repositoryhttps://gitlab.com/andrzej1_1/weighted-sampling
max_upload_size
id1949455
size4,842
(koxu1996)

documentation

README

= weighted-sampling

Rust library for weighted reservoir sampling using Algorithm A-Chao.

== Usage

[source,rust]

use weighted_sampling::WeightedReservoirSampler; use rand::thread_rng;

let mut sampler = WeightedReservoirSampler::new(); let mut rng = thread_rng();

// Process items from a stream. sampler.sample(10, "item1", &mut rng); // weight: 10 sampler.sample(5, "item2", &mut rng); // weight: 5 sampler.sample(15, "item3", &mut rng); // weight: 15

// Get the selected item. if let Some(selected) = sampler.selected() { println!("Selected: {}", selected); }

// Or take ownership. let result = sampler.into_selected();

Commit count: 0

cargo fmt