https://github.com/klippersubs/bfs
General purpose BFS implementation.
https://github.com/klippersubs/bfs
bfs-algorithm graph-algorithms
Last synced: 9 months ago
JSON representation
General purpose BFS implementation.
- Host: GitHub
- URL: https://github.com/klippersubs/bfs
- Owner: klippersubs
- License: mit
- Created: 2017-10-04T03:12:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-06T07:39:09.000Z (over 8 years ago)
- Last Synced: 2025-08-21T19:57:03.667Z (10 months ago)
- Topics: bfs-algorithm, graph-algorithms
- Language: JavaScript
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @klippersubs/bfs
[][ci]
[][npm]
> General purpose BFS implementation.
````bash
yarn add @klippersubs/bfs
````
````javascript
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` — 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` — returns children
of the given vertex.
Return value:
* `Set` — flat set of vertices.
## License
MIT
[ci]: https://travis-ci.org/klippersubs/bfs
[npm]: https://www.npmjs.com/package/@klippersubs/bfs