sospin is hosted by Hepforge, IPPP Durham
SOSpin  1.0.0
dlist.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // SOSpin Library
3 // Copyright (C) 2015 SOSpin Project
4 //
5 // Authors:
6 //
7 // Nuno Cardoso (nuno.cardoso@tecnico.ulisboa.pt)
8 // David Emmanuel-Costa (david.costa@tecnico.ulisboa.pt)
9 // Nuno Gonçalves (nunogon@deec.uc.pt)
10 // Catarina Simoes (csimoes@ulg.ac.be)
11 //
12 // ----------------------------------------------------------------------------
13 // This file is part of SOSpin Library.
14 //
15 // SOSpin Library is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or any
18 // later version.
19 //
20 // SOSpin Library is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with SOSpin Library. If not, see <http://www.gnu.org/licenses/>.
27 // ----------------------------------------------------------------------------
28 
29 // dllist.cpp created on 27/02/2015
30 //
31 // This file contains the functions necessary to do things
32 // in the SOSpin Library.
33 //
34 // Revision 1.1 28/02/2015 23:19:29 david
35 // Revision 1.2 26/05/2015 09:02:00 nunogon
36 // License updated
37 //
38 
45 #include "dlist.h"
46 #include "son.h"
47 #include "index.h"
48 
49 namespace sospin {
50 
52  DList::DList(void){
53  begin = 0;
54  end = 0;
55  actual = 0;
56  sign=1;
57  }
58 
64  DList::DList(int tp, int i){
65  begin=new noList();
67  begin->prv=0;
68  begin->nxt=0;
69  actual = begin;
70  end = begin;
71  sign=1;
72  }
73 
79  DList::DList(int tp, int i, int j){
80  begin=new noList();
81  begin->data=elemType::make_elem(tp, i, j);
82  begin->prv=0;
83  begin->nxt=0;
84  actual = begin;
85  end = begin;
86  sign=1;
87  }
88 
90  DList::DList(const DList &L) {
91  begin = 0;
92  end = 0;
93  actual = 0;
94  sign=1;
95  if(!L.begin) return;
96  this->sign = L.sign;
97  noList *q, *p, *k;
98  q = L.begin;
99  if (q != 0) {
100  p = new noList();
101  p->data = (q->data);
102  p->prv = 0;
103  p->nxt = 0;
104  this->begin = p;
105  this->end = p;
106  k = begin;
107  q = q->nxt;
108  while (q != 0) {
109  p = new noList();
110  p->data = (q->data);
111  p->prv = k;
112  p->nxt = 0;
113  k->nxt = p;
114  this->end = p;
115  q = q->nxt;
116  k = k->nxt;
117  }
118  this->actual = p;
119  }
120  }
121 
124  clear();
125  }
126 
127 
128  //Changing, writing and updating
129 
131  void DList::clear(){
132  if(begin){
133  noList *seg;
134  actual = begin;
135  seg = actual->nxt;
136  while(seg !=0){
137  delete(actual);
138  actual = seg;
139  seg = seg->nxt;
140  }
141  delete(actual);
142  }
143  actual=0;
144  begin=0;
145  end=0;
146  sign=1;
147  }
148 
149 
154  void DList::add(elemType elem){
155  noList *q,*p;
156  if(!begin){
157  begin=new noList();
158  begin->data = elem;
159  begin->prv=0;
160  begin->nxt=0;
161  actual = begin;
162  end = begin;
163  }
164  else{
165  q=begin;
166  while(q->nxt!=0) q=q->nxt;
167  p=new noList();
168  p->data = elem;
169  p->prv=q;
170  p->nxt=0;
171  q->nxt=p;
172  actual = p;
173  end = p;
174  }
175  }
176 
182  noList *q,*p;
183  if(begin == 0){
184  begin=new noList();
185  begin->data=elem;
186  begin->prv=0;
187  begin->nxt=0;
188  actual = begin;
189  end = begin;
190  }
191  else{
192  p=new noList();
193  p->data=elem;
194  p->prv=0;
195  p->nxt=begin;
196  begin->prv = p;
197  begin = p;
198  actual = p;
199  }
200  }
201 
207  noList *q,*p;
208  if(!begin){
209  begin=new noList();
210  begin->data=elem;
211  begin->prv=0;
212  begin->nxt=0;
213  actual = begin;
214  end = begin;
215  }
216  else{
217  p=new noList();
218  p->data=elem;
219  p->prv=end;
220  p->nxt=0;
221  end->nxt=p;
222  end = p;
223  actual = p;
224  }
225  }
226 
227 
232  void DList::join(DList& L){
233 
234  noList *k,*p,*q;
235  q=L.begin;
236  k=begin;
237  if(!begin){
238  p=new noList();
239  p->data=(q->data);
240  p->prv=0;
241  p->nxt=0;
242  begin=p;
243  end = k;
244  k=begin;
245  q = q->nxt;
246  }
247  else while(k->nxt!=0) k = k->nxt;
248  while(q!=0){
249  p=new noList();
250  p->data=(q->data);
251  p->prv=k;
252  p->nxt=0;
253  k->nxt=p;
254  end = k;
255  q = q->nxt;
256  k = k->nxt;
257  }
258  actual = end;
259  }
260 
261 
264  DList M;
265  M.sign = sign;
266  noList *q;
267  q=begin;
268  if(q!=0){
269  if(q->nxt==0) M.add_end(q->data);
270  else{
271  while(q!=0){
272  if(q->data.getType()==2) M.add_end(q->data);
273  q=q->nxt;
274  }
275  q=begin;
276  while(q!=0){
277  if(q->data.getType()==0 || q->data.getType()==1 ) M.add_end(q->data);
278  q=q->nxt;
279  }
280  }
281  }
282  return M;
283  }
284 
286  void DList::remove(unsigned int type){
287  actual = begin;
288  noList *next;
289  noList *prv;
290  if(begin){
291  prv=0;
292  while(actual!=0){
293  if(actual->data.getType()==type){
294  if(prv==0) begin=actual->nxt;
295  else prv->nxt=actual->nxt;
296  if(actual->nxt == 0) end = prv;
297  else{
298  next = actual->nxt;
299  next-> prv = actual->prv;
300  }
301  delete(actual);
302  actual = begin;
303  return;
304  }
305  prv=actual;
306  actual=actual->nxt;
307  }
308  }
309  actual=begin;
310  }
311 
314  noList *next;
315  noList *prv;
316  if(begin)
317  if(actual!=0){
318  prv=0;
319  if(actual->prv==0) begin=actual->nxt;
320  else{
321  prv = actual -> prv;
322  prv->nxt=actual->nxt;
323  }
324  if(actual->nxt == 0) end = prv;
325  else{
326  next = actual->nxt;
327  next-> prv = actual->prv;
328  }
329  delete(actual);
330  //length--;
331  //if(beg==end) empty = true;
332  actual = begin;
333  return;
334  }
335  }
336 
339  if(!actual || (actual->nxt) == 0) cout << "swap empty list or end of list" << endl;
340  else{
341  noList *before, *after, *after2;
342  after2=0;
343  before = actual-> prv;
344  after = actual-> nxt;
345  if(after->nxt != 0) after2 = after->nxt;
346  else end = actual;
347  if(before!=0) before->nxt = after;
348  else begin=after;
349  actual -> nxt = after2;
350  if(after2!=0) after2 -> prv = actual;
351  after-> prv = before;
352  actual-> prv = after;
353  after -> nxt = actual;
354  }
355  }
356 
357 
358  //Reading and accessing data
359 
361  vector<int> DList::getIds(){
362  vector<int> ids;
363  if(begin!=0){
364  noList *q;
365  q=begin;
366  while(q!=0) {
367  switch(q->data.getType()){
368  case 0:
369  ids.push_back(0);
370  break;
371  case 1:
372  ids.push_back(1);
373  break;
374  }
375  q=q->nxt;
376  }
377  }
378  return ids;
379  }
380 
382  void DList::getBandBdaggerIds(bool &BandBdagger, vector<string> &id0, vector<string> &id1, int &sign){
383  BandBdagger = false;
384  if(begin!=0){
385  noList *q;
386  q=begin;
387  sign = getSign();
388  while(q!=0) {
389  switch(q->data.getType()){
390  case 0:
391  id0.push_back(getIdx(q->data.getIdx1()));
392  BandBdagger = true;
393  break;
394  case 1:
395  id1.push_back(getIdx(q->data.getIdx1()));
396  BandBdagger = true;
397  break;
398  }
399  q=q->nxt;
400  }
401  }
402  }
403 
405  void DList::getDeltaIds(bool &AllDeltas, vector<string> &id0, vector<string> &id1, int &sign){
406  bool expwithAllDelta = false;
407  if(begin!=0){
408  noList *q;
409  q=begin;
410  sign = getSign();
411  bool alldeltas = true;
412  while(q!=0) {
413  switch(q->data.getType()){
414  case 0:
415  alldeltas = false;
416  break;
417  case 1:
418  alldeltas = false;
419  break;
420  case 2:
421  id0.push_back(getIdx(q->data.getIdx1()));
422  id1.push_back(getIdx(q->data.getIdx2()));
423  break;
424  case 3:
425  alldeltas = false;
426  break;
427  }
428  if(alldeltas == false) break;
429  q=q->nxt;
430  }
431  if(alldeltas) expwithAllDelta = true;
432  }
433  AllDeltas = expwithAllDelta;
434  }
435 
437  void DList::getBandBdaggerAndDeltasIds(vector<string> &id0, vector<string> &id1, \
438  vector<string> &id2, vector<string> &id3,int &sign){
439  if(begin!=0){
440  noList *q;
441  q=begin;
442  sign = getSign();
443  while(q!=0) {
444  switch(q->data.getType()){
445  case 0:
446  id0.push_back(getIdx(q->data.getIdx1()));
447  break;
448  case 1:
449  id1.push_back(getIdx(q->data.getIdx1()));
450  break;
451  case 2:
452  id2.push_back(getIdx(q->data.getIdx1()));
453  id3.push_back(getIdx(q->data.getIdx2()));
454  break;
455  }
456  q=q->nxt;
457  }
458  }
459  }
460 
463  if(begin==0) return 0;
464  else{
465  noList *q;
466  q=begin;
467  int alldeltas = 0;
468  while(q!=0) {
469  if(q->data.getType() == 2){
470  alldeltas++;
471  }
472  q=q->nxt;
473  }
474  return alldeltas;
475  }
476  }
477 
480  if(begin==0) return 0;
481  else{
482  noList *q;
483  q=begin;
484  int numbs = 0;
485  while(q!=0) {
486  if(q->data.getType() == 0){
487  numbs++;
488  }
489  q=q->nxt;
490  }
491  return numbs;
492  }
493  }
494 
499  bool DList::search_last(unsigned int type){
500  if(!begin) return false;
501  actual=end;
502  while(actual!=0) {
503  if(actual->data.getType()==type) break;
504  actual=actual->prv;
505  }
506  if(actual == end) return false;
507  return true;
508  }
509 
515  bool DList::search_first(unsigned int type1){
516  if(!begin) return false;
517  actual=begin;
518  while(actual!=0) {
519  if(actual->data.getType()==type1) break;
520  actual=actual->nxt;
521  }
522  if(actual == begin) return false;
523  return true;
524  }
525 
531  //NG: devia alterar-se o nome da funcao.
532  bool DList::search_first(unsigned int type0, unsigned int type1){
533  if(!begin) return false;
534  actual=begin;
535  bool opb = false;
536  bool elem = true;
537  while(actual!=0) {
538  if(actual->data.getType()==type0){
539  elem = false;
540  break;
541  }
542  else if(actual->data.getType()==type1) opb = true;
543  actual=actual->nxt;
544  }
545  if(opb) elem = true;
546  return elem;
547  }
548 
553  bool DList::search_elem(unsigned int type1){
554  if(!begin) return false;
555  actual=begin;
556  while(actual!=0) {
557  if(actual->data.getType()==type1) break;
558  actual=actual->nxt;
559  }
560  if(actual == 0) return false;
561  return true;
562  }
563 
564 
565  //Querying and booleans
566 
570  bool DList::check(){
571  if(!begin) return false;
572  else{
573  actual=begin;
574  int zero = 0;
575  int um = 0;
576  while(actual!=0) {
577  if(actual->data.getType()==0) zero++;
578  if(actual->data.getType()==1) um++;
579  actual=actual->nxt;
580  }
581  if(um == zero && um <=getDim() / 2 && zero <= getDim() / 2) return true;
582  return false;
583  }
584  }
585 
589  //NG: rever esta função. Parece-me que pode estar errada.
591  if(!begin) return false;
592  actual=begin;
593  bool elem = true;
594  int nson = getDim() / 2;
595  while(actual!=0) {
596  if(actual->data.getType()==2){
597  string id0 = getIdx(actual->data.getIdx1());
598  string id1 = getIdx(actual->data.getIdx2());
599  if( id0 == id1){
600  if(atoi(id0.c_str()) <= nson )
601  if(atoi(id0.c_str()) > 0 )
602  if(atoi(id1.c_str()) <= nson )
603  if(atoi(id1.c_str()) > 0 )
604  if(atoi(id0.c_str()) != atoi(id1.c_str())){
605  break;
606  }
607  }
608  else{
609  if(atoi(id0.c_str()) <= nson )
610  if(atoi(id0.c_str()) > 0 )
611  if(atoi(id1.c_str()) <= nson )
612  if(atoi(id1.c_str()) > 0 )
613  if(atoi(id0.c_str()) != atoi(id1.c_str())){
614  elem = false;
615  break;
616  }
617  }
618  if(atoi(id0.c_str()) > nson || atoi(id1.c_str()) > nson ){
619  elem = false;
620  break;
621  }
622  }
623  actual=actual->nxt;
624  }
625 
626  return elem;
627  }
628 
629 
632  if(!begin) return false;
633  else{
634  actual=begin;
635  int zero = 0;
636  int um = 0;
637  while(actual!=0) {
638  if(actual->data.getType()==0) zero++;
639  if(actual->data.getType()==1) um++;
640  actual=actual->nxt;
641  }
642  if(um <=getDim() / 2 && zero <= getDim() / 2) return true;
643  return false;
644  }
645  }
646 
649  if(!begin) return false;
650  else{
651  actual=begin;
652  int zero = 0;
653  int um = 0;
654  while(actual!=0) {
655  if(actual->data.getType()==0) zero++;
656  if(actual->data.getType()==1) um++;
657  actual=actual->nxt;
658  }
659  if(um == zero ) return true;
660  return false;
661  }
662  }
663 
664 
667  if(begin==0) return true;
668  else{
669  noList *q;
670  q=begin;
671  bool nodeltas = true;
672  while(q!=0) {
673  if(q->data.getType() == 2){
674  nodeltas = false;
675  break;
676  }
677  if(nodeltas == false) break;
678  q=q->nxt;
679  }
680  return nodeltas;
681  }
682  }
683 
686  if(begin==0) return false;
687  else{
688  noList *q;
689  q=begin;
690  bool alldeltas = true;
691  while(q!=0) {
692  if(q->data.getType() != 2){
693  alldeltas = false;
694  break;
695  }
696  q=q->nxt;
697  }
698  return alldeltas;
699  }
700  }
701 
704  vector<string> id0;
705  bool repid = false;
706  if(begin!=0){
707  noList *q;
708  q=begin;
709  while(q!=0) {
710  switch(q->data.getType()){
711  case 0:
712  id0.push_back(getIdx(q->data.getIdx1()));
713  break;
714  case 1:
715  id0.push_back(getIdx(q->data.getIdx1()));
716  break;
717  case 2:
718  id0.push_back(getIdx(q->data.getIdx1()));
719  id0.push_back(getIdx(q->data.getIdx2()));
720  break;
721  }
722  q=q->nxt;
723  }
724  int size = id0.size();
725  sort (id0.begin(), id0.end());
726  vector<string>::iterator it;
727  it = unique (id0.begin(), id0.end());
728  id0.resize( it - id0.begin() );
729  if(size!=id0.size())
730  repid = true;
731  }
732  return repid;
733  }
734 
735 
736 
737  //Operators
738 
741  if(!L.begin) return *this;
742  sign = L.sign;
743  noList *q,*p, *k;
744  q=L.begin;
745  if(q!=0){
746  p=new noList();
747  p->data=(q->data);
748  p->prv=0;
749  p->nxt=0;
750  begin=p;
751  end = p;
752  k=begin;
753  q = q->nxt;
754  while(q!=0){
755  p=new noList();
756  p->data=(q->data);
757  p->prv=k;
758  p->nxt=0;
759  k->nxt=p;
760  end = p;
761  q = q->nxt;
762  k = k->nxt;
763  }
764  actual = p;
765  }
766  return *this;
767  }
768 
769 
771  const DList DList::operator-()const{
772  DList L;
773  L.sign = -1 * sign;
774  noList *q,*p, *k;
775  q=begin;
776  k=L.begin;
777  if(q!=0){
778  p=new noList();
779  p->data=(q->data);
780  p->prv=0;
781  p->nxt=0;
782  L.begin=p;
783  L.end = p;
784  k=L.begin;
785  q = q->nxt;
786  while(q!=0){
787  p=new noList();
788  p->data=(q->data);
789  p->prv=k;
790  p->nxt=0;
791  k->nxt=p;
792  L.end = p;
793  q = q->nxt;
794  k = k->nxt;
795  }
796  L.actual = L.end;
797  }
798  return L;
799  }
800 
801 
802 
803  //Friends
804 
806  DList* copy( DList *L){
807  DList *M = 0;
808  noList *q,*p, *k;
809  q=L->begin;
810  if(q!=0){
811  M =new DList();
812  M->sign = L->sign;
813  p=new noList();
814  p->data=(q->data);
815  p->prv=0;
816  p->nxt=0;
817  M->begin=p;
818  M->end = p;
819  k=M->begin;
820  q = q->nxt;
821  while(q!=0){
822  p=new noList();
823  p->data=(q->data);
824  p->prv=k;
825  p->nxt=0;
826  k->nxt=p;
827  M->end = p;
828  q = q->nxt;
829  k = k->nxt;
830  }
831  M->actual = p;
832  }
833  return M;
834  }
835 
845  DList contract_deltas(DList &L, bool braketmode){
846  DList M;
847 
848  if(L.isEmpty()) return M;
849  noList *k,*p,*q;
850  q=L.begin;
851  elemType bb;
852  elemType bdag;
853 
854  if(L.begin==0) return M;
855 
856  L.search_last(0);
857  if(L.actual == L.end){
858  if(braketmode) L.clear();
859  return M;
860  }
861  if(L.actual == 0) return M;
862  M << L;
863  M.set_sign(-1*L.getSign());
864  M.search_last(0);
865  noList *elem = M.actual;
866  bb=elem->data;
867  bdag=elem->nxt->data;
868  if(bb.getType() != 0 || bdag.getType() !=1){
869  DList A;
870  return A;
871  }
872  elemType delta;
873  delta.setType(2);
874  delta.setIdx1(bb.getIdx1());
875  delta.setIdx2(bdag.getIdx1());
876  L.add_begin(delta);
877  L.search_last(0);
878 
879  noList *elem1 = L.actual;
880  noList *before, *after, *after2;
881  after2=0;
882  before=elem1->prv;
883  L.actual = L.actual->prv;
884  after=elem1->nxt;
885  L.actual = after;
886  if(after!=0) after2 = after->nxt;
887  L.actual = after2;
888  if(before!=0) before->nxt = after2;
889  else L.begin = 0;
890  L.actual = L.begin;
891  if(after2!=0) after2->prv = before;
892  if(after2==0) L.end = before;
893  delete elem1;
894  if(after!=0) delete after;
895 
896  M.search_last(0);
897  M.swap_next();
898  return M;
899  }
900 
911  DList ordering(DList &L, bool braketmode){
912  DList M;
913 
914  if(L.isEmpty()) return M;
915  noList *k,*p,*q;
916  q=L.begin;
917  elemType bb;
918  elemType bdag;
919 
920  if(L.begin==0) return M;
921 
922  L.search_first(1);
923  if(L.actual == L.begin){
924  if(braketmode) L.clear();
925  return M;
926  }
927  if(L.actual == 0) return M;
928  M << L;
929  M.set_sign(-1*L.getSign());
930  M.search_first(1);
931  L.search_first(1);
932  noList *elemM = M.actual;
933  noList *elemL = L.actual;
934  bdag=elemM->data;
935  bb =elemM->nxt->data;
936  while(true){
937  if(bb.getType() == 0 && bdag.getType() ==1) break;
938  elemM = elemM->nxt;
939  elemL = elemL->nxt;
940  bdag=elemM->data;
941  bb =elemM->nxt->data;
942  }
943  M.actual = elemM;
944  L.actual = elemL;
945  elemType delta;
946  delta.setType(2);
947  delta.setIdx1(bb.getIdx1());
948  delta.setIdx2(bdag.getIdx1());
949 
950 
951  noList *elem1 = L.actual;
952  noList *before, *after, *after2;
953  after2=0;
954  before=elem1->prv;
955  L.actual = L.actual->prv;
956  after=elem1->nxt;
957  L.actual = after;
958  if(after!=0) after2 = after->nxt;
959  L.actual = after2;
960  if(before!=0) before->nxt = after2;
961  else L.begin = 0;
962  L.actual = L.begin;
963  if(after2!=0) after2->prv = before;
964  if(after2==0) L.end = before;
965  delete elem1;
966  if(after!=0) delete after;
967  L.add_begin(delta);
968 
969  M.swap_next();
970  return M;
971  }
972 
973  //NG: o "*" deveria ser colocado tb para type=3, não?
975  string printDeltas(DList &L){
976  string deltas = "";
977  if(!L.begin) return deltas;
978  noList *q;
979  q=L.begin;
980 
981  while(q!=0) {
982  if(q->data.getType() == 2)
983  deltas += "d_(" + getIdx(q->data.getIdx1()) + "," + getIdx(q->data.getIdx2()) + ")";
984  if(q->data.getType() == 3)
985  deltas += "1";
986  q=q->nxt;
987  if(q!=0) if(q->data.getType() == 2 ) deltas += "*";
988  }
989  return deltas;
990  }
991 
992 
993  // Friends - Operators
994 
997  L.add_end(j);
998  return L;
999  }
1000 
1002  DList operator*(const DList &O, const DList &P){
1003  DList L;
1004  L.sign = O.sign * P.sign;
1005  noList *q,*p, *k;
1006  q=O.begin;
1007  k=L.begin;
1008  if(q!=0){
1009  p=new noList();
1010  p->data=(q->data);
1011  p->prv=0;
1012  p->nxt=0;
1013  L.begin=p;
1014  k=L.begin;
1015  L.end = p;
1016  q = q->nxt;
1017  while(q!=0){
1018  p=new noList();
1019  p->data=(q->data);
1020  p->prv=k;
1021  p->nxt=0;
1022  k->nxt=p;
1023  L.end = p;
1024  q = q->nxt;
1025  k = k->nxt;
1026  }
1027  }
1028  q=P.begin;
1029  while(q!=0 ){
1030  if( (O.begin != 0 || q->nxt != 0) && q->data.getType() == 3){
1031  q = q->nxt;
1032  continue;
1033  }
1034  p=new noList();
1035  p->data=(q->data);
1036  p->prv=k;
1037  p->nxt=0;
1038  k->nxt=p;
1039  L.end = p;
1040  q = q->nxt;
1041  k = k->nxt;
1042  }
1043  L.actual = L.end;
1044  return L;
1045  }
1046 
1049  L.set_sign(-1 * L.getSign());
1050  L.add_end(j);
1051  return L;
1052  }
1053 
1056  L.add_end(j);
1057  return L;
1058  }
1059 
1069  ostream& operator<<(ostream& out, DList &L){
1070  if(!L.begin) return out << " ";
1071  noList *q;
1072  q=L.begin;
1073  if(q!=0){
1074  out << "\t";
1075  if(L.getSign() == -1) out << " - ";
1076  if(L.getSign() == 1) out << " + ";
1077  }
1078  while(q!=0) {
1079  if(q->data.getType() == 2)
1080  out << "d(" << getIdx(q->data.getIdx1()) << "," << getIdx(q->data.getIdx2()) << ")";
1081  if(q->data.getType() == 0)
1082  out << "b(" << getIdx(q->data.getIdx1()) << ")";
1083  if(q->data.getType() == 1)
1084  out << "bt(" << getIdx(q->data.getIdx1()) << ")";
1085  if(q->data.getType() == 3)
1086  out << "1";
1087  if( q == L.actual) out << "@";
1088  if(q->nxt!=0) out << " * ";
1089  q=q->nxt;
1090  }
1091  return out << " ";
1092  }
1093 
1095  ostream& operator<<(ostream& out, DList *L){
1096  if(!L) return out << " ";
1097  if(!L->begin) return out << " ";
1098  noList *q;
1099  q=L->begin;
1100  if(q!=0){
1101  out << "\t";
1102  if(L->getSign() == -1) out << " - ";
1103  if(L->getSign() == 1) out << " + ";
1104  }
1105  while(q!=0) {
1106  if(q->data.getType() == 2)
1107  out << "d(" << getIdx(q->data.getIdx1()) << "," << getIdx(q->data.getIdx2()) << ")";
1108  if(q->data.getType() == 0)
1109  out << "b(" << getIdx(q->data.getIdx1()) << ")";
1110  if(q->data.getType() == 1)
1111  out << "bt(" << getIdx(q->data.getIdx1()) << ")";
1112  if(q->data.getType() == 3)
1113  out << "1";
1114  if( q == L->actual) out << "@";
1115  if(q->nxt!=0) out << " * ";
1116  q=q->nxt;
1117  }
1118  return out << " ";
1119  }
1120 
1121  //same as operator* and operator,
1124  L.add_end(j);
1125  return L;
1126  }
1127 
1139  if(!M.begin) return L;
1140  L.set_sign(L.getSign()*M.getSign());
1141  noList *q,*p, *k;
1142  q=M.begin;
1143  k=L.begin;
1144  if(!L.begin){
1145  p=new noList();
1146  p->data=(q->data);
1147  p->prv=0;
1148  p->nxt=0;
1149  L.begin=p;
1150  k=L.begin;
1151  q = q->nxt;
1152  L.end = p;
1153  }
1154  else while(k->nxt!=0) k = k->nxt;
1155  while(q!=0){
1156  p=new noList();
1157  p->data=(q->data);
1158  p->prv=k;
1159  p->nxt=0;
1160  k->nxt=p;
1161  L.end = p;
1162  q = q->nxt;
1163  k = k->nxt;
1164  }
1165  L.actual = L.end;
1166  return L;
1167  }
1168 
1170  bool operator==(DList &L, DList &M){
1171  if(!M.begin && !L.begin) return true;
1172  if(L.getSign() != M.getSign()) return false;
1173 
1174  noList *q,*p, *k;
1175  elemType data0, data1;
1176  q=M.begin;
1177  k=L.begin;
1178  while(true){
1179  data0 = q->data;
1180  data1 = k->data;
1181  if(data0.getType() != data1.getType()){
1182  return false;
1183  }
1184  if(getIdx(data0.getIdx1()) != getIdx(data1.getIdx1())){
1185  return false;
1186  }
1187  if(getIdx(data0.getIdx2()) != getIdx(data1.getIdx2())){
1188  return false;
1189  }
1190  if(k->nxt !=0 && q->nxt !=0){
1191  k=k->nxt;
1192  q=q->nxt;
1193  }
1194  else{
1195  if((k->nxt !=0) != (q->nxt !=0)){
1196  return false;
1197  }
1198  break;
1199  }
1200  }
1201  return true;
1202  }
1203 
1204 }
unsigned int getType()
Returns the type of the element. Ex.: $b$ - type=0; $b^{}$ - type=1; $$ - type=2; constant - type=3...
Definition: dlist.h:111
void swap_next()
Swaps the actual node with the next node of DList.
Definition: dlist.cpp:338
bool checkDeltaIndex()
Checks the indexes of $$ elements. They must be less or equal to the n of SO(2n). Checks also if the ...
Definition: dlist.cpp:590
void getBandBdaggerAndDeltasIds(vector< string > &id0, vector< string > &id1, vector< string > &id2, vector< string > &id3, int &sign)
Updates integer vector sequence containers "id0" and "id1" with ids (data fields) of $b$'s and $b^$'s...
Definition: dlist.cpp:437
OPMode operator-(const OPMode a, const OPMode b)
calculate the mode for the subtraction
Definition: braket.cpp:291
int getDim()
Get the group dimension.
Definition: son.cpp:64
void getBandBdaggerIds(bool &BandBdagger, vector< string > &id0, vector< string > &id1, int &sign)
Updates integer vector sequence containers "id0" and "id1" with ids (data fields) of $b$'s and $b^$'s...
Definition: dlist.cpp:382
void add(elemType)
Adds one node at the end of DList (scans the list). Updates actual pointer to be the last node...
Definition: dlist.cpp:154
Functions and cointainer for indices.
bool search_elem(unsigned int type1)
Searches for the element with "data.get\_type()==type" found in DList. Returns true if the element is...
Definition: dlist.cpp:553
OPMode operator*(const OPMode a, const OPMode b)
calculate the mode for the multiplication
Definition: braket.cpp:317
noList * begin
Pointer to the first node.
Definition: dlist.h:266
int sign
Store the sign of the monomial.
Definition: dlist.h:272
DList & operator,(DList &L, elemType j)
Adds element "j" to the end of DList. Returns pointer to DList.
Definition: dlist.cpp:1055
bool check_num()
Verifies if the number of $b$'s and $b^$'s is less or equal than N of SO(2N). Returns true if so...
Definition: dlist.cpp:631
unsigned int getIdx2()
Returns the second data field of the element (id.y).
Definition: dlist.h:134
noList * actual
Pointer to the actual node.
Definition: dlist.h:270
void set_sign(int ii)
Sets the sign of DList.
Definition: dlist.h:331
DList * copy(DList *L)
Creates and returns a pointer to a new copy of a DList.
Definition: dlist.cpp:806
void clear()
Deletes all nodes from DList.
Definition: dlist.cpp:131
void remove(unsigned int type)
Removes the first element with "data.get\_type()==type" found in DList. Updates actual pointer to be ...
Definition: dlist.cpp:286
DList rearrange()
Creates and returns a new DList by copying nodes in DList ordered by type. The nodes that first appea...
Definition: dlist.cpp:263
Defintions for all general (initialisation etc.) routines of class DList.
bool isEmpty()
Returns true if DList has no nodes.
Definition: dlist.h:440
bool check_same_num()
Verifies if the number of $b$'s and $b^$'s match. Returns true if they match, false otherwise...
Definition: dlist.cpp:648
void setType(unsigned int typ)
Sets the type of the element.
Definition: dlist.h:173
int numDeltas()
Returns the number of elements of type $$ (type=2).
Definition: dlist.cpp:462
void setIdx1(unsigned int idx)
Sets first data field of the element (idx1).
Definition: dlist.h:203
DList ordering(DList &L, bool braketmode)
Order only the b's (to the left hand side) and b's (to the right hand side) terms. Applies the following identity: input DList L keeps delta term and function returns the swapped term.
Definition: dlist.cpp:911
void add_end(elemType)
Adds one node in the end of DList. Updates actual pointer to be the last node.
Definition: dlist.cpp:206
string getIdx(int i)
Get index.
Definition: index.cpp:142
string printDeltas(DList &L)
Creates and returns a string with the deltas and constants of a DList.
Definition: dlist.cpp:975
void remove_actual()
Removes the element for which the actual pointer, "actual", is pointing at in DList.
Definition: dlist.cpp:313
DList with nodes.
Definition: dlist.h:264
noList * prv
Pointer to the previous (prv) node.
Definition: dlist.h:255
DList contract_deltas(DList &L, bool braketmode)
Applies the following identity: input DList L keeps delta term and function returns the swapped term...
Definition: dlist.cpp:845
int numBs()
Returns the number of elements of type b (type=0).
Definition: dlist.cpp:479
vector< int > getIds()
Creates and returns an integer vector sequence container with the ids (data fields) of $b$'s and $b^$...
Definition: dlist.cpp:361
Main Sospin header file. Includes C++ macros, to simplify expression writing, B operator, Verbosity level and memory usage.
noList * nxt
Pointer to the next (nxt) node.
Definition: dlist.h:257
bool operator==(DList &L, DList &M)
Returns true if two DLists are equal.
Definition: dlist.cpp:1170
bool hasOnlyDeltas()
Returns true if all nodes in DList are of $$ type.
Definition: dlist.cpp:685
int getSign()
Returns the sign of DList.
Definition: dlist.h:384
ostream & operator<<(ostream &out, const OPMode &a)
Get the mode of the expression.
Definition: braket.cpp:266
DList & operator=(const DList &L)
Copies a DList.
Definition: dlist.cpp:740
\delta element
Definition: dlist.h:72
DList(void)
Default constructor.
Definition: dlist.cpp:52
elemType data
Store symbol type.
Definition: dlist.h:253
bool hasRepeatedIndex()
Returns true if there is elements with the same id (data fields) in the DList (repeated ids)...
Definition: dlist.cpp:703
bool search_last(unsigned int type1)
Search the last element with "data.get\_type()==type1" found in DList. Returns true a node was found...
Definition: dlist.cpp:499
void setIdx2(unsigned int idx)
Sets second data field of the element (idx2).
Definition: dlist.h:220
static elemType make_elem(int type, int data)
Creates and return an element of type "type" and one data field "data". Second data field is set to z...
Definition: dlist.h:142
void add_begin(elemType)
Adds one node in the beginning of DList. Updates actual pointer to be the new first node...
Definition: dlist.cpp:181
bool hasNoDeltas()
Returns true if there is no elements of type $$ in DList.
Definition: dlist.cpp:666
bool check()
Verifies if the number of $b$'s and $b^$'s matches and if each one is less or equal than N of SO(2N)...
Definition: dlist.cpp:570
void getDeltaIds(bool &AllDeltas, vector< string > &id0, vector< string > &id1, int &sign)
Updates integer vector sequence containers "id0" and "id1" with first and second ids (data fields) of...
Definition: dlist.cpp:405
void join(DList &L)
Joins a DList to the end of the current DList (this). Updates "actual" pointer to be the end of the f...
Definition: dlist.cpp:232
~DList(void)
Destructor.
Definition: dlist.cpp:123
struct for the node of DList
Definition: dlist.h:251
const DList operator-() const
Negates operator, change sign of DList.
Definition: dlist.cpp:771
noList * end
Pointer to the last node.
Definition: dlist.h:268
unsigned int getIdx1()
Returns the first data field of the element (id.x).
Definition: dlist.h:126
bool search_first(unsigned int type1)
Search the first element with "data.get\_type()==type" found in DList. Returns true if the symbol is ...
Definition: dlist.cpp:515
#define bb(a)
C++ Macro for DList b operator.
Definition: son.h:75