@klippersubs/bfs
v2.1.7
Published
General purpose BFS implementation.
Downloads
10
Maintainers
Readme
@klippersubs/bfs
General purpose BFS implementation.
yarn add @klippersubs/bfs
import { flatten } from '@klippersubs/bfs';
const en = { name: 'en', fallback: [] };
const ru = { name: 'ru', fallback: [en] };
const be = { name: 'be', fallback: [ru] };
const uk = { name: 'uk', fallback: [be, ru] };
be.fallback = [ru, uk];
const beTarask = { name: 'be-tarask', fallback: [be, uk] };
const lookupList = flatten(null, beTarask, (_, language) => language.fallback);
console.log(lookupList);
// → Set {
// { name: 'be-tarask', fallback: [ [Object], [Object] ] },
// { name: 'be', fallback: [ [Object], [Object] ] },
// { name: 'uk', fallback: [ [Object], [Object] ] },
// { name: 'ru', fallback: [ [Object] ] },
// { name: 'en', fallback: [] } }
Exported API
Type export ChildrenGetter
Returns children of the given vertex in the given graph.
Generic params:
Graph
— graph type.Vertex
— vertex type.
Params:
graph: Graph
— graph containing the vertex.vertex: Vertex
— vertex in the graph.
Return value:
Array<Node>
— flat array of vertices.
Export flatten
Flattens cyclic graph starting from root vertex.
Generic params:
Graph
— graph type.Vertex
— vertex type.
Params:
graph: Graph
— graph or forest.root: Vertex
— vertex to start search.getChildren: ChildrenGetter<Graph, Vertex>
— returns children of the given vertex.
Return value:
Set<Vertex>
— flat set of vertices.
License
MIT