main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
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
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
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
34
namespace
Gecode
{
namespace
Iter {
namespace
Ranges {
35
45
template
<
class
I,
class
J>
46
class
Append
:
public
MinMax
{
47
protected
:
49
I
i
;
51
J
j
;
52
public
:
54
55
Append
(
void
);
58
Append
(I&
i
, J&
j
);
60
void
init
(I&
i
, J&
j
);
62
64
65
void
operator ++
(
void
);
68
};
69
70
80
template
<
class
I>
81
class
NaryAppend
:
public
MinMax
{
82
protected
:
84
I*
r
;
86
int
n
;
88
int
active
;
89
public
:
91
92
NaryAppend
(
void
);
95
NaryAppend
(I*
i
,
int
n
);
97
void
init
(I*
i
,
int
n
);
99
101
102
void
operator ++
(
void
);
105
};
106
107
108
/*
109
* Binary Append
110
*
111
*/
112
113
template
<
class
I,
class
J>
114
inline
void
115
Append<I,J>::operator ++
(
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
134
Append<I,J>::Append
(
void
) {}
135
136
template
<
class
I,
class
J>
137
forceinline
138
Append<I,J>::Append
(I& i0, J& j0)
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
164
NaryAppend<I>::operator ++
(
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
187
NaryAppend<I>::NaryAppend
(
void
) {}
188
189
template
<
class
I>
190
inline
191
NaryAppend<I>::NaryAppend
(I* r0,
int
n0)
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
Gecode::Iter::Ranges::NaryAppend::NaryAppend
NaryAppend(void)
Default constructor.
Definition:
ranges-append.hpp:187
Gecode::Iter::Ranges::NaryAppend::r
I * r
The array of iterators to be appended.
Definition:
ranges-append.hpp:84
Gecode::Iter::Ranges::Append::i
I i
First iterator.
Definition:
ranges-append.hpp:49
Gecode::Iter::Ranges::NaryAppend::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-append.hpp:164
Gecode
Gecode toplevel namespace
Gecode::Iter::Ranges::MinMax
Base for range iterators with explicit min and max.
Definition:
ranges-minmax.hpp:47
Gecode::Iter::Ranges::NaryAppend
Range iterator for appending arbitrarily many iterators.
Definition:
ranges-append.hpp:81
Gecode::Iter::Ranges::NaryAppend::init
void init(I *i, int n)
Initialize with n iterators in i.
Definition:
ranges-append.hpp:204
Gecode::Iter::Ranges::NaryAppend::n
int n
Number of iterators.
Definition:
ranges-append.hpp:86
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::Iter::Ranges::Append::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-append.hpp:115
Gecode::Iter::Ranges::Append::j
J j
Iterator to be appended.
Definition:
ranges-append.hpp:51
Gecode::Iter::Ranges::Append::Append
Append(void)
Default constructor.
Definition:
ranges-append.hpp:134
Gecode::Iter::Ranges::Append::init
void init(I &i, J &j)
Initialize with iterator i and j.
Definition:
ranges-append.hpp:148
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:67
Gecode::Iter::Ranges::NaryAppend::active
int active
Number of current iterator being processed.
Definition:
ranges-append.hpp:88
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::Iter::Ranges::MinMax::finish
void finish(void)
Set range such that iteration stops
Definition:
ranges-minmax.hpp:82
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::Iter::Ranges::Append
Range iterator for appending two range iterators
Definition:
ranges-append.hpp:46