main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
iter
ranges-list.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, 2010
8
*
9
* Last modified:
10
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
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
45
class
RangeListIter
{
46
protected
:
48
class
RangeList
:
public
Support::BlockClient
<RangeList,Region> {
49
public
:
51
int
min
,
max
;
53
RangeList
*
next
;
54
};
56
class
RLIO
:
public
Support::BlockAllocator
<RangeList,Region> {
57
public
:
59
unsigned
int
use_cnt
;
61
RLIO
(
Region
&
r
);
62
};
64
RLIO
*
rlio
;
66
RangeList
*
h
;
68
RangeList
*
c
;
70
void
set
(
RangeList
*
l
);
72
RangeList
*
get
(
void
)
const
;
74
RangeList
*
range
(
int
min
,
int
max
,
RangeList
*&
f
);
76
RangeList
*
range
(
int
min
,
int
max
);
78
template
<
class
I>
79
RangeList
*
range
(I&
i
,
RangeList
*&
f
);
81
template
<
class
I>
82
RangeList
*
range
(I&
i
);
84
template
<
class
I>
85
RangeList
*
copy
(I&
i
);
86
public
:
88
89
RangeListIter
(
void
);
92
RangeListIter
(
const
RangeListIter
&
i
);
94
RangeListIter
(
Region
&
r
);
96
void
init
(
Region
&
r
);
98
RangeListIter
&
operator =
(
const
RangeListIter
&
i
);
100
102
103
bool
operator ()
(
void
)
const
;
106
void
operator ++
(
void
);
108
void
reset
(
void
);
110
112
113
int
min
(
void
)
const
;
116
int
max
(
void
)
const
;
118
unsigned
int
width
(
void
)
const
;
120
122
~RangeListIter
(
void
);
123
};
124
125
126
forceinline
127
RangeListIter::RLIO::RLIO
(
Region
&
r
)
128
: Support::BlockAllocator<
RangeList
,
Region
>(
r
), use_cnt(1) {}
129
130
131
forceinline
132
RangeListIter::RangeListIter
(
void
)
133
:
rlio
(NULL),
h
(NULL),
c
(NULL) {}
134
135
forceinline
136
RangeListIter::RangeListIter
(
Region
&
r
)
137
: rlio(new (
r
.ralloc(sizeof(
RLIO
)))
RLIO
(
r
)), h(NULL),
c
(NULL) {}
138
139
forceinline
void
140
RangeListIter::init
(
Region
&
r
) {
141
rlio
=
new
(
r
.ralloc(
sizeof
(
RLIO
)))
RLIO
(
r
);
142
h
=
c
= NULL;
143
}
144
145
forceinline
146
RangeListIter::RangeListIter
(
const
RangeListIter
&
i
)
147
: rlio(
i
.rlio), h(
i
.h),
c
(
i
.
c
) {
148
if
(
rlio
!= NULL)
149
rlio
->
use_cnt
++;
150
}
151
152
forceinline
RangeListIter
&
153
RangeListIter::operator =
(
const
RangeListIter
&
i
) {
154
if
(&
i
!=
this
) {
155
if
((
rlio
!= NULL) && (--
rlio
->
use_cnt
== 0)) {
156
Region
&
r
=
rlio
->
allocator
();
157
rlio
->~RLIO();
158
r
.rfree(
rlio
,
sizeof
(
RLIO
));
159
}
160
rlio
=
i
.rlio;
161
if
(
rlio
!= NULL)
162
rlio
->
use_cnt
++;
163
c
=
i
.c;
h
=
i
.h;
164
}
165
return
*
this
;
166
}
167
168
forceinline
169
RangeListIter::~RangeListIter
(
void
) {
170
if
((
rlio
!= NULL) && (--
rlio
->
use_cnt
== 0)) {
171
Region
&
r
=
rlio
->
allocator
();
172
rlio
->~RLIO();
173
r
.rfree(
rlio
,
sizeof
(
RLIO
));
174
}
175
}
176
177
178
forceinline
void
179
RangeListIter::set
(
RangeList
*
l
) {
180
h
=
c
=
l
;
181
}
182
183
forceinline
RangeListIter::RangeList
*
184
RangeListIter::get
(
void
)
const
{
185
return
h
;
186
}
187
188
forceinline
RangeListIter::RangeList
*
189
RangeListIter::range
(
int
min
,
int
max
,
RangeList
*&
f
) {
190
RangeList
*
t
;
191
// Take element from freelist if possible
192
if
(
f
!= NULL) {
193
t
=
f
;
f
=
f
->next;
194
}
else
{
195
t
=
new
(*rlio)
RangeList
;
196
}
197
t
->min =
min
;
t
->max =
max
;
198
return
t
;
199
}
200
201
forceinline
RangeListIter::RangeList
*
202
RangeListIter::range
(
int
min
,
int
max
) {
203
RangeList
*
t
=
new
(*rlio)
RangeList
;
204
t
->min =
min
;
t
->max =
max
;
205
return
t
;
206
}
207
208
template
<
class
I>
209
forceinline
RangeListIter::RangeList
*
210
RangeListIter::range
(I&
i
,
RangeList
*&
f
) {
211
return
range
(
i
.min(),
i
.max(),
f
);
212
}
213
214
template
<
class
I>
215
forceinline
RangeListIter::RangeList
*
216
RangeListIter::range
(I&
i
) {
217
return
range
(
i
.min(),
i
.max());
218
}
219
220
template
<
class
I>
221
inline
RangeListIter::RangeList
*
222
RangeListIter::copy
(I&
i
) {
223
RangeList
*
h
;
224
RangeList
**
c
= &
h
;
225
for
( ;
i
(); ++
i
) {
226
RangeList
*
t
=
range
(
i
);
227
*
c
=
t
;
c
= &
t
->next;
228
}
229
*
c
= NULL;
230
return
h
;
231
}
232
233
forceinline
bool
234
RangeListIter::operator ()
(
void
)
const
{
235
return
c
!= NULL;
236
}
237
238
forceinline
void
239
RangeListIter::operator ++
(
void
) {
240
c
=
c
->
next
;
241
}
242
243
forceinline
void
244
RangeListIter::reset
(
void
) {
245
c
=
h
;
246
}
247
248
forceinline
int
249
RangeListIter::min
(
void
)
const
{
250
return
c
->
min
;
251
}
252
forceinline
int
253
RangeListIter::max
(
void
)
const
{
254
return
c
->
max
;
255
}
256
forceinline
unsigned
int
257
RangeListIter::width
(
void
)
const
{
258
return
static_cast<
unsigned
int
>
(
c
->
max
-
c
->
min
)+1;
259
}
260
261
}}}
262
263
// STATISTICS: iter-any
264
Gecode::Iter::Ranges::RangeListIter::~RangeListIter
~RangeListIter(void)
Destructor.
Definition:
ranges-list.hpp:169
Gecode::Iter::Ranges::RangeListIter::RangeListIter
RangeListIter(void)
Default constructor.
Definition:
ranges-list.hpp:132
Gecode::Support::BlockAllocator::allocator
A & allocator(void)
Return allocator used.
Definition:
block-allocator.hpp:120
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Support::BlockAllocator
Manage memory organized into block lists (allocator)
Definition:
block-allocator.hpp:49
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:53
Gecode::Iter::Ranges::RangeListIter::operator()
bool operator()(void) const
Test whether iterator is still at a range or done.
Definition:
ranges-list.hpp:234
Gecode::Iter::Ranges::RangeListIter::range
RangeList * range(int min, int max, RangeList *&f)
Create new range possibly from freelist f and init.
Definition:
ranges-list.hpp:189
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:234
Gecode::Support::BlockClient
Client for block allocator of type T.
Definition:
block-allocator.hpp:88
Gecode::Iter::Ranges::RangeListIter::operator=
RangeListIter & operator=(const RangeListIter &i)
Assignment operator.
Definition:
ranges-list.hpp:153
Gecode::Iter::Ranges::RangeListIter::RLIO
Shared object for allocation.
Definition:
ranges-list.hpp:56
Gecode::Iter::Ranges::RangeListIter::reset
void reset(void)
Reset iterator to start.
Definition:
ranges-list.hpp:244
Gecode
Gecode toplevel namespace
Gecode::Iter::Ranges::RangeListIter::max
int max(void) const
Return largest value of range.
Definition:
ranges-list.hpp:253
Gecode::Iter::Ranges::RangeListIter::RangeList
Range list class.
Definition:
ranges-list.hpp:48
Gecode::Iter::Ranges::RangeListIter::RLIO::RLIO
RLIO(Region &r)
Initialize.
Definition:
ranges-list.hpp:127
Gecode::Iter::Ranges::RangeListIter::copy
RangeList * copy(I &i)
Copy the iterator i to a range list.
Definition:
ranges-list.hpp:222
Gecode::Region
Handle to region.
Definition:
region.hpp:61
Gecode::Iter::Ranges::RangeListIter::RangeList::max
int max
Definition:
ranges-list.hpp:51
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::Iter::Ranges::RangeListIter::rlio
RLIO * rlio
Reference to shared object.
Definition:
ranges-list.hpp:64
Gecode::Iter::Ranges::RangeListIter
Iterator over range lists.
Definition:
ranges-list.hpp:45
Gecode::Iter::Ranges::RangeListIter::min
int min(void) const
Return smallest value of range.
Definition:
ranges-list.hpp:249
Gecode::Iter::Ranges::RangeListIter::set
void set(RangeList *l)
Set range lists.
Definition:
ranges-list.hpp:179
Gecode::Iter::Ranges::RangeListIter::RLIO::use_cnt
unsigned int use_cnt
Counter used for reference counting.
Definition:
ranges-list.hpp:59
Gecode::Iter::Ranges::RangeListIter::RangeList::min
int min
Minimum and maximum of a range.
Definition:
ranges-list.hpp:51
l
NNF * l
Left subtree.
Definition:
bool-expr.cpp:244
Gecode::Iter::Ranges::RangeListIter::RangeList::next
RangeList * next
Next element.
Definition:
ranges-list.hpp:53
Gecode::Iter::Ranges::RangeListIter::init
void init(Region &r)
Initialize.
Definition:
ranges-list.hpp:140
Gecode::Iter::Ranges::RangeListIter::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-list.hpp:239
Gecode::Iter::Ranges::RangeListIter::get
RangeList * get(void) const
Get head of current range list.
Definition:
ranges-list.hpp:184
Gecode::Iter::Ranges::RangeListIter::h
RangeList * h
Head of range list.
Definition:
ranges-list.hpp:66
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:71
Gecode::f
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::Iter::Ranges::RangeListIter::width
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Definition:
ranges-list.hpp:257
Gecode::Iter::Ranges::RangeListIter::c
RangeList * c
Current list element.
Definition:
ranges-list.hpp:68