weight_matchers

Crates.ioweight_matchers
lib.rsweight_matchers
version
sourcesrc
created_at2025-01-08 22:30:14.080012
updated_at2025-01-08 22:30:14.080012
descriptionEfficiently find items by matching weight. You can build the lookup structure at compile time.
homepage
repositoryhttp://sourceforge.net/p/weight_matchers
max_upload_size
id1509240
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(daniel-pfeiffer)

documentation

README

Efficiently find items by matching weight. If your data is static, you can build the lookup structure (a complete binary tree) at compile time, by making it const.

You can use any numeric type for the weights, by default f32. You can have any range for the lookup, by default 0.0 .. 1.0 for floats, and their respective whole spectrum for integers.

As a small example, let’s make red more than twice as likely as green, and that in turn five times as likely as blue.

# extern crate weight_matchers;
# use weight_matchers::*;
# fn rand_f32() -> f32 { 0.0 }
let colours = const {
    weights! {
        0.70 => "red",
        0.25 => "green",
        0.05 => "blue",
    }
};
// Any random source of the same type and range as your weights will do.
println!("I got {}", colours.get(rand_f32()))

There’s a blog about the design choices behind this.

Commit count: 0

cargo fmt