pub struct Config<T: Clone + Eq + Hash> {
pub table: Table<T>,
pub inversed: bool,
pub repetitive: bool,
}Expand description
Configuration required by Picker. All members are public
and are supposed to be modified by the user.
Fields§
§table: Table<T>Table of choices and weights which are proportional to the probabilities on repetitive mode or single-item mode.
inversed: boolDo multiplicative inversion for each value in the table.
repetitive: boolAllow the same item to be picked for multiple times in the result.
Implementations§
source§impl<T: Clone + Eq + Hash> Config<T>
impl<T: Clone + Eq + Hash> Config<T>
sourcepub fn calc_probabilities(&self, pick_amount: usize) -> Result<Table<T>, Error>
pub fn calc_probabilities(&self, pick_amount: usize) -> Result<Table<T>, Error>
Calculates probabilities of existences of table items
in each picking result of length pick_amount.
In non-repetitive mode, the multi-thread tree algorithm may be used.
TODO: figure out why its single-thread performance is 10.3% slower than the previous C++ version, and unsafe operations can’t make it faster.
source§impl<T: Clone + Eq + Hash> Config<T>
impl<T: Clone + Eq + Hash> Config<T>
source§impl Config<String>
impl Config<String>
sourcepub fn append_str(&mut self, str_items: &str)
pub fn append_str(&mut self, str_items: &str)
Appends, modifies or deletes items in the table according to the configuration input string.
let mut conf: random_picker::Config<String> = "
repetitive = true
inversed = false
[items]
oxygen = 47
sillicon = 28
aluminium=8; iron=5; magnesium=4;
calcium=2: potassium=2: sodium=2:
others = 2; nonexistium = 31
aluminium = 9; delete nonexistium
".parse().unwrap();
assert_eq!(conf.table.len(), 9);
assert_eq!(conf.repetitive, true);
assert_eq!(conf.inversed, false);
assert_eq!(conf.table.get("aluminium"), Some(&9.));
conf.append_str("\
power_inversed
# invalid: repetitive = 0
repetitive = 0
delete others
");
assert_eq!(conf.repetitive, true);
assert_eq!(conf.inversed, true);
conf.append_str("inversed = false");
assert_eq!(conf.inversed, false);Trait Implementations§
impl<T: Clone + Eq + Hash> StructuralPartialEq for Config<T>
Auto Trait Implementations§
impl<T> Freeze for Config<T>
impl<T> RefUnwindSafe for Config<T>where
T: RefUnwindSafe,
impl<T> Send for Config<T>where
T: Send,
impl<T> Sync for Config<T>where
T: Sync,
impl<T> Unpin for Config<T>where
T: Unpin,
impl<T> UnwindSafe for Config<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)