00001 /* 00002 * $Revision: 2027 $ 00003 * 00004 * last checkin: 00005 * $Author: gutwenger $ 00006 * $Date: 2010-09-01 11:55:17 +0200 (Wed, 01 Sep 2010) $ 00007 ***************************************************************/ 00008 00054 #ifdef _MSC_VER 00055 #pragma once 00056 #endif 00057 00058 #ifndef OGDF_FACE_SET_H 00059 #define OGDF_FACE_SET_H 00060 00061 00062 #include <ogdf/basic/FaceArray.h> 00063 #include <ogdf/basic/List.h> 00064 00065 00066 00067 namespace ogdf { 00068 00069 00071 00073 class OGDF_EXPORT FaceSetSimple { 00074 public: 00076 FaceSetSimple(const CombinatorialEmbedding &E) : m_isContained(E,false) { } 00077 00079 ~FaceSetSimple() { } 00080 00082 00085 void insert(face f) { 00086 OGDF_ASSERT(f->embeddingOf() == m_isContained.embeddingOf()); 00087 bool &isContained = m_isContained[f]; 00088 if (isContained == false) { 00089 isContained = true; 00090 m_faces.pushFront(f); 00091 } 00092 } 00093 00094 00096 00098 void clear() { 00099 SListIterator<face> it; 00100 for(it = m_faces.begin(); it.valid(); ++it) { 00101 m_isContained[*it] = false; 00102 } 00103 m_faces.clear(); 00104 } 00105 00106 00108 00111 bool isMember(face f) const { 00112 OGDF_ASSERT(f->embeddingOf() == m_isContained.embeddingOf()); 00113 return m_isContained[f]; 00114 } 00115 00117 const SListPure<face> &faces() const { 00118 return m_faces; 00119 } 00120 00121 private: 00123 FaceArray<bool> m_isContained; 00125 SListPure<face> m_faces; 00126 }; 00127 00128 00129 00131 00133 class OGDF_EXPORT FaceSetPure { 00134 public: 00136 FaceSetPure(const CombinatorialEmbedding &E) : m_it(E,ListIterator<face>()) { } 00137 00139 ~FaceSetPure() { } 00140 00142 00145 void insert(face f) { 00146 OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf()); 00147 ListIterator<face> &itF = m_it[f]; 00148 if (!itF.valid()) 00149 itF = m_faces.pushBack(f); 00150 } 00151 00153 00156 void remove(face f) { 00157 OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf()); 00158 ListIterator<face> &itF = m_it[f]; 00159 if (itF.valid()) { 00160 m_faces.del(itF); 00161 itF = ListIterator<face>(); 00162 } 00163 } 00164 00165 00167 00169 void clear() { 00170 ListIterator<face> it; 00171 for(it = m_faces.begin(); it.valid(); ++it) { 00172 m_it[*it] = ListIterator<face>(); 00173 } 00174 m_faces.clear(); 00175 } 00176 00177 00179 00182 bool isMember(face f) const { 00183 OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf()); 00184 return m_it[f].valid(); 00185 } 00186 00188 const ListPure<face> &faces() const { 00189 return m_faces; 00190 } 00191 00192 private: 00194 FaceArray<ListIterator<face> > m_it; 00196 ListPure<face> m_faces; 00197 }; 00198 00199 00200 00202 class OGDF_EXPORT FaceSet { 00203 public: 00205 FaceSet(const CombinatorialEmbedding &E) : m_it(E,ListIterator<face>()) { } 00206 00208 ~FaceSet() { } 00209 00211 00214 void insert(face f) { 00215 OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf()); 00216 ListIterator<face> &itF = m_it[f]; 00217 if (!itF.valid()) 00218 itF = m_faces.pushBack(f); 00219 } 00220 00222 /* running time: O(1) 00223 * Precond.: f is a face in the asociated embedding 00224 */ 00225 void remove(face f) { 00226 OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf()); 00227 ListIterator<face> &itF = m_it[f]; 00228 if (itF.valid()) { 00229 m_faces.del(itF); 00230 itF = ListIterator<face>(); 00231 } 00232 } 00233 00234 00236 00238 void clear() { 00239 ListIterator<face> it; 00240 for(it = m_faces.begin(); it.valid(); ++it) { 00241 m_it[*it] = ListIterator<face>(); 00242 } 00243 m_faces.clear(); 00244 } 00245 00246 00248 00251 bool isMember(face f) const { 00252 OGDF_ASSERT(f->embeddingOf() == m_it.embeddingOf()); 00253 return m_it[f].valid(); 00254 } 00255 00257 00259 int size() const { 00260 return m_faces.size(); 00261 } 00262 00264 const List<face> &faces() const { 00265 return m_faces; 00266 } 00267 00268 private: 00270 FaceArray<ListIterator<face> > m_it; 00272 List<face> m_faces; 00273 }; 00274 00275 00276 } // end namespace ogdf 00277 00278 00279 #endif 00280