bitset-offset.hpp climits cmath iostream /usr/include/gecode/support.hh Gecode::Support::BitSetOffset Gecode Gecode::Support /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristopherMears<chris.mears@monash.edu> * *Contributingauthors: *MikaelLagerkvist<lagerkvist@gecode.org> *ChristianSchulte<schulte@gecode.org> * *Copyright: *MikaelLagerkvist,2007 *ChristopherMears,2012 *ChristianSchulte,2007 * *Lastmodified: *$Date:2013-03-0717:39:13+0100(Thu,07Mar2013)$by$Author:schulte$ *$Revision:13458$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ #include<climits> #include<cmath> #include<iostream> namespaceGecode{namespaceSupport{ template<classA> classBitSetOffset:publicBitSetBase{ protected: A&a; int_offset; public: BitSetOffset(A&a,unsignedints,into); BitSetOffset(A&a,constBitSetOffset&bs); ~BitSetOffset(void); //Asfortheordinarybitset,mostoperationscanbeinherited //directlyfromBitSetBase.Weonlymodifytheoperationsthat //involveindicesortheoffsetitself. boolget(inti)const; voidset(inti); voidclear(inti); intnext(inti)const; voidresize(A&a,unsignedintn,intoffset,boolset=false); intoffset(void)const; intmax_bit(void)const; boolvalid(inti)const; }; template<classA> forceinline BitSetOffset<A>::BitSetOffset(A&a0,unsignedints,into) :BitSetBase(a0,s),a(a0),_offset(o){} template<classA> forceinline BitSetOffset<A>::BitSetOffset(A&a0,constBitSetOffset<A>&bs) :BitSetBase(a0,bs),a(a0),_offset(bs._offset){} template<classA> forceinline BitSetOffset<A>::~BitSetOffset(void){ dispose(a); } template<classA> forceinlinebool BitSetOffset<A>::get(inti)const{returnBitSetBase::get(i-_offset);} template<classA> forceinlinevoid BitSetOffset<A>::set(inti){BitSetBase::set(i-_offset);} template<classA> forceinlinevoid BitSetOffset<A>::clear(inti){BitSetBase::clear(i-_offset);} template<classA> forceinlineint BitSetOffset<A>::next(inti)const{return_offset+BitSetBase::next(i-_offset);} template<classA> void BitSetOffset<A>::resize(A&a,unsignedintn,intoffset,boolset){ BitSetBase::resize(a,n,set); _offset=offset; } template<classA> forceinlineint BitSetOffset<A>::offset(void)const{return_offset;} template<classA> forceinlineint BitSetOffset<A>::max_bit(void)const{return_offset+size()-1;} template<classA> forceinlinebool BitSetOffset<A>::valid(inti)const{return_offset<=i&&i<=_offset+(int)size()-1;} template<classA,classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constBitSetOffset<A>&bs){ for(inti=bs.offset();i<bs.offset()+static_cast<int>(bs.size());i++) if(bs.get(i)) os<<i<<""; returnos; } }} //STATISTICS:support-any