2.1.7 • Published 7 years ago

@klippersubs/bfs v2.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

@klippersubs/bfs

Travis CI NPM version

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

2.1.7

7 years ago

2.1.6

7 years ago

2.1.5

7 years ago

2.1.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago