new DisjointSet(size, subsetPropsReduceropt, defaultPropsopt)
Create a disjoint set.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
size |
Number | The number of elements in the set | ||
subsetPropsReducer |
SubsetPropsReducer |
<optional> |
Defines how subset properties are combined when two subsets are merged as the result of a union. | |
defaultProps |
Object | SubsetPropsInitializer |
<optional> |
{} | Initial subset properties or a callback that returns initial subset properties. |
- Source:
Methods
find(x) → {Number}
Find the root of the subset containing element x.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | An element in the set. |
- Source:
Returns:
The root of the subset containing element x.
- Type
- Number
isConnected(x, y) → {Boolean}
Determine if two elements are connected.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | An element in the set. |
y |
Number | An element in the set. |
- Source:
Returns:
True if elements x and y are connected (in the same subset).
- Type
- Boolean
numSubsets() → {Number}
Get the number of subsets in the set.
- Source:
Returns:
Number of subsets in the set.
- Type
- Number
subset(x) → {Array.<Number>}
Get the subset containing an element.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | An element in the set. |
- Source:
Returns:
Array of elements in the subset containing element x.
- Type
- Array.<Number>
subsetProps(x) → {Object}
Get the properties of the subset containing a specific element.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | An element in the set. |
- Source:
Returns:
- The properties of the subset containing element x.
- Type
- Object
subsets() → {Array.<Array.<Number>>}
Get all subsets in the set.
- Source:
Returns:
An array of subsets. Each subset is an array of elements contained in that subset.
- Type
- Array.<Array.<Number>>
union(x, y, edgeopt) → {Number}
Connect two elements and merge their subsets.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number | An element in the set. | |
y |
Number | An element in the set. | |
edge |
Object |
<optional> |
Arbitrary properties of the edge connecting elements x and y. These are passed to the set's SubsetPropsReducer to determine properties of the merged subset. |
- Source:
Returns:
The root of the merged subset.
- Type
- Number