Struct SearchScratch

Source
pub struct SearchScratch { /* private fields */ }
Expand description

Indexed binary heap: at most one open entry per cell. Scratch, heap and route storage are allocated once; decreases do not insert duplicate heap entries.

Implementations§

Source§

impl SearchScratch

Source

pub fn new(capacity: usize) -> Result<SearchScratch, NavigationError>

Source

pub fn capacity(&self) -> usize

Source

pub fn status(&self) -> SearchStatus

Source

pub fn total_work(&self) -> u64

Work consumed since the last successful Self::begin or Self::restart.

Counts both expanded cells and traced parents. Cancellation, stale-grid detection and rejected requests preserve this count; a fresh search resets it. This is observed work, not an estimate of work remaining.

use ferravex_play::navigation::{Cell, Connectivity, Grid, SearchScratch};
let grid = Grid::new(2, 1).unwrap();
let mut search = SearchScratch::new(2).unwrap();
search.begin(&grid, Cell { x: 0, y: 0 }, Cell { x: 1, y: 0 }, Connectivity::Four).unwrap();
search.step(&grid, 1);
search.step(&grid, 1);
assert_eq!(search.total_work(), 2);
search.step(&grid, 2); // Two cells of path reconstruction.
assert_eq!(search.total_work(), 4);
Source

pub fn cancel(&mut self) -> bool

Discard pending work and any path, returning whether the status changed.

Sets the status to SearchStatus::Idle without allocating or spending search work. Repeated cancellation returns false. The last request and its Self::total_work remain available for inspection and restart.

use ferravex_play::navigation::{Cell, Connectivity, Grid, SearchScratch, SearchStatus};
let grid = Grid::new(2, 1).unwrap();
let mut search = SearchScratch::new(2).unwrap();
search.begin(&grid, Cell { x: 0, y: 0 }, Cell { x: 1, y: 0 }, Connectivity::Four).unwrap();
search.step(&grid, 1);
assert!(search.cancel());
assert!(!search.cancel());
assert_eq!(search.step(&grid, 10).status, SearchStatus::Idle);
assert_eq!(search.total_work(), 1);
assert!(search.reverse_path().is_none());
Source

pub fn restart(&mut self, grid: &Grid) -> Result<(), NavigationError>

Restart the last successful request against the supplied grid snapshot.

Reuses the original cell coordinates and connectivity, even if the grid identity or dimensions changed. This also works after cancellation or a terminal outcome. Returns NavigationError::InvalidInput if no request has ever begun; other errors are the same as Self::begin. Every error leaves the existing search and its work count unchanged. Like begin, this reuses storage and only clears stamps on generation wrap.

use ferravex_play::navigation::{Cell, Connectivity, Grid, NavigationError, SearchScratch};
let mut grid = Grid::new(3, 1).unwrap();
let mut search = SearchScratch::new(3).unwrap();
assert_eq!(search.restart(&grid), Err(NavigationError::InvalidInput));
search.begin(&grid, Cell { x: 0, y: 0 }, Cell { x: 2, y: 0 }, Connectivity::Four).unwrap();
search.step(&grid, 1);
search.cancel();
grid.set_cost(Cell { x: 1, y: 0 }, 2).unwrap();
search.restart(&grid).unwrap();
assert_eq!(search.total_work(), 0);
assert!(search.step(&grid, 1).budget_exhausted());
Source

pub fn begin( &mut self, grid: &Grid, start: Cell, end: Cell, connectivity: Connectivity, ) -> Result<(), NavigationError>

Invalid requests leave an existing search unchanged. A valid request resets it without allocation. Generation wrap clears stamps once in 2^32 starts.

Source

pub fn step(&mut self, grid: &Grid, max_work: u32) -> SearchProgress

One work unit pops/expands one cell (up to eight fixed neighbors), or reconstructs one parent. Both phases honor the same tick allowance. An empty frontier reports NoPath in the same call as its last expansion, even when that expansion uses the final work unit. A zero allowance does no expansion or tracing, but still invalidates results from another grid snapshot, including an earlier NoPath result.

Source

pub fn step_budgeted( &mut self, grid: &Grid, budget: &mut WorkBudget, ) -> SearchProgress

Source

pub fn reverse_path(&self) -> Option<&[Cell]>

Goal-to-start order avoids an unbudgeted reversal at completion.

Source

pub fn copy_path(&self, output: &mut [Cell]) -> Result<usize, NavigationError>

Copying is explicit host work, bounded by the supplied output and path size. Failure leaves output unchanged.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.