UNPKG

fp-search-algorithms

Version:

Functional Programming Style Search Algorithms and Unordered Containers

43 lines (42 loc) 1.84 kB
/** * Dynamically generates and walks a tree in breadth-first order * This tree produces all possible pathways, and will revisit nodes, but not among its own unique pathway * * @category BreadthFirst * @param getNextStates - a function to generate list of neighboring states given the current state * @param forest - top level "forest" of states to begin traversal from */ export declare const generateBreadthFirstTreeTraversal: <T>(getNextStates: (state: T) => T[], forest: T[]) => Generator<{ path: T[]; state: T; }>; /** * Generator function that lazily iterates through each visit of a breadth-first search. * If you want just the found path to the solution, use `breadthFirstSearch` * * Each yield is an object `{ path: T[]; state: T }` * * `state` is the current state being visited * * `path` is, including current state, the in order steps it took to get to that state * * states are never re-visited * * @category BreadthFirst * @param getNextStates - a function to generate list of neighboring states given the current state * @param initial - initial state */ export declare const generateBreadthFirstSearch: <T>(getNextStates: (state: T) => T[], initial: T) => Generator<{ path: T[]; state: T; }>; /** * Performs a breadth-first-search (bfs) over a set of states starting from an `initial` * Returns a `{ path: T[]; state: T }` when solution found, `undefined` otherwise * * @category BreadthFirst * @param getNextStates - a function to generate list of neighboring states given the current state * @param determineIfFound - a function to determine if solution found * @param initial - initial state */ export declare const breadthFirstSearch: <T>(getNextStates: (state: T) => T[], determineIfFound: (state: T) => boolean, initial: T) => { path: T[]; state: T; } | undefined;