Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:04

0001 
0002    template<unsigned int D>
0003    struct RowOffsets {
0004       inline RowOffsets() {
0005          int v[D];
0006          v[0]=0;
0007          for (unsigned int i=1; i<D; ++i)
0008             v[i]=v[i-1]+i;
0009          for (unsigned int i=0; i<D; ++i) { 
0010             for (unsigned int j=0; j<=i; ++j)
0011                fOff[i*D+j] = v[i]+j; 
0012             for (unsigned int j=i+1; j<D; ++j)
0013                fOff[i*D+j] = v[j]+i ;
0014          }
0015       }
0016       inline int operator()(unsigned int i, unsigned int j) const { return fOff[i*D+j]; }
0017       inline int apply(unsigned int i) const { return fOff[i]; }
0018       int fOff[D*D];
0019    };
0020 
0021 #include<iostream>
0022 template<unsigned int D>
0023 void dump( RowOffsets<D> const & ro ) {
0024   std::cout << "{ ";
0025   for (int i=0; i!=D*D-1; ++i)
0026     std::cout << ro.apply(i) << ",";
0027   std::cout << ro.apply(D*D-1) << " }," << std::endl;
0028 }
0029 
0030 int  main() {
0031   RowOffsets<15> ro;
0032   dump(ro);
0033   return 0;
0034 }