Generated on for Gecode by doxygen 1.18.0
ranges-append.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2004
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Iter { namespace Ranges {
35
44
45 template<class I, class J>
46 class Append : public MinMax {
47 protected:
49 I i;
51 J j;
52 public:
54
55
56 Append(void);
58 Append(I& i, J& j);
60 void init(I& i, J& j);
62
64
65
66 void operator ++(void);
68 };
69
70
79
80 template<class I>
81 class NaryAppend : public MinMax {
82 protected:
84 I* r;
86 int n;
88 int active;
89 public:
91
92
93 NaryAppend(void);
95 NaryAppend(I* i, int n);
97 void init(I* i, int n);
99
101
102
103 void operator ++(void);
105 };
106
107
108 /*
109 * Binary Append
110 *
111 */
112
113 template<class I, class J>
114 inline void
116 if (i()) {
117 mi = i.min(); ma = i.max();
118 ++i;
119 if (!i() && j() && (j.min() == ma+1)) {
120 ma = j.max();
121 ++j;
122 }
123 } else if (j()) {
124 mi = j.min(); ma = j.max();
125 ++j;
126 } else {
127 finish();
128 }
129 }
130
131
132 template<class I, class J>
133 forceinline
135
136 template<class I, class J>
137 forceinline
139 : i(i0), j(j0) {
140 if (i() || j())
141 operator ++();
142 else
143 finish();
144 }
145
146 template<class I, class J>
147 forceinline void
148 Append<I,J>::init(I& i0, J& j0) {
149 i = i0; j = j0;
150 if (i() || j())
151 operator ++();
152 else
153 finish();
154 }
155
156
157 /*
158 * Nary Append
159 *
160 */
161
162 template<class I>
163 inline void
165 mi = r[active].min();
166 ma = r[active].max();
167 ++r[active];
168 while (!r[active]()) {
169 //Skip empty iterators:
170 do {
171 active++;
172 if (active >= n) {
173 finish(); return;
174 }
175 } while (!r[active]());
176 if (r[active].min() == ma+1){
177 ma = r[active].max();
178 ++r[active];
179 } else {
180 return;
181 }
182 }
183 }
184
185 template<class I>
186 forceinline
188
189 template<class I>
190 inline
192 : r(r0), n(n0), active(0) {
193 while (active < n && !r[active]())
194 active++;
195 if (active < n){
196 operator ++();
197 } else {
198 finish();
199 }
200 }
201
202 template<class I>
203 inline void
204 NaryAppend<I>::init(I* r0, int n0) {
205 r = r0; n = n0; active = 0;
206 while (active < n && !r[active]())
207 active++;
208 if (active < n){
209 operator ++();
210 } else {
211 finish();
212 }
213 }
214
215}}}
216
217// STATISTICS: iter-any
218
void init(I &i, J &j)
Initialize with iterator i and j.
void operator++(void)
Move iterator to next range (if possible).
Append(void)
Default constructor.
J j
Iterator to be appended.
int ma
Maximum of current range.
int mi
Minimum of current range.
int min(void) const
Return smallest value of range.
MinMax(void)
Default constructor.
void finish(void)
Set range such that iteration stops
void operator++(void)
Move iterator to next range (if possible).
NaryAppend(void)
Default constructor.
void init(I *i, int n)
Initialize with n iterators in i.
I * r
The array of iterators to be appended.
int active
Number of current iterator being processed.
Range iterators.
Definition iter.hh:43
Range and value iterators.
Definition iter.hh:41
Gecode toplevel namespace