void CachedView<View>::initCache(Space& home, const IntSet& s) { _firstRange = NULL; for (int i=s.ranges(); i--;) { _firstRange = new (home) RangeList(s.min(i),s.max(i),_firstRange); if (i==s.ranges()-1) _lastRange = _firstRange; } _size = s.size(); }
BndSet::BndSet(Space& home, const IntSet& is) { if (is.ranges()==0) { fst(NULL); lst(NULL); _size = 0; } else { int n = is.ranges(); RangeList* r = home.alloc<RangeList>(n); fst(r); lst(r+n-1); unsigned int s = 0; for (int i = n; i--; ) { s += is.width(i); r[i].min(is.min(i)); r[i].max(is.max(i)); r[i].next(&r[i+1]); } r[n-1].next(NULL); _size = s; } assert(isConsistent()); }
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; } }
ExecStatus ReIntSet<View,rm>::post(Home home, View x, const IntSet& s, BoolView b) { if (s.ranges() == 0) { if (rm == RM_PMI) return ES_OK; GECODE_ME_CHECK(b.zero(home)); } else if (s.ranges() == 1) { return ReRange<View,rm>::post(home,x,s.min(),s.max(),b); } else if (b.one()) { if (rm == RM_PMI) return ES_OK; IntSetRanges i_is(s); GECODE_ME_CHECK(x.inter_r(home,i_is,false)); } else if (b.zero()) { if (rm == RM_IMP) return ES_OK; IntSetRanges i_is(s); GECODE_ME_CHECK(x.minus_r(home,i_is,false)); } else { (void) new (home) ReIntSet<View,rm>(home,x,s,b); } return ES_OK; }
forceinline ConstSetView::ConstSetView(Space& home, const IntSet& dom) { size = dom.ranges(); domSize = 0; if (size > 0) { ranges = home.alloc<int>(2*size); IntSetRanges dr(dom); for (int i=0; dr(); ++dr, i+=2) { int min = dr.min(); int max = dr.max(); ranges[i] = min; ranges[i+1] = max; domSize += static_cast<unsigned int>(max-min+1); } } else { ranges = NULL; } }