1 /* Powerset class implementation: inline functions.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Powerset_inlines_hh
25 #define PPL_Powerset_inlines_hh 1
26 
27 #include "assertions.hh"
28 #include <algorithm>
29 
30 namespace Parma_Polyhedra_Library {
31 
32 template <typename D>
33 inline typename Powerset<D>::iterator
begin()34 Powerset<D>::begin() {
35   return sequence.begin();
36 }
37 
38 template <typename D>
39 inline typename Powerset<D>::iterator
end()40 Powerset<D>::end() {
41   return sequence.end();
42 }
43 
44 template <typename D>
45 inline typename Powerset<D>::const_iterator
begin() const46 Powerset<D>::begin() const {
47   return sequence.begin();
48 }
49 
50 template <typename D>
51 inline typename Powerset<D>::const_iterator
end() const52 Powerset<D>::end() const {
53   return sequence.end();
54 }
55 
56 template <typename D>
57 inline typename Powerset<D>::reverse_iterator
rbegin()58 Powerset<D>::rbegin() {
59   return reverse_iterator(end());
60 }
61 
62 template <typename D>
63 inline typename Powerset<D>::reverse_iterator
rend()64 Powerset<D>::rend() {
65   return reverse_iterator(begin());
66 }
67 
68 template <typename D>
69 inline typename Powerset<D>::const_reverse_iterator
rbegin() const70 Powerset<D>::rbegin() const {
71   return const_reverse_iterator(end());
72 }
73 
74 template <typename D>
75 inline typename Powerset<D>::const_reverse_iterator
rend() const76 Powerset<D>::rend() const {
77   return const_reverse_iterator(begin());
78 }
79 
80 template <typename D>
81 inline typename Powerset<D>::size_type
size() const82 Powerset<D>::size() const {
83   return sequence.size();
84 }
85 
86 template <typename D>
87 inline bool
empty() const88 Powerset<D>::empty() const {
89   return sequence.empty();
90 }
91 
92 template <typename D>
93 inline typename Powerset<D>::iterator
drop_disjunct(iterator position)94 Powerset<D>::drop_disjunct(iterator position) {
95   return sequence.erase(position.base);
96 }
97 
98 template <typename D>
99 inline void
drop_disjuncts(iterator first,iterator last)100 Powerset<D>::drop_disjuncts(iterator first, iterator last) {
101   sequence.erase(first.base, last.base);
102 }
103 
104 template <typename D>
105 inline void
clear()106 Powerset<D>::clear() {
107   sequence.clear();
108 }
109 
110 template <typename D>
111 inline
Powerset(const Powerset & y)112 Powerset<D>::Powerset(const Powerset& y)
113   : sequence(y.sequence), reduced(y.reduced) {
114 }
115 
116 template <typename D>
117 inline Powerset<D>&
operator =(const Powerset & y)118 Powerset<D>::operator=(const Powerset& y) {
119   sequence = y.sequence;
120   reduced = y.reduced;
121   return *this;
122 }
123 
124 template <typename D>
125 inline void
m_swap(Powerset & y)126 Powerset<D>::m_swap(Powerset& y) {
127   std::swap(sequence, y.sequence);
128   std::swap(reduced, y.reduced);
129 }
130 
131 template <typename D>
132 inline
Powerset()133 Powerset<D>::Powerset()
134   : sequence(), reduced(true) {
135 }
136 
137 template <typename D>
138 inline
Powerset(const D & d)139 Powerset<D>::Powerset(const D& d)
140   : sequence(), reduced(false) {
141   sequence.push_back(d);
142   PPL_ASSERT_HEAVY(OK());
143 }
144 
145 template <typename D>
146 inline
~Powerset()147 Powerset<D>::~Powerset() {
148 }
149 
150 template <typename D>
151 inline void
add_non_bottom_disjunct_preserve_reduction(const D & d)152 Powerset<D>::add_non_bottom_disjunct_preserve_reduction(const D& d) {
153   // !d.is_bottom() is asserted by the callee.
154   add_non_bottom_disjunct_preserve_reduction(d, begin(), end());
155 }
156 
157 template <typename D>
158 inline void
add_disjunct(const D & d)159 Powerset<D>::add_disjunct(const D& d) {
160   sequence.push_back(d);
161   reduced = false;
162 }
163 
164 /*! \relates Powerset */
165 template <typename D>
166 inline
operator !=(const Powerset<D> & x,const Powerset<D> & y)167 bool operator!=(const Powerset<D>& x, const Powerset<D>& y) {
168   return !(x == y);
169 }
170 
171 template <typename D>
172 inline bool
is_top() const173 Powerset<D>::is_top() const {
174   // Must perform omega-reduction for correctness.
175   omega_reduce();
176   const_iterator xi = begin();
177   const_iterator x_end = end();
178   return xi != x_end && xi->is_top() && ++xi == x_end;
179 }
180 
181 template <typename D>
182 inline bool
is_bottom() const183 Powerset<D>::is_bottom() const {
184   // Must perform omega-reduction for correctness.
185   omega_reduce();
186   return empty();
187 }
188 
189 template <typename D>
190 inline void
collapse()191 Powerset<D>::collapse() {
192   if (!empty()) {
193     collapse(sequence.begin());
194   }
195 }
196 
197 template <typename D>
198 inline void
meet_assign(const Powerset & y)199 Powerset<D>::meet_assign(const Powerset& y) {
200   pairwise_apply_assign(y, std::mem_fun_ref(&D::meet_assign));
201 }
202 
203 template <typename D>
204 inline void
upper_bound_assign(const Powerset & y)205 Powerset<D>::upper_bound_assign(const Powerset& y) {
206   least_upper_bound_assign(y);
207 }
208 
209 template <typename D>
210 inline bool
upper_bound_assign_if_exact(const Powerset & y)211 Powerset<D>::upper_bound_assign_if_exact(const Powerset& y) {
212   least_upper_bound_assign(y);
213   return true;
214 }
215 
216 template <typename D>
217 inline memory_size_type
total_memory_in_bytes() const218 Powerset<D>::total_memory_in_bytes() const {
219   return sizeof(*this) + external_memory_in_bytes();
220 }
221 
222 /*! \relates Powerset */
223 template <typename D>
224 inline void
swap(Powerset<D> & x,Powerset<D> & y)225 swap(Powerset<D>& x, Powerset<D>& y) {
226   x.m_swap(y);
227 }
228 
229 } // namespace Parma_Polyhedra_Library
230 
231 #endif // !defined(PPL_Powerset_inlines_hh)
232