https://github.com/arnellebalane/union-find
Implementation of the Union-Find data structure for NodeJS
https://github.com/arnellebalane/union-find
data-structures hacktoberfest npm-package union-find
Last synced: 6 months ago
JSON representation
Implementation of the Union-Find data structure for NodeJS
- Host: GitHub
- URL: https://github.com/arnellebalane/union-find
- Owner: arnellebalane
- License: mit
- Created: 2017-08-07T10:25:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-09T10:22:45.000Z (over 8 years ago)
- Last Synced: 2025-03-01T04:32:19.538Z (about 1 year ago)
- Topics: data-structures, hacktoberfest, npm-package, union-find
- Language: JavaScript
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Union Find
Implementation of the **Union-Find** data structure for NodeJS.
## Installation
```bash
$ npm install git+https://git@github.com/arnellebalane/union-find.git
```
## Usage
This package exposes four implementations of the Union-Find data structure.
```js
import {
QuickFindUF,
QuickUnionUF,
WeightedQuickUnionUF,
PathCompressionUF
} from 'union-find';
```
## Api
- **`constructor(size)`**: Initializes a new Union-Find data structure with a given size.
- **`union(source, target)`**: Connects a node to another.
- **`connected(source, target)`** _(Boolean)_: Checks whether two nodes are connected.
## Example
```js
import { QuickFindUF } from 'union-find';
const uf = new QuickFindUF(10);
uf.union(4, 3);
uf.union(3, 8);
uf.connected(4, 8); // => true
uf.connected(1, 3); // => false
```
## Contributing
```bash
# or `npm` if yarn is not available
$ yarn install
$ yarn test
```
## License
MIT License