6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
10 * \brief declaration and implementation of class FaceSetSimple,
11 * FaceSetPure and FaceSet
13 * \author Carsten Gutwenger
16 * This file is part of the Open Graph Drawing Framework (OGDF).
20 * See README.txt in the root directory of the OGDF installation for details.
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * Version 2 or 3 as published by the Free Software Foundation;
26 * see the file LICENSE.txt included in the packaging of this file
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public
37 * License along with this program; if not, write to the Free
38 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 * Boston, MA 02110-1301, USA.
41 * \see http://www.gnu.org/copyleft/gpl.html
42 ***************************************************************/
49 #ifndef OGDF_FACE_SET_H
50 #define OGDF_FACE_SET_H
53 #include <ogdf/basic/FaceArray.h>
54 #include <ogdf/basic/List.h>
61 //! Maintains a subset S of the faces contained in an associated combinatorial embedding E
62 /** (only insertion of elements and clear operation)
64 class OGDF_EXPORT FaceSetSimple
{
66 //! creates a new empty face set associated with combinatorial embedding E
67 FaceSetSimple(const CombinatorialEmbedding
&E
) : m_isContained(E
,false) { }
72 //! inserts face f into set S
73 /** running time: O(1)
74 * Precond.: f is a face in the associated combinatorial embedding
77 OGDF_ASSERT(f
->embeddingOf() == m_isContained
.embeddingOf());
78 bool &isContained
= m_isContained
[f
];
79 if (isContained
== false) {
86 //! removes all faces from set S
87 /** running time: O(|S|)
90 SListIterator
<face
> it
;
91 for(it
= m_faces
.begin(); it
.valid(); ++it
) {
92 m_isContained
[*it
] = false;
98 //! returns true iff face f is contained in S
99 /** running time: O(1)
100 * Precond.: f is a face in the asociated embedding
102 bool isMember(face f
) const {
103 OGDF_ASSERT(f
->embeddingOf() == m_isContained
.embeddingOf());
104 return m_isContained
[f
];
107 //! returns the list of faces contained in S
108 const SListPure
<face
> &faces() const {
113 //! m_isContained[f] is true <=> f is contained in S
114 FaceArray
<bool> m_isContained
;
115 //! list of faces contained in S
116 SListPure
<face
> m_faces
;
121 //! maintains a subset S of the faces contained in an associated combinatorial embedding E
122 /** (no efficient access to size of S)
124 class OGDF_EXPORT FaceSetPure
{
126 //! creates a new empty face set associated with combinatorial embedding E
127 FaceSetPure(const CombinatorialEmbedding
&E
) : m_it(E
,ListIterator
<face
>()) { }
132 //! inserts face f into set S
133 /** running time: O(1)
134 * Precond.: f is a face in the associated combinatorial embedding
136 void insert(face f
) {
137 OGDF_ASSERT(f
->embeddingOf() == m_it
.embeddingOf());
138 ListIterator
<face
> &itF
= m_it
[f
];
140 itF
= m_faces
.pushBack(f
);
143 //! removes face f from set S
144 /** running time: O(1)
145 * Precond.: f is a face in the asociated embedding
147 void remove(face f
) {
148 OGDF_ASSERT(f
->embeddingOf() == m_it
.embeddingOf());
149 ListIterator
<face
> &itF
= m_it
[f
];
152 itF
= ListIterator
<face
>();
157 //! removes all faces from set S
158 /** running time: O(|S|)
161 ListIterator
<face
> it
;
162 for(it
= m_faces
.begin(); it
.valid(); ++it
) {
163 m_it
[*it
] = ListIterator
<face
>();
169 //! returns true iff face f is contained in S
170 /** running time: O(1)
171 * Precond.: f is a face in the asociated embedding
173 bool isMember(face f
) const {
174 OGDF_ASSERT(f
->embeddingOf() == m_it
.embeddingOf());
175 return m_it
[f
].valid();
178 //! returns the list of faces contained in S
179 const ListPure
<face
> &faces() const {
184 //! m_it[f] contains list iterator pointing to f if f is contained in S, an invalid list iterator otherwise
185 FaceArray
<ListIterator
<face
> > m_it
;
186 //! list of faces contained in S
187 ListPure
<face
> m_faces
;
192 //! maintains a subset S of the faces contained in an associated combinatorial embedding E
193 class OGDF_EXPORT FaceSet
{
195 //! creates a new empty face set associated with combinatorial embedding E
196 FaceSet(const CombinatorialEmbedding
&E
) : m_it(E
,ListIterator
<face
>()) { }
201 //! inserts face f into set S
202 /** running time: O(1)
203 * Precond.: f is a face in the associated combinatorial embedding
205 void insert(face f
) {
206 OGDF_ASSERT(f
->embeddingOf() == m_it
.embeddingOf());
207 ListIterator
<face
> &itF
= m_it
[f
];
209 itF
= m_faces
.pushBack(f
);
212 //! removes face f from set S
213 /* running time: O(1)
214 * Precond.: f is a face in the asociated embedding
216 void remove(face f
) {
217 OGDF_ASSERT(f
->embeddingOf() == m_it
.embeddingOf());
218 ListIterator
<face
> &itF
= m_it
[f
];
221 itF
= ListIterator
<face
>();
226 //! removes all faces from set S
227 /** running time: O(|S|)
230 ListIterator
<face
> it
;
231 for(it
= m_faces
.begin(); it
.valid(); ++it
) {
232 m_it
[*it
] = ListIterator
<face
>();
238 //! returns true iff face f is contained in S
239 /** running time: O(1)
240 * Precond.: f is a face in the asociated embedding
242 bool isMember(face f
) const {
243 OGDF_ASSERT(f
->embeddingOf() == m_it
.embeddingOf());
244 return m_it
[f
].valid();
247 //! returns the size of set S
248 /** running time: O(1)
251 return m_faces
.size();
254 //! returns the list of faces contained in S
255 const List
<face
> &faces() const {
260 //! m_it[f] contains list iterator pointing to f if f is contained in S,an invalid list iterator otherwise
261 FaceArray
<ListIterator
<face
> > m_it
;
262 //! list of faces contained in S
267 } // end namespace ogdf