pub struct BendableScore<const H: usize, const S: usize> { /* private fields */ }Expand description
A score with a configurable number of hard and soft levels.
Level counts are const generic parameters, enabling Copy and zero heap allocation.
§Type Parameters
H- Number of hard score levelsS- Number of soft score levels
§Examples
use solverforge_core::score::{BendableScore, Score};
// Create a score with 2 hard levels and 3 soft levels
let score: BendableScore<2, 3> = BendableScore::of([-1, -2], [-10, -20, -30]);
assert_eq!(score.hard_levels_count(), 2);
assert_eq!(score.soft_levels_count(), 3);
assert!(!score.is_feasible()); // Negative hard scoresImplementations§
Source§impl<const H: usize, const S: usize> BendableScore<H, S>
impl<const H: usize, const S: usize> BendableScore<H, S>
Sourcepub const fn of(hard: [i64; H], soft: [i64; S]) -> Self
pub const fn of(hard: [i64; H], soft: [i64; S]) -> Self
Creates a score from its hard levels and soft levels, each ordered from highest to lowest priority.
Sourcepub const fn hard_levels_count(&self) -> usize
pub const fn hard_levels_count(&self) -> usize
Returns the number of hard levels, H.
Sourcepub const fn soft_levels_count(&self) -> usize
pub const fn soft_levels_count(&self) -> usize
Returns the number of soft levels, S.
Sourcepub const fn hard_score(&self, level: usize) -> i64
pub const fn hard_score(&self, level: usize) -> i64
Sourcepub const fn soft_score(&self, level: usize) -> i64
pub const fn soft_score(&self, level: usize) -> i64
Sourcepub const fn hard_scores(&self) -> &[i64; H]
pub const fn hard_scores(&self) -> &[i64; H]
Returns all hard levels, highest priority first.
Sourcepub const fn soft_scores(&self) -> &[i64; S]
pub const fn soft_scores(&self) -> &[i64; S]
Returns all soft levels, highest priority first.
Trait Implementations§
impl<const H: usize, const S: usize> Copy for BendableScore<H, S>
impl<const H: usize, const S: usize> Eq for BendableScore<H, S>
Source§impl<const H: usize, const S: usize> Ord for BendableScore<H, S>
impl<const H: usize, const S: usize> Ord for BendableScore<H, S>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<const H: usize, const S: usize> PartialOrd for BendableScore<H, S>
impl<const H: usize, const S: usize> PartialOrd for BendableScore<H, S>
Source§impl<const H: usize, const S: usize> Score for BendableScore<H, S>
impl<const H: usize, const S: usize> Score for BendableScore<H, S>
Source§fn is_feasible(&self) -> bool
fn is_feasible(&self) -> bool
Returns true if this score represents a feasible solution. Read more
Source§fn levels_count() -> usize
fn levels_count() -> usize
Returns the number of score levels. Read more
Source§fn level_number(&self, index: usize) -> i64
fn level_number(&self, index: usize) -> i64
Returns the score value at a priority level. Read more
Source§fn from_level_numbers(levels: &[i64]) -> Self
fn from_level_numbers(levels: &[i64]) -> Self
Creates a score from level numbers. Read more
Source§fn multiply(&self, multiplicand: f64) -> Self
fn multiply(&self, multiplicand: f64) -> Self
Multiplies every level by a scalar, rounding to the nearest integer. Read more
Source§fn overflowing_multiply(&self, multiplicand: f64) -> (Self, bool)
fn overflowing_multiply(&self, multiplicand: f64) -> (Self, bool)
multiply without panicking: the flag is set for a non-finite
multiplicand or a rounded level outside i64; see overflowing_add.Source§fn divide(&self, divisor: f64) -> Self
fn divide(&self, divisor: f64) -> Self
Divides every level by a scalar, rounding to the nearest integer. Read more
Source§fn scale(&self, factor: i64) -> Self
fn scale(&self, factor: i64) -> Self
Multiplies every level by an exact integer factor. Read more
Source§fn overflowing_scale(&self, factor: i64) -> (Self, bool)
fn overflowing_scale(&self, factor: i64) -> (Self, bool)
scale without panicking: the flag is set when a level overflowed;
see overflowing_add.Source§fn overflowing_add(self, other: Self) -> (Self, bool)
fn overflowing_add(self, other: Self) -> (Self, bool)
Adds
other without panicking, returning the sum and whether any level
overflowed i64 (the levels are then wrapped and meaningless). Read moreSource§fn overflowing_sub(self, other: Self) -> (Self, bool)
fn overflowing_sub(self, other: Self) -> (Self, bool)
Subtracts
other without panicking; see overflowing_add.Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
Negates without panicking; see
overflowing_add.Source§fn level_label(index: usize) -> ScoreLevel
fn level_label(index: usize) -> ScoreLevel
Returns the semantic label for the score level at the given index. Read more
Source§fn compare(&self, other: &Self) -> Ordering
fn compare(&self, other: &Self) -> Ordering
Compares two scores, returning the ordering. Read more
Source§fn is_better_than(&self, other: &Self) -> bool
fn is_better_than(&self, other: &Self) -> bool
Returns true if this score is better than the other score. Read more
Source§fn is_worse_than(&self, other: &Self) -> bool
fn is_worse_than(&self, other: &Self) -> bool
Returns true if this score is worse than the other score.
Source§fn is_equal_to(&self, other: &Self) -> bool
fn is_equal_to(&self, other: &Self) -> bool
Returns true if this score is equal to the other score.
Source§fn one_medium() -> Self
fn one_medium() -> Self
Returns a score with 1 at the first Medium-labeled level and 0 elsewhere.
impl<const H: usize, const S: usize> StructuralPartialEq for BendableScore<H, S>
Auto Trait Implementations§
impl<const H: usize, const S: usize> Forget for BendableScore<H, S>
impl<const H: usize, const S: usize> Freeze for BendableScore<H, S>
impl<const H: usize, const S: usize> RefUnwindSafe for BendableScore<H, S>
impl<const H: usize, const S: usize> Send for BendableScore<H, S>
impl<const H: usize, const S: usize> Sync for BendableScore<H, S>
impl<const H: usize, const S: usize> Unpin for BendableScore<H, S>
impl<const H: usize, const S: usize> UnsafeUnpin for BendableScore<H, S>
impl<const H: usize, const S: usize> UnwindSafe for BendableScore<H, S>
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