bundles / scipy 1.17.1 / scipy / _lib / _disjoint_set / DisjointSet
class
scipy._lib._disjoint_set:DisjointSet
source: /scipy/_lib/_disjoint_set.py :6
Signature
class DisjointSet ( elements = None ) Members
Summary
Disjoint set data structure for incremental connectivity queries.
Extended Summary
Attributes
n_subsets: intThe number of subsets.
Methods
addmergeconnectedsubsetsubset_sizesubsets__getitem__
Notes
This class implements the disjoint set [1], also known as the union-find or merge-find data structure. The find operation (implemented in __getitem__) implements the path halving variant. The merge method implements the merge by size variant.
Examples
from scipy.cluster.hierarchy import DisjointSet
✓disjoint_set = DisjointSet([1, 2, 3, 'a', 'b'])
✓disjoint_set.merge(1, 2) disjoint_set.merge(3, 'a') disjoint_set.merge('a', 'b') disjoint_set.merge('b', 'b')✓
disjoint_set[2] disjoint_set['b']✓
disjoint_set.connected(1, 2) disjoint_set.connected(1, 'b')✓
list(disjoint_set)
✓disjoint_set.subset('a')
✗disjoint_set.subset_size('a')
✓disjoint_set.subsets()
✗Aliases
-
scipy.cluster.hierarchy.DisjointSet