ranges-operations.hpp /usr/include/gecode/iter.hh Gecode Gecode::Iter Gecode::Iter::Ranges /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2004 * *Lastmodified: *$Date:2010-07-2817:35:33+0200(Wed,28Jul2010)$by$Author:schulte$ *$Revision:11294$ * *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. * */ namespaceGecode{namespaceIter{namespaceRanges{ template<classI> unsignedintsize(I&i); template<classI,classJ> boolequal(I&i,J&j); template<classI,classJ> boolsubset(I&i,J&j); template<classI,classJ> booldisjoint(I&i,J&j); enumCompareStatus{ CS_SUBSET, CS_DISJOINT, CS_NONE }; template<classI,classJ> CompareStatuscompare(I&i,J&j); template<classI> inlineunsignedint size(I&i){ unsignedints=0; while(i()){ s+=i.width();++i; } returns; } template<classI,classJ> forceinlinebool equal(I&i,J&j){ //Areiandjequal? while(i()&&j()) if((i.min()==j.min())&&(i.max()==j.max())){ ++i;++j; }else{ returnfalse; } return!i()&&!j(); } template<classI,classJ> forceinlinebool subset(I&i,J&j){ //Isisubsetofj? while(i()&&j()) if(j.max()<i.min()){ ++j; }elseif((i.min()>=j.min())&&(i.max()<=j.max())){ ++i; }else{ returnfalse; } return!i(); } template<classI,classJ> forceinlinebool disjoint(I&i,J&j){ //Areiandjdisjoint? while(i()&&j()) if(j.max()<i.min()){ ++j; }elseif(i.max()<j.min()){ ++i; }else{ returnfalse; } returntrue; } template<classI,classJ> forceinlineCompareStatus compare(I&i,J&j){ boolsubset=true; booldisjoint=true; while(i()&&j()){ if(j.max()<i.min()){ ++j; }elseif(i.max()<j.min()){ ++i;subset=false; }elseif((i.min()>=j.min())&&(i.max()<=j.max())){ ++i;disjoint=false; }elseif(i.max()<=j.max()){ ++i;disjoint=false;subset=false; }elseif(j.max()<=i.max()){ ++j;disjoint=false;subset=false; } } if(i()) subset=false; if(subset) returnCS_SUBSET; returndisjoint?CS_DISJOINT:CS_NONE; } }}} //STATISTICS:iter-any