00001 #include "pup.h"
00002
00003 #ifndef CKARRAYINDEX_H
00004 #define CKARRAYINDEX_H
00005
00006
00008 #ifndef CK_ARRAYINDEX_MAXLEN
00009 #define CK_ARRAYINDEX_MAXLEN 3
00010 #endif
00011
00014 class CkArrayIndex;
00015
00016
00031 struct CkArrayIndexBase
00032 {
00033 public:
00035 short int nInts;
00037 short int dimension;
00039 union {
00040 int index[CK_ARRAYINDEX_MAXLEN];
00041 short int indexShorts[2 * CK_ARRAYINDEX_MAXLEN];
00042 };
00043
00045 inline CkArrayIndex& asChild() const { return *(CkArrayIndex*)this; }
00046
00048 void pup(PUP::er &p)
00049 {
00050 p|nInts;
00051 p|dimension;
00052 for (int i=0;i<nInts;i++) p|index[i];
00053 }
00054 };
00055
00056
00057
00065 class CkArrayIndex: public CkArrayIndexBase
00066 {
00067 public:
00069 CkArrayIndex() { nInts=0; dimension=0; for (int i=0; i<CK_ARRAYINDEX_MAXLEN; i++) index[i] = 0; }
00070
00071 CkArrayIndex(int idx) {init(1,1,idx);};
00072
00074 int *data(void) {return index; }
00076 const int *data(void) const {return index; }
00077
00079 int getCombinedCount(void) const
00080 {
00081 if (dimension == 1) return data()[0];
00082 else if (dimension == 2) return data()[0] * data()[1];
00083 else if (dimension == 3) return data()[0] * data()[1] * data()[2];
00084 else return 0;
00085 }
00086
00088 void print() { CmiPrintf("%d: %d %d %d\n", nInts, index[0], index[1], index[2]); }
00089
00091 CmiBool operator==(const CkArrayIndex& idx) const
00092 {
00093 if (nInts != idx.nInts) return CmiFalse;
00094 for (int i=0; i<nInts; i++)
00095 if (index[i] != idx.index[i]) return CmiFalse;
00096 return CmiTrue;
00097 }
00098
00100 inline CkHashCode hash(void) const
00101 {
00102 register int i;
00103 register const int *d=data();
00104 register CkHashCode ret=d[0];
00105 for (i=1;i<nInts;i++)
00106 ret +=circleShift(d[i],10+11*i)+circleShift(d[i],9+7*i);
00107 return ret;
00108 }
00110 static CkHashCode staticHash(const void *a,size_t) { return ((const CkArrayIndex *)a)->hash(); }
00112 inline int compare(const CkArrayIndex &idx) const { return (idx == *this); }
00114 static int staticCompare(const void *a,const void *b, size_t)
00115 { return (*(const CkArrayIndex *)a == *(const CkArrayIndex *)b); }
00116
00122 CmiObjId *getProjectionID(int arrayID)
00123 {
00124 CmiObjId *ret = new CmiObjId;
00125 int i;
00126 const int *data=this->data();
00127 if (OBJ_ID_SZ>=this->nInts)
00128 {
00129 for (i=0;i<this->nInts;i++)
00130 ret->id[i]=data[i];
00131 for (i=this->nInts;i<OBJ_ID_SZ;i++)
00132 ret->id[i]=0;
00133 }
00134 else
00135 {
00136
00137 int j;
00138 for (j=0;j<OBJ_ID_SZ;j++)
00139 ret->id[j]=data[j];
00140 for (i=0;i<this->nInts;i++)
00141 for (j=0;j<OBJ_ID_SZ;j++)
00142 ret->id[j]+=circleShift(data[i],22+11*i*(j+1))+
00143 circleShift(data[i],21-9*i*(j+1));
00144 }
00145 return ret;
00146 }
00147
00148 protected:
00149 inline void init(const short num, const short dims, const int x, const int y=0, const int z=0)
00150 {
00151 nInts = num;
00152 dimension = dims;
00153 index[0] = x;
00154 index[1] = y;
00155 index[2] = z;
00156 for (int i=3; i < CK_ARRAYINDEX_MAXLEN; i++)
00157 index[i] = 0;
00158 }
00159
00160 inline void init(const short num, const short dims,
00161 const short u, const short v, const short w,
00162 const short x, const short y=0, const short z=0)
00163 {
00164 nInts = num;
00165 dimension = dims;
00166 indexShorts[0] = u;
00167 indexShorts[1] = v;
00168 indexShorts[2] = w;
00169 indexShorts[3] = x;
00170 indexShorts[4] = y;
00171 indexShorts[5] = z;
00172 for (int i=6; i < 2 * CK_ARRAYINDEX_MAXLEN; i++)
00173 indexShorts[i] = 0;
00174 }
00175 };
00176
00177
00189 typedef CkArrayIndex CkArrayIndexMax;
00190
00191 #endif // CKARRAYINDEX_H
00192