From 745bba706c93b239a0cbe29656c15facf6a6f7c4 Mon Sep 17 00:00:00 2001 From: jiri Date: Sun, 2 Apr 2006 20:07:29 +0000 Subject: [PATCH] *** empty log message *** --- fourindex.h | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/fourindex.h b/fourindex.h index d1b5167..edb6c0d 100644 --- a/fourindex.h +++ b/fourindex.h @@ -6,24 +6,34 @@ //element of a linked list, indices in a portable way, no bit shifts and endianity problems any more! //note: nn is never compared with individual indices, so indexing from 1 as well as from 0 is possible +template +union packed_index { + I packed[4]; + struct { + I i; + I j; + I k; + I l; + } indiv; + }; template struct matel4 { T elem; matel4 *next; - typedef union { - I packed[4]; - struct { - I i; - I j; - I k; - I l; - } indiv; - } packedindex; - packedindex index; + union packed_index index; }; + +template +struct matel4stored + { + T elem; + union packed_index index; + }; + + typedef enum {nosymmetry=0, twoelectronrealmullikan=1, twoelectronrealdirac=2, T2ijab_real=3} fourindexsymtype; //only permutation-nonequivalent elements are stored // these should actually be static private members of the fourindex class, but leads to an ICE on gcc3.2 static const int fourindex_n_symmetrytypes=4; @@ -135,11 +145,11 @@ public: inline void add(const I i, const I j, const I k, const I l, const T elem) {matel4 *ltmp= new matel4; ltmp->next=list; list=ltmp; list->index.indiv.i=i;list->index.indiv.j=j;list->index.indiv.k=k;list->index.indiv.l=l; list->elem=elem;} - inline void add(const typename matel4::packedindex &index , const T elem) + inline void add(const union packed_index &index , const T elem) {matel4 *ltmp= new matel4; ltmp->next=list; list=ltmp; list->index=index; list->elem=elem;} inline void add(const I (&index)[4], const T elem) - {matel4 *ltmp= new matel4; ltmp->next=list; list=ltmp; memcpy(&list->index.packed, &index, sizeof(typename matel4::packedindex)); list->elem=elem;} + {matel4 *ltmp= new matel4; ltmp->next=list; list=ltmp; memcpy(&list->index.packed, &index, sizeof(union packed_index)); list->elem=elem;} @@ -297,7 +307,7 @@ ostream& operator<<(ostream &s, const fourindex &x) typename fourindex::iterator it=x.begin(),end=x.end(); while(it!=end) { - s << (int)it->index.indiv.i << ' ' << (int)it->index.indiv.j<< ' ' <<(int)it->index.indiv.k << ' ' << (int)it->index.indiv.l << ' ' << it->elem << '\n'; + s << (int)it->index.indiv.i << ' ' << (int)it->index.indiv.j<< ' ' <<(int)it->index.indiv.k << ' ' << (int)it->index.indiv.l << ' ' << (typename LA_traits_io::IOtype) it->elem << '\n'; ++it; } s << "-1 -1 -1 -1\n"; @@ -308,7 +318,7 @@ template istream& operator>>(istream &s, fourindex &x) { int i,j,k,l; - T elem; + typename LA_traits_io::IOtype elem; int n; s >> n ; x.resize(n); @@ -316,7 +326,7 @@ istream& operator>>(istream &s, fourindex &x) while(i>=0 && j>=0 &&k>=0 &&l>=0) { s>>elem; - x.add(i,j,k,l,elem); + x.add(i,j,k,l,(T)elem); s >> i >> j >>k >>l; } return s;