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
values-union.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, 2008
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
Values {
35
42
template
<
class
I,
class
J>
43
class
Union
{
44
protected
:
46
I
i
;
48
J
j
;
50
int
v
;
52
bool
done
;
53
public
:
55
56
Union
(
void
);
59
Union
(I&
i
, J&
j
);
61
void
init
(I&
i
, J&
j
);
63
65
66
bool
operator ()
(
void
)
const
;
69
void
operator ++
(
void
);
71
73
74
int
val
(
void
)
const
;
77
};
78
79
80
template
<
class
I,
class
J>
81
forceinline
82
Union<I,J>::Union
(
void
) :
v
(0) {}
83
84
template
<
class
I,
class
J>
85
forceinline
void
86
Union<I,J>::operator ++
(
void
) {
87
if
(
i
()) {
88
if
(j()) {
89
if
(
i
.val() == j.val()) {
90
v
=
i
.val(); ++
i
; ++j;
91
}
else
if
(
i
.val() < j.val()) {
92
v
=
i
.val(); ++
i
;
93
}
else
{
94
v
=j.val(); ++j;
95
}
96
}
else
{
97
v
=
i
.val(); ++
i
;
98
}
99
}
else
if
(j()) {
100
v
=j.val(); ++j;
101
}
else
{
102
done=
true
;
103
}
104
}
105
106
template
<
class
I,
class
J>
107
inline
void
108
Union<I,J>::init
(I& i0, J& j0) {
109
i
=i0; j=j0;
v
=0; done=
false
;
110
operator ++();
111
}
112
113
template
<
class
I,
class
J>
114
forceinline
115
Union<I,J>::Union
(I& i0, J& j0) :
i
(i0), j(j0),
v
(0), done(false) {
116
operator ++
();
117
}
118
119
template
<
class
I,
class
J>
120
forceinline
bool
121
Union<I,J>::operator ()
(
void
)
const
{
122
return
!done;
123
}
124
125
template
<
class
I,
class
J>
126
forceinline
int
127
Union<I,J>::val
(
void
)
const
{
128
return
v
;
129
}
130
131
}}}
132
133
// STATISTICS: iter-any
Gecode::Iter::Values::Union::init
void init(I &i, J &j)
Initialize with values from i and j.
Definition:
values-union.hpp:108
Gecode::Iter::Values::Union::j
J j
Second iterator.
Definition:
values-union.hpp:48
Gecode::Iter::Values::Union::v
int v
Current value.
Definition:
values-union.hpp:50
Gecode
Gecode toplevel namespace
Gecode::Iter::Values::Union::operator++
void operator++(void)
Move iterator to next value (if possible)
Definition:
values-union.hpp:86
Gecode::Iter::Values::Union::val
int val(void) const
Return current value.
Definition:
values-union.hpp:127
Test::Int::Distinct::v
const int v[7]
Definition:
distinct.cpp:259
Gecode::Iter::Values::Union::Union
Union(void)
Default constructor.
Definition:
values-union.hpp:82
Gecode::Iter::Values::Union::done
bool done
Whether iterator is done.
Definition:
values-union.hpp:52
Gecode::Iter::Values::Union::operator()
bool operator()(void) const
Test whether iterator is still at a value or done.
Definition:
values-union.hpp:121
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Iter::Values::Union
Value iterator for the union of two value iterators.
Definition:
values-union.hpp:43
Gecode::Iter::Values::Union::i
I i
First iterator.
Definition:
values-union.hpp:46
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})