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
impl SearchScratch
pub fn new(capacity: usize) -> Result<SearchScratch, NavigationError>
pub fn capacity(&self) -> usize
pub fn status(&self) -> SearchStatus
Sourcepub fn total_work(&self) -> u64
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);Sourcepub fn cancel(&mut self) -> bool
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());Sourcepub fn restart(&mut self, grid: &Grid) -> Result<(), NavigationError>
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());Sourcepub fn begin(
&mut self,
grid: &Grid,
start: Cell,
end: Cell,
connectivity: Connectivity,
) -> Result<(), NavigationError>
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.
Sourcepub fn step(&mut self, grid: &Grid, max_work: u32) -> SearchProgress
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.
pub fn step_budgeted( &mut self, grid: &Grid, budget: &mut WorkBudget, ) -> SearchProgress
Sourcepub fn reverse_path(&self) -> Option<&[Cell]>
pub fn reverse_path(&self) -> Option<&[Cell]>
Goal-to-start order avoids an unbudgeted reversal at completion.