private int[] _repShuffle; // Used to pick the "right" representant for // Havlak's loop analysis /// <summary> /// Constructs an instance of the union-find data structure. /// </summary> /// <param name="a">set adapter</param> /// <param name="elems">The list set elements. It is assumed that the list index of each set element /// matched the index returned by the set adapter.</param> public UnionFind(ISetAdapter <T> a, IList <T> elems) { _index = a.Index; _elems = new List <T>(elems); _repShuffle = new int[elems.Count]; for (int i = 0; i < _elems.Count; i++) { Debug.Assert(_index[_elems[i]] == i); _repShuffle[i] = i; } _impl = new DisjointSets(elems.Count); }
/// <summary> /// Creates a union-find data structure. /// </summary> /// <typeparam name="T">type of a set element</typeparam> /// <param name="a">set adapter</param> /// <param name="elems">The list of set elements. It is assumed that the list index of each set element /// matched the index returned by the set adapter.</param> public static UnionFind <T> CreateUnionFind <T>(this ISetAdapter <T> a, IList <T> elems) { return(new UnionFind <T>(a, elems)); }