/********************************************************************** 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 "bitvec.h" #include "bitvec.h" using namespace std; DEBUG( int nbitvecs=0; ) char* qc_check_txt = "QCLIB: qc_check failed on condition "; char* qc_check_stdmsg = "Can't continue. Provoking segfault to simplify backtracking.\n"; char* qc_check_msg = qc_check_stdmsg; char* qc_delete_txt = "QCLIB: qc_delete warning"; char* qc_delarray_txt = "QCLIB: qc_delarray warning"; char* qc_del_msg = "This should not happen (out of memory?). If the warning is reproducable,\n" "please send a bugreport to Bernhard Oemer .\n"; /* private members */ void bitvec::l_bitvec(word v) { int i,l; l=WORDS(len); pvec=new word[l]; pvec[0]=v; for(i=1;i>LDBPW);k++) v.pvec[k]=l_getword(i+(k<>LDBPW; v.pvec[k]=l_getword(i+(k<>LDBPW; w=(pvec[k]>>j)&MASK(l); if(l+j>BPW) w|=(pvec[k+1]<<(BPW-j))&MASK(l); return w; } void bitvec::l_setbits(int i,int l,word v) { int j,k; j=i&DBITS; k=i>>LDBPW; pvec[k]&=~(MASK(l)<>(BPW-j); } void bitvec::l_setbits(int i,const bitvec& v) { int k; for(k=0;k<(v.len>>LDBPW);k++) l_setbits(i+(k<>LDBPW; l_setbits(i+(k<>LDBPW;k>=0;k--) { if(pvec[k]v.pvec[k]) return 0; }; return 0; } word bitvec::hashfunct() const { int k; word f=len; if(len<=BPW) return vec+(vec>>(BPW/2))+(vec>>(BPW/4))+(vec>>(BPW/8)); for(k=0;k>(BPW/2)); return f; } bitvec& bitvec::qnot() { int k,l; if(len<=BPW) { vec=(~vec) & MASK(len); } else { l=WORDS(len); for(k=0;k=0;i-=4) { c=v.getword(i,(i+4<=v.length()) ? 4 : (v.length()-i)); if(c<=9) s << (char)('0'+c); else s << (char)('a'+c-10); } s << bitvec_hex_postfix; } else { for(i=v.length()-1;i>=0;i--) { s << (v[i] ? '1' : '0'); } } if(bitvec_format&BITVEC_FORMAT_KET) { s << bitvec_ket_postfix; } return s; } istream& operator >> (istream& s,bitvec& v) { int j=0,i=0,h=0,k=0; char *b; char c; if(!(b=new char[v.length()+3])) goto error; do { s >> c; if(!s) goto error; if(c=='|') k=1; } while(c==' ' || c=='\t' || c=='|'); while(1) { b[i++]=c; if(!(h && i<=(v.length()-1)/4) && !(!h && i> c; if(!s) goto error; if(c=='x' && b[i-1]=='0') { h=1; s >> c; i=0; continue; } if(c>='A' && c<='F') c+='a'-'A'; if((h && (c<'0' || c>'9') && (c<'a' || c>'f')) || (!h && c!='0' && c!='1')) goto error; } b[i--]=0; if(k) { s >> c; if(c!='>') goto error; } v=0; if(h) { for(j=0;i>=0 && j='0' && b[i]<='9' ? b[i]-'0' : b[i]-'a'+10)); } else { for(j=0;i>=0 && j