klaudiosinani / dsforest

Disjoint-set forests for ES6
MIT License
16 stars 0 forks source link

Add new `DisjointSet#findSet(value)` class method (#3) #8

Closed klaudiosinani closed 5 years ago

klaudiosinani commented 5 years ago

Description

The PR introduces the following new unary method:

Returns the representative element of the disjoint set that element value is part of. If the given element is not part of any set, then undefined is returned. The method uses the path compression heuristic which mutates the parent pointer of each element, part of the find path, by making it point directly to the set representative.

Also, the corresponding TypeScript ambient declarations are included in the PR.