@Reference(authors="R. Sedgewick", title="1.3 Union-Find Algorithms", booktitle="Algorithms in C, Parts 1-4") public class WeightedQuickUnionStaticDBIDs extends Object implements UnionFind
StaticDBIDs
, with optimizations.
To instantiate, use UnionFindUtil.make(de.lmu.ifi.dbs.elki.database.ids.StaticDBIDs)
, which will automatically
choose the best implementation available.
This is the weighted quick union approach, weighted by count and using
path-halving for optimization.
This version needs more memory than WeightedQuickUnionRangeDBIDs
but
can work with any unmodifiable DBID set (although ArrayDBIDs
are
recommended).
Reference:
R. Sedgewick
1.3 Union-Find Algorithms
Algorithms in C, Parts 1-4
Modifier and Type | Field and Description |
---|---|
private ArrayDBIDs |
ids
Object ID range.
|
private WritableIntegerDataStore |
index
Index, to map DBID to offset.
|
private int[] |
parent
Parent element
|
private int[] |
weight
Weight, for optimization.
|
Constructor and Description |
---|
WeightedQuickUnionStaticDBIDs(StaticDBIDs ids)
Constructor (package private, use
UnionFindUtil.make(de.lmu.ifi.dbs.elki.database.ids.StaticDBIDs) ). |
Modifier and Type | Method and Description |
---|---|
int |
find(DBIDRef element)
Find the component ID of an element.
|
DBIDs |
getRoots()
Collect all component root elements.
|
boolean |
isConnected(DBIDRef first,
DBIDRef second)
Test if two components are connected.
|
int |
union(DBIDRef first,
DBIDRef second)
Join the components of elements p and q.
|
private ArrayDBIDs ids
private WritableIntegerDataStore index
private int[] parent
private int[] weight
WeightedQuickUnionStaticDBIDs(StaticDBIDs ids)
UnionFindUtil.make(de.lmu.ifi.dbs.elki.database.ids.StaticDBIDs)
).ids
- Range to usepublic int find(DBIDRef element)
UnionFind
public int union(DBIDRef first, DBIDRef second)
UnionFind
public boolean isConnected(DBIDRef first, DBIDRef second)
UnionFind
isConnected
in interface UnionFind
first
- First elementsecond
- Second elementtrue
if they are in the same component.Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.