Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/include/objMesh-disjointSet.h

raw symbols SCIP
1 /*************************************************************************
2 * *
3 * Vega FEM Simulation Library Version 3.1 *
4 * *
5 * "objMesh" library , Copyright (C) 2007 CMU, 2009 MIT, 2016 USC *
6 * All rights reserved. *
7 * *
8 * Code authors: Yili Zhao, Jernej Barbic *
9 * http://www.jernejbarbic.com/code *
10 * *
11 * Research: Jernej Barbic, Fun Shing Sin, Daniel Schroeder, *
12 * Doug L. James, Jovan Popovic *
13 * *
14 * Funding: National Science Foundation, Link Foundation, *
15 * Singapore-MIT GAMBIT Game Lab, *
16 * Zumberge Research and Innovation Fund at USC *
17 * *
18 * This library is free software; you can redistribute it and/or *
19 * modify it under the terms of the BSD-style license that is *
20 * included with this library in the file LICENSE.txt *
21 * *
22 * This library is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *
25 * LICENSE.TXT for more details. *
26 * *
27 *************************************************************************/
28
29 /*
30 "Disjoint set", a union-find data structure
31 that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets.
32
33 Operations:
34 1) MakeSet: Make each set containing only a given element.
35 2) Find: Determine which set a particular element is in. Also useful for determining if two elements are in the same set.
36 3) Union: Combine or merge two sets into a single set.
37
38 Heuristics such as path compression etc. have been implemented.
39 */
40
41 #ifndef _DISJOINT_SET_H_
42 #define _DISJOINT_SET_H_
43
44 class DisjointSet
45 {
46 public:
47
48 // constructor
49 DisjointSet(int num=0); // 'num' is the total number of elements
50
51 // destructor
52 ~DisjointSet();
53
54 // resizes the data structure to have size 'num'
55 void Resize(int num);
56
57 // makes each element be its own set (usually the first operation after the constructor)
58 void MakeSet();
59
60 // returns the representative of the set that x belongs to (path compression is implemented in this function as well)
61 int FindSet(int x);
62
63 // merge two sets (the smaller one will be absorbed by the larger one)
64 // x and y can be arbitrary elements, they need not be representatives
65 void UnionSet(int x, int y);
66
67 protected:
68 int * disjointSetParent;
69 int size;
70
71 enum {NO_SUCCESSOR = -1};
72
73 // destroys the data structure
74 void Destroy();
75 };
76
77 #endif
78