/usr/include/gecode/int/int-set-1.hpp is in libgecode-dev 3.7.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2003
*
* Last modified:
* $Date: 2010-07-28 17:35:33 +0200 (Wed, 28 Jul 2010) $ by $Author: schulte $
* $Revision: 11294 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <sstream>
namespace Gecode {
/*
* Integer sets
*
*/
forceinline
IntSet::IntSet(void) {}
template<class I>
IntSet::IntSet(I& i) {
Support::DynamicArray<Range,Heap> d(heap);
int n=0;
unsigned int s = 0;
while (i()) {
d[n].min = i.min(); d[n].max = i.max(); s += i.width();
++n; ++i;
}
if (n > 0) {
IntSetObject* o = IntSetObject::allocate(n);
for (int j=n; j--; )
o->r[j]=d[j];
o->size = s;
object(o);
}
}
#ifndef __INTEL_COMPILER
template<>
#endif
forceinline
IntSet::IntSet(const IntSet& s)
: SharedHandle(s) {}
#ifndef __INTEL_COMPILER
template<>
#endif
forceinline
IntSet::IntSet(IntSet& s)
: SharedHandle(s) {}
forceinline
IntSet::IntSet(const int r[][2], int n) {
init(r,n);
}
forceinline
IntSet::IntSet(const int r[], int n) {
init(r,n);
}
forceinline
IntSet::IntSet(int n, int m) {
init(n,m);
}
forceinline int
IntSet::min(int i) const {
assert(object() != NULL);
return static_cast<IntSetObject*>(object())->r[i].min;
}
forceinline int
IntSet::max(int i) const {
assert(object() != NULL);
return static_cast<IntSetObject*>(object())->r[i].max;
}
forceinline unsigned int
IntSet::width(int i) const {
assert(object() != NULL);
IntSetObject* o = static_cast<IntSetObject*>(object());
return static_cast<unsigned int>(o->r[i].max-o->r[i].min)+1;
}
forceinline int
IntSet::ranges(void) const {
IntSetObject* o = static_cast<IntSetObject*>(object());
return (o == NULL) ? 0 : o->n;
}
forceinline bool
IntSet::in(int n) const {
IntSetObject* o = static_cast<IntSetObject*>(object());
if ((o == NULL) || (n < o->r[0].min) || (n > o->r[o->n-1].max))
return false;
else
return o->in(n);
}
forceinline int
IntSet::min(void) const {
IntSetObject* o = static_cast<IntSetObject*>(object());
return (o == NULL) ? Int::Limits::max : o->r[0].min;
}
forceinline int
IntSet::max(void) const {
IntSetObject* o = static_cast<IntSetObject*>(object());
return (o == NULL) ? Int::Limits::min : o->r[o->n-1].max;
}
forceinline unsigned int
IntSet::size(void) const {
IntSetObject* o = static_cast<IntSetObject*>(object());
return (o == NULL) ? 0 : o->size;
}
forceinline unsigned int
IntSet::width(void) const {
return static_cast<unsigned int>(max()-min()+1);
}
/*
* Range iterator for integer sets
*
*/
forceinline
IntSetRanges::IntSetRanges(void) {}
forceinline
void
IntSetRanges::init(const IntSet& s) {
int n = s.ranges();
if (n > 0) {
i = &static_cast<IntSet::IntSetObject*>(s.object())->r[0]; e = i+n;
} else {
i = e = NULL;
}
}
forceinline
IntSetRanges::IntSetRanges(const IntSet& s) { init(s); }
forceinline void
IntSetRanges::operator ++(void) {
i++;
}
forceinline bool
IntSetRanges::operator ()(void) const {
return i<e;
}
forceinline int
IntSetRanges::min(void) const {
return i->min;
}
forceinline int
IntSetRanges::max(void) const {
return i->max;
}
forceinline unsigned int
IntSetRanges::width(void) const {
return static_cast<unsigned int>(i->max - i->min) + 1;
}
/*
* Value iterator for integer sets
*
*/
forceinline
IntSetValues::IntSetValues(void) {}
forceinline
IntSetValues::IntSetValues(const IntSet& s) {
IntSetRanges r(s);
Iter::Ranges::ToValues<IntSetRanges>::init(r);
}
forceinline void
IntSetValues::init(const IntSet& s) {
IntSetRanges r(s);
Iter::Ranges::ToValues<IntSetRanges>::init(r);
}
template<class Char, class Traits>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os, const IntSet& is) {
std::basic_ostringstream<Char,Traits> s;
s.copyfmt(os); s.width(0);
s << '{';
for (int i = 0; i < is.ranges(); ) {
int min = is.min(i);
int max = is.max(i);
if (min == max)
s << min;
else
s << min << ".." << max;
i++;
if (i < is.ranges())
s << ',';
}
s << '}';
return os << s.str();
}
}
// STATISTICS: int-var
|