Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DisjointSets.hh
Go to the documentation of this file.
1 // (c) Copyright Rosetta Commons Member Institutions.
2 // (c) This file is part of the Rosetta software suite and is made available under license.
3 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
4 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
5 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
6 
7 /// @file core/graph/Graph.hh
8 /// @brief generic graph class header
9 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
10 
11 #ifndef INCLUDED_core_graph_DisjointSets_hh
12 #define INCLUDED_core_graph_DisjointSets_hh
13 
14 // Project Headers
15 // AUTO-REMOVED #include <platform/types.hh>
16 
17 // Utility Headers
18 // AUTO-REMOVED #include <utility/vector1.hh>
19 
20 // C++ headers
21 #include <map>
22 
23 #include <utility/vector1_bool.hh>
24 
25 
26 namespace core {
27 namespace graph {
28 
29 struct DS_Node {
33 };
34 
36 {
37 
38 public:
39 
40  DisjointSets();
41 
42  /// @brief ctor for class if the number of nodes is known upfront. Fastest.
44 
45  platform::Size n_nodes() const;
46 
47  /// @brief add a new node -- as implemented, O(N) operation
48  /// use the DS(platform::Size) constructor for better speed.
49  void ds_make_set();
50 
51  /// @brief return the representative for a node
52  platform::Size ds_find( platform::Size node_id ) const;
53 
54  /// @brief make it so that two nodes end up in the same set
55  void ds_union( platform::Size node1, platform::Size node2 );
56 
57  /// @brief DS_Node read access
58  DS_Node const &
59  node( platform::Size node_id ) const {
60  return nodes_[ node_id ];
61  }
62 
63  /// @brief count the number of disjoint sets. O(N)
65 
66  /// @brief count the size of each disjoint set. O(N)
68  disjoint_set_sizes() const;
69 
70  /// @brief return the nodes in the set containing the specified node.
72  nodes_in_set( platform::Size node_id ) const;
73 
74  /// @brief return a map from the representative node of each set to
75  /// the list of nodes in their sets
76  std::map< platform::Size, utility::vector1< platform::Size > >
77  sets() const;
78 
79 private:
80 
82 
83 };
84 
85 
86 
87 }
88 }
89 
90 #endif