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