dynamic-stack.hpp /usr/include/gecode/support.hh Gecode::Support::DynamicStack Gecode Gecode::Support /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2002 * *Lastmodified: *$Date:2013-07-1112:30:18+0200(Thu,11Jul2013)$by$Author:schulte$ *$Revision:13840$ * *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{namespaceSupport{ template<classT,classA> classDynamicStack{ private: A&a; intlimit; inttos; T*stack; voidresize(void); public: DynamicStack(A&a,intn=64); ~DynamicStack(void); boolempty(void)const; intentries(void)const; Tpop(void); T&top(void)const; T&last(void)const; voidpush(constT&x); T&operator [](inti); constT&operator [](inti)const; private: staticvoid*operatornew(size_ts)throw(){(void)s;returnNULL;} staticvoidoperatordelete(void*p){(void)p;}; DynamicStack(constDynamicStack&s):a(s.a){} constDynamicStack&operator=(constDynamicStack&){return*this;} }; template<classT,classA> void DynamicStack<T,A>::resize(void){ intnl=(limit*3)/2; stack=a.templaterealloc<T>(stack,limit,nl); limit=nl; } template<classT,classA> forceinline DynamicStack<T,A>::DynamicStack(A&a0,intn) :a(a0),limit(n),tos(0),stack(a.templatealloc<T>(n)){} template<classT,classA> forceinline DynamicStack<T,A>::~DynamicStack(void){ a.free(stack,limit); } template<classT,classA> forceinlineT DynamicStack<T,A>::pop(void){ returnstack[--tos]; } template<classT,classA> forceinlineT& DynamicStack<T,A>::top(void)const{ returnstack[tos-1]; } template<classT,classA> forceinlineT& DynamicStack<T,A>::last(void)const{ returnstack[tos]; } template<classT,classA> forceinlinevoid DynamicStack<T,A>::push(constT&x){ stack[tos++]=x; if(tos==limit) resize(); } template<classT,classA> forceinlinebool DynamicStack<T,A>::empty(void)const{ returntos==0; } template<classT,classA> forceinlineint DynamicStack<T,A>::entries(void)const{ returntos; } template<classT,classA> forceinlineT& DynamicStack<T,A>::operator [](inti){ returnstack[i]; } template<classT,classA> forceinlineconstT& DynamicStack<T,A>::operator [](inti)const{ returnstack[i]; } }} //STATISTICS:support-any