searchlib 0.1.2

Satisficing and optimal search algorithms
Documentation
pub mod bfs;
pub mod dfs;
pub mod ehcs;
pub mod gbfs;
pub mod hcs;
pub mod lgbfs;

use indexmap::IndexMap;
use rustc_hash::FxHasher;
use std::hash::BuildHasherDefault;

type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;

fn trace<STATE>(parents: &FxIndexMap<STATE, usize>, goal_index: usize) -> Vec<STATE>
where
    STATE: Clone,
{
    let mut i = goal_index;
    let mut states = vec![];
    loop {
        let (state, parent) = parents.get_index(i).unwrap();
        states.push(state.clone());
        i = *parent;
        if i == 0 {
            states.push(parents.get_index(*parent).unwrap().0.clone());
            break;
        }
    }
    states.reverse();
    states
}