weighted-sampling 0.1.0

Weighted reservoir sampling using Algorithm A-Chao
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented0 out of 7 items with examples
  • Size
  • Source code size: 4.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • andrzej1_1/weighted-sampling
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • koxu1996

= 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();