Skip to main content

CostExt

Trait CostExt 

Source
pub trait CostExt: Cost {
    // Required methods
    fn saturating_sub(self, other: Self) -> Self;
    fn to_f64(self) -> f64;
}
Expand description

Priority arithmetic that Cost lacks: subtraction and conversion to f64.

Some searches order nodes by priorities that subtract or divide costs: the (G - g) / h order of anytime nonparametric A*, the 2g + h - h_opposite key of front-to-end bidirectional searches, or a potential such as dynamic potential search. Those searches require this trait; every other search needs Cost alone. Like WideMul and ExactArith, it is a separate trait, so cost types without it keep working.

Costsaturating_subto_f64
u8 to u128, usizesaturates at 0nearest float; exact up to 2^53
Decimal<K>on raw units, saturates at 0the raw unit count, not divided by 10^K
NonNegF64 (feature float)clamps at 0, also ∞ - ∞the value itself

A user-defined cost type implements it next to Cost.

§Examples

use search_core::{CostExt, Decimal};

assert_eq!(CostExt::saturating_sub(3_u32, 5), 0);
assert_eq!(7_u64.to_f64(), 7.0);

// Decimal converts its raw units: 1.50 at scale 10^2 is 150.
assert_eq!(Decimal::<2>::from_raw(150).to_f64(), 150.0);

Required Methods§

Source

fn saturating_sub(self, other: Self) -> Self

Subtracts other, saturating at Cost::ZERO.

For priorities that subtract one estimate from another, such as a G - g slack.

Source

fn to_f64(self) -> f64

The cost as a float, possibly rounded; for Decimal<K> the raw units, scaled by 10^K.

Only for priorities that divide costs, such as a (G - g) / h order. Rounding can change the expansion order among nearly equal priorities, but never a returned cost. Within one cost type the result is proportional to the cost, so quotients and the order of differences are what the exact values give, up to rounding. Do not compare the result against a threshold in cost units: for Decimal<K> it is off by 10^K.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl CostExt for u8

Source§

fn saturating_sub(self, other: Self) -> Self

Source§

fn to_f64(self) -> f64

Source§

impl CostExt for u16

Source§

fn saturating_sub(self, other: Self) -> Self

Source§

fn to_f64(self) -> f64

Source§

impl CostExt for u32

Source§

fn saturating_sub(self, other: Self) -> Self

Source§

fn to_f64(self) -> f64

Source§

impl CostExt for u64

Source§

fn saturating_sub(self, other: Self) -> Self

Source§

fn to_f64(self) -> f64

Source§

impl CostExt for u128

Source§

fn saturating_sub(self, other: Self) -> Self

Source§

fn to_f64(self) -> f64

Source§

impl CostExt for usize

Source§

fn saturating_sub(self, other: Self) -> Self

Source§

fn to_f64(self) -> f64

Implementors§

Source§

impl CostExt for NonNegF64

Available on crate feature float only.
Source§

impl<const K: u32> CostExt for Decimal<K>