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-operations.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
47
template
<
class
I>
49
unsigned
int
size
(I&
i
);
50
52
template
<
class
I,
class
J>
53
bool
equal
(I&
i
, J& j);
54
56
template
<
class
I,
class
J>
57
bool
subset
(I&
i
, J& j);
58
60
template
<
class
I,
class
J>
61
bool
disjoint
(I&
i
, J& j);
62
64
enum
CompareStatus
{
65
CS_SUBSET
,
66
CS_DISJOINT
,
67
CS_NONE
68
};
69
71
template
<
class
I,
class
J>
72
CompareStatus
compare
(I&
i
, J& j);
74
75
76
template
<
class
I>
77
inline
unsigned
int
78
size
(I&
i
) {
79
unsigned
int
s = 0;
80
while
(
i
()) {
81
s +=
i
.width(); ++
i
;
82
}
83
return
s;
84
}
85
86
template
<
class
I,
class
J>
87
forceinline
bool
88
equal
(I&
i
, J& j) {
89
// Are i and j equal?
90
while
(
i
() && j())
91
if
((
i
.min() == j.min()) && (
i
.max() == j.max())) {
92
++
i
; ++j;
93
}
else
{
94
return
false
;
95
}
96
return
!
i
() && !j();
97
}
98
99
template
<
class
I,
class
J>
100
forceinline
bool
101
subset
(I&
i
, J& j) {
102
// Is i subset of j?
103
while
(
i
() && j())
104
if
(j.max() <
i
.min()) {
105
++j;
106
}
else
if
((
i
.min() >= j.min()) && (
i
.max() <= j.max())) {
107
++
i
;
108
}
else
{
109
return
false
;
110
}
111
return
!
i
();
112
}
113
114
template
<
class
I,
class
J>
115
forceinline
bool
116
disjoint
(I&
i
, J& j) {
117
// Are i and j disjoint?
118
while
(
i
() && j())
119
if
(j.max() <
i
.min()) {
120
++j;
121
}
else
if
(
i
.max() < j.min()) {
122
++
i
;
123
}
else
{
124
return
false
;
125
}
126
return
true
;
127
}
128
129
template
<
class
I,
class
J>
130
forceinline
CompareStatus
131
compare
(I&
i
, J& j) {
132
bool
subset
=
true
;
133
bool
disjoint
=
true
;
134
while
(
i
() && j()) {
135
if
(j.max() <
i
.min()) {
136
++j;
137
}
else
if
(
i
.max() < j.min()) {
138
++
i
;
subset
=
false
;
139
}
else
if
((
i
.min() >= j.min()) && (
i
.max() <= j.max())) {
140
++
i
;
disjoint
=
false
;
141
}
else
if
(
i
.max() <= j.max()) {
142
++
i
;
disjoint
=
false
;
subset
=
false
;
143
}
else
if
(j.max() <=
i
.max()) {
144
++j;
disjoint
=
false
;
subset
=
false
;
145
}
146
}
147
if
(
i
())
148
subset
=
false
;
149
if
(
subset
)
150
return
CS_SUBSET
;
151
return
disjoint
?
CS_DISJOINT
:
CS_NONE
;
152
}
153
154
}}}
155
156
// STATISTICS: iter-any
157
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Iter::Ranges::CS_NONE
@ CS_NONE
Neither of the above.
Definition:
ranges-operations.hpp:67
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:78
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Iter::Ranges::disjoint
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
Definition:
ranges-operations.hpp:116
Gecode::Iter::Ranges::subset
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Definition:
ranges-operations.hpp:101
Gecode
Gecode toplevel namespace
Gecode::Iter::Ranges::CS_SUBSET
@ CS_SUBSET
First is subset of second iterator.
Definition:
ranges-operations.hpp:65
Gecode::Iter::Ranges::equal
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Definition:
ranges-operations.hpp:88
Gecode::Iter::Ranges::CompareStatus
CompareStatus
Comapre two iterators with each other.
Definition:
ranges-operations.hpp:64
Gecode::Iter::Ranges::compare
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Definition:
ranges-operations.hpp:131
Gecode::Iter::Ranges::CS_DISJOINT
@ CS_DISJOINT
Intersection is empty.
Definition:
ranges-operations.hpp:66