main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:29 for Gecode by
doxygen
1.8.4
gecode
iter
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.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2004
8
*
9
* Last modified:
10
* $Date: 2010-07-28 17:35:33 +0200 (Wed, 28 Jul 2010) $ by $Author: schulte $
11
* $Revision: 11294 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
namespace
Gecode {
namespace
Iter {
namespace
Ranges {
39
49
template
<
class
I,
class
J>
50
class
Append
:
public
MinMax
{
51
protected
:
53
I
i
;
55
J
j
;
56
public
:
58
59
Append
(
void
);
62
Append
(I&
i
, J&
j
);
64
void
init
(I&
i
, J&
j
);
66
68
69
void
operator ++
(
void
);
72
};
73
74
84
template
<
class
I>
85
class
NaryAppend
:
public
MinMax
{
86
protected
:
88
I*
r
;
90
int
n
;
92
int
active
;
93
public
:
95
96
NaryAppend
(
void
);
99
NaryAppend
(I*
i
,
int
n
);
101
void
init
(I*
i
,
int
n
);
103
105
106
void
operator ++
(
void
);
109
};
110
111
112
/*
113
* Binary Append
114
*
115
*/
116
117
template
<
class
I,
class
J>
118
inline
void
119
Append<I,J>::operator ++
(
void
) {
120
if
(
i
()) {
121
mi =
i
.min(); ma =
i
.max();
122
++
i
;
123
if
(!
i
() && j() && (j.min() == ma+1)) {
124
ma = j.max();
125
++j;
126
}
127
}
else
if
(j()) {
128
mi = j.min(); ma = j.max();
129
++j;
130
}
else
{
131
finish();
132
}
133
}
134
135
136
template
<
class
I,
class
J>
137
forceinline
138
Append<I,J>::Append
(
void
) {}
139
140
template
<
class
I,
class
J>
141
forceinline
142
Append<I,J>::Append
(I& i0, J& j0)
143
:
i
(i0), j(j0) {
144
if
(
i
() ||
j
())
145
operator ++
();
146
else
147
finish
();
148
}
149
150
template
<
class
I,
class
J>
151
forceinline
void
152
Append<I,J>::init
(I& i0, J& j0) {
153
i
= i0; j = j0;
154
if
(
i
() || j())
155
operator ++();
156
else
157
finish();
158
}
159
160
161
/*
162
* Nary Append
163
*
164
*/
165
166
template
<
class
I>
167
inline
void
168
NaryAppend<I>::operator ++
(
void
) {
169
mi =
r
[active].min();
170
ma =
r
[active].max();
171
++
r
[active];
172
while
(!
r
[active]()) {
173
//Skip empty iterators:
174
do
{
175
active++;
176
if
(active >=
n
) {
177
finish();
return
;
178
}
179
}
while
(!
r
[active]());
180
if
(
r
[active].
min
() == ma+1){
181
ma =
r
[active].max();
182
++
r
[active];
183
}
else
{
184
return
;
185
}
186
}
187
}
188
189
template
<
class
I>
190
forceinline
191
NaryAppend<I>::NaryAppend
(
void
) {}
192
193
template
<
class
I>
194
inline
195
NaryAppend<I>::NaryAppend
(I* r0,
int
n0)
196
:
r
(r0),
n
(n0), active(0) {
197
while
(
active
<
n
&& !
r
[
active
]())
198
active
++;
199
if
(
active
<
n
){
200
operator ++
();
201
}
else
{
202
finish
();
203
}
204
}
205
206
template
<
class
I>
207
inline
void
208
NaryAppend<I>::init
(I* r0,
int
n0) {
209
r
= r0;
n
= n0; active = 0;
210
while
(active <
n
&& !
r
[active]())
211
active++;
212
if
(active <
n
){
213
operator ++();
214
}
else
{
215
finish();
216
}
217
}
218
219
}}}
220
221
// STATISTICS: iter-any
222