Open
Graph Drawing
Framework

 v.2012.05
 

ClusterSet.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046 
00047 #ifndef OGDF_NODE_SET_H
00048 #define OGDF_NODE_SET_H
00049 
00050 
00051 #include <ogdf/cluster/ClusterArray.h>
00052 #include <ogdf/basic/List.h>
00053 
00054 
00055 
00056 namespace ogdf {
00057 
00058 
00059 //---------------------------------------------------------
00060 // ClusterSetSimple
00061 // maintains a subset S of the clusters contained in an associated
00062 // cluster graph G (only insertion of elements and clear operation)
00063 //---------------------------------------------------------
00064 class OGDF_EXPORT ClusterSetSimple {
00065 public:
00066     // creates a new empty cluster set associated with cluster graph CG
00067     ClusterSetSimple(const ClusterGraph &CG) : m_isContained(CG,false) { }
00068 
00069     // destructor
00070     ~ClusterSetSimple() { }
00071 
00072     // inserts cluster c into set S
00073     // running time: O(1)
00074     // Precond.: c is a cluster in the associated graph
00075     void insert(cluster c) {
00076         OGDF_ASSERT(c->graphOf() == m_isContained.graphOf());
00077         bool &isContained = m_isContained[c];
00078         if (isContained == false) {
00079             isContained = true;
00080             m_clusters.pushFront(c);
00081         }
00082     }
00083 
00084 
00085     // removes all clusters from set S
00086     // running time: O(|S|)
00087     void clear() {
00088         SListIterator<cluster> it;
00089         for(it = m_clusters.begin(); it.valid(); ++it) {
00090             m_isContained[*it] = false;
00091         }
00092         m_clusters.clear();
00093     }
00094 
00095 
00096     // returns true iff cluster c is contained in S
00097     // running time: O(1)
00098     // Precond.: c is a cluster in the asociated graph
00099     bool isMember(cluster c) const {
00100         OGDF_ASSERT(c->graphOf() == m_isContained.graphOf());
00101         return m_isContained[c];
00102     }
00103 
00104     // returns the list of clusters contained in S
00105     const SListPure<cluster> &clusters() const {
00106         return m_clusters;
00107     }
00108 
00109 private:
00110     // m_isContained[c] is true <=> c is contained in S
00111     ClusterArray<bool> m_isContained;
00112     // list of clusters contained in S
00113     SListPure<cluster> m_clusters;
00114 };
00115 
00116 
00117 
00118 //---------------------------------------------------------
00119 // ClusterSetPure
00120 // maintains a subset S of the clusters contained in an associated
00121 // graph G (no efficient access to size of S)
00122 //---------------------------------------------------------
00123 class OGDF_EXPORT ClusterSetPure {
00124 public:
00125     // creates a new empty cluster set associated with graph G
00126     ClusterSetPure(const ClusterGraph &G) : m_it(G,ListIterator<cluster>()) { }
00127 
00128     // destructor
00129     ~ClusterSetPure() { }
00130 
00131     // inserts cluster c into set S
00132     // running time: O(1)
00133     // Precond.: c is a cluster in the associated graph
00134     void insert(cluster c) {
00135         OGDF_ASSERT(c->graphOf() == m_it.graphOf());
00136         ListIterator<cluster> &itV = m_it[c];
00137         if (!itV.valid())
00138             itV = m_clusters.pushBack(c);
00139     }
00140 
00141     // removes cluster c from set S
00142     // running time: O(1)
00143     // Precond.: c is a cluster in the asociated graph
00144     void remove(cluster c) {
00145         OGDF_ASSERT(c->graphOf() == m_it.graphOf());
00146         ListIterator<cluster> &itV = m_it[c];
00147         if (itV.valid()) {
00148             m_clusters.del(itV);
00149             itV = ListIterator<cluster>();
00150         }
00151     }
00152 
00153 
00154     // removes all clusters from set S
00155     // running time: O(|S|)
00156     void clear() {
00157         ListIterator<cluster> it;
00158         for(it = m_clusters.begin(); it.valid(); ++it) {
00159             m_it[*it] = ListIterator<cluster>();
00160         }
00161         m_clusters.clear();
00162     }
00163 
00164 
00165     // returns true iff cluster c is contained in S
00166     // running time: O(1)
00167     // Precond.: c is a cluster in the asociated graph
00168     bool isMember(cluster c) const {
00169         OGDF_ASSERT(c->graphOf() == m_it.graphOf());
00170         return m_it[c].valid();
00171     }
00172 
00173     // returns the list of clusters contained in S
00174     const ListPure<cluster> &clusters() const {
00175         return m_clusters;
00176     }
00177 
00178 private:
00179     // m_it[c] contains list iterator pointing to c if c is contained in S,
00180     // an invalid list iterator otherwise
00181     ClusterArray<ListIterator<cluster> > m_it;
00182     // list of clusters contained in S
00183     ListPure<cluster> m_clusters;
00184 };
00185 
00186 
00187 
00188 //---------------------------------------------------------
00189 // ClusterSet
00190 // maintains a subset S of the clusters contained in an associated
00191 // graph G
00192 //---------------------------------------------------------
00193 class OGDF_EXPORT ClusterSet {
00194 public:
00195     // creates a new empty cluster set associated with graph G
00196     ClusterSet(const ClusterGraph &G) : m_it(G,ListIterator<cluster>()) { }
00197 
00198     // destructor
00199     ~ClusterSet() { }
00200 
00201     // inserts cluster c into set S
00202     // running time: O(1)
00203     // Precond.: c is a cluster in the associated graph
00204     void insert(cluster c) {
00205         OGDF_ASSERT(c->graphOf() == m_it.graphOf());
00206         ListIterator<cluster> &itV = m_it[c];
00207         if (!itV.valid())
00208             itV = m_clusters.pushBack(c);
00209     }
00210 
00211     // removes cluster c from set S
00212     // running time: O(1)
00213     // Precond.: c is a cluster in the asociated graph
00214     void remove(cluster c) {
00215         OGDF_ASSERT(c->graphOf() == m_it.graphOf());
00216         ListIterator<cluster> &itV = m_it[c];
00217         if (itV.valid()) {
00218             m_clusters.del(itV);
00219             itV = ListIterator<cluster>();
00220         }
00221     }
00222 
00223 
00224     // removes all clusterss from set S
00225     // running time: O(|S|)
00226     void clear() {
00227         ListIterator<cluster> it;
00228         for(it = m_clusters.begin(); it.valid(); ++it) {
00229             m_it[*it] = ListIterator<cluster>();
00230         }
00231         m_clusters.clear();
00232     }
00233 
00234 
00235     // returns true iff cluster c is contained in S
00236     // running time: O(1)
00237     // Precond.: c is a cluster in the asociated graph
00238     bool isMember(cluster c) const {
00239         OGDF_ASSERT(c->graphOf() == m_it.graphOf());
00240         return m_it[c].valid();
00241     }
00242 
00243     // returns the size of set S
00244     // running time: O(1)
00245     int size() const {
00246         return m_clusters.size();
00247     }
00248 
00249     // returns the list of clusters contained in S
00250     const List<cluster> &clusters() const {
00251         return m_clusters;
00252     }
00253 
00254 private:
00255     // m_it[c] contains list iterator pointing to c if c is contained in S,
00256     // an invalid list iterator otherwise
00257     ClusterArray<ListIterator<cluster> > m_it;
00258     // list of clusters contained in S
00259     List<cluster> m_clusters;
00260 };
00261 
00262 
00263 } // end namespace ogdf
00264 
00265 
00266 #endif