/********************************************************************** This file is part of the Quantum Computation Library (QCLIB). (c) Copyright by Bernhard Oemer , 1996-1998 This program comes without any warranty; without even the implied warranty of merchantability or fitness for any particular purpose. This program is free software under the terms of the GNU General Public Licence (GPL) version 2 or higher ************************************************************************/ #pragma implementation "terms.h" #include "terms.h" #include using namespace std; #define NONE (-1) DEBUG( int nterms=0; ) DEBUG( int ntermlists=0; ) DEBUG( int nprobtrees=0; ) /* member functions */ // class termlist: termlist::termlist(int bits,int len) { _nbits=bits; listlen=len; hashlen=1<=listlen) { pt=list; n=_nterms; listlen*=2; hashlen*=2; hashmask=hashlen-1; qc_delarray(hash); newlist(); clear(); for(i=0;ivect()==v) { pt->setampl(pt->ampl()+z); return; }; h+=hashfunct2(v); h&=hashmask; }; } /* other functions */ int duallog(int k) { int i=0; for(;k!=0;k>>=1) i++; return i; } ostream& operator << (ostream& s,const term& t) { complx z=t.ampl(); //s.form("%+19.17f\t%+19.17f\t",z.real(),z.imag()); s << setw(19) << setprecision(17) << z.real() << '\t'; s << setw(19) << setprecision(17) << z.imag() << '\t'; s << t.vect(); return s; } istream& operator >> (istream& s,term& t) { bitvec v(t.nbits()); double x=10,y=10; //s.scan("%lf %lf",&x,&y); s >> x >> y; if(x>1 || x<-1 || y>1 || y<-1) goto error; s >> v; t.setvect(v); t.setampl(complx(x,y)); return s; error: t.setvect(bitvec()); return s; }