search-core
Small shared traits for planning and search crates.
A heuristic, goal test or budget written once against these traits works with every
algorithm of the ecosystem. The crate is no_std, has no dependencies and holds only what
at least two independent search crates need.
Scope and status
Implemented:
Cost: non-negative, totally ordered scalar path cost withZERO,saturating_addandsaturating_times. Implemented foru8,u16,u32(the ecosystem default),u64,u128andusize.Decimal<K>: exact fixed-point decimal cost with scale10^K(K <= 19, checked at compile time), stored asu64.FromStrparses"3.25"exactly and rejects more thanKfraction digits (so nothing rounds), signs and overflow (ParseDecimalError).NonNegF64(featurefloat): anf64cost that rejects NaN and negative values, so it can beOrd. Sound, but rounds; prefer integers orDecimalfor exact results.CostExt:saturating_suband a possibly roundingto_f64(raw units forDecimal) for priorities that subtract or divide costs, such as anytime and bidirectional searches. A separate trait, implemented for every cost above.WideMul: the product of two costs in a wider type (u8–u64into the next wider integer,usizeintou128,u128into a(high, low)256-bit pair,Decimal<K>intou128,NonNegF64into itself) and the distanceabs_diff, exact for every integer andDecimalinput. For comparing cost ratios by cross-multiplication; a separate trait, soCostis unchanged.ExactArith(featurealloc): converts a cost into an exact number type (ExactNumber:BigUintfor the integers andDecimal,NonNegF64itself) with+,*and a distance, for sums of products and longer products. Also separate fromCost.NonNegF64gainsMul(with0 · ∞ = 0).Heuristic<S, C = u32>with&mut selfworkspaces, forwarding impls for&mut HandBox<H>(featurealloc, default),heuristic_fnfor closures, and the blindZero(for everyCostand forf64).Goal<S>, implemented forFn(&S) -> bool.Budget<Stats>over a crate's own statistics type, implemented forFnMut(&Stats) -> bool.
Not included, on purpose: successor generation (Successors, Graph, Mdp), statistics
and limits structs, and Pareto dominance. Their shapes differ between the sibling crates, or
only one crate uses them. See MIGRATION.md for how each sibling would adopt
this crate.
Pre-release: version 0.0.0 reserves the name, and the API may still change before 0.1.
Install
Example
use ;
let mut h = heuristic_fn;
assert_eq!;
let cost = from_raw + from_int.unwrap;
assert_eq!;
assert!;
Features
alloc(default):HeuristicforBox<H>, andExactArithwithBigUint.float: the checked float costNonNegF64.
Without default features the crate needs neither std nor alloc.
MSRV
Rust 1.85 (edition 2024). The minimum supported Rust version may be raised in a minor release when a dependency or a language feature calls for it.
Contributing
See CONTRIBUTING.md.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.