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