/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2003 * * Last modified: * $Date: 2008-07-11 09:31:51 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $ * $Revision: 7288 $ * * 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. * */ namespace Gecode { /* * Integer sets * */ forceinline IntSet::IntSet(void) {} template IntSet::IntSet(I& i) { Support::DynamicArray d; int n=0; while (i()) { d[n].min = i.min(); d[n].max = i.max(); ++n; ++i; } if (n > 0) { IntSetObject* o = IntSetObject::allocate(n); for (int j=n; j--; ) o->r[j]=d[j]; 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(object())->r[i].min; } forceinline int IntSet::max(int i) const { assert(object() != NULL); return static_cast(object())->r[i].max; } forceinline unsigned int IntSet::width(int i) const { assert(object() != NULL); IntSetObject* o = static_cast(object()); return static_cast(o->r[i].max-o->r[i].min)+1; } forceinline int IntSet::size(void) const { IntSetObject* o = static_cast(object()); return (o == NULL) ? 0 : o->n; } forceinline int IntSet::min(void) const { IntSetObject* o = static_cast(object()); return (o == NULL) ? 1 : o->r[0].min; } forceinline int IntSet::max(void) const { IntSetObject* o = static_cast(object()); return (o == NULL) ? 0 : o->r[o->n-1].max; } /* * Range iterator for integer sets * */ forceinline IntSetRanges::IntSetRanges(void) {} forceinline void IntSetRanges::init(const IntSet& s) { int n = s.size(); if (n > 0) { i = &static_cast(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 imin; } forceinline int IntSetRanges::max(void) const { return i->max; } forceinline unsigned int IntSetRanges::width(void) const { return static_cast(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::init(r); } forceinline void IntSetValues::init(const IntSet& s) { IntSetRanges r(s); Iter::Ranges::ToValues::init(r); } } // STATISTICS: int-var