00001 #ifndef _GRIDCOLUMN_H__
00002 #define _GRIDCOLUMN_H__
00003
00004 #include "IntArrayList.h"
00005 #include "Array.h"
00006
00007 DSS_NAMESPASE_BEGIN
00008
00009
00010
00011
00012 class SparseGridColumn
00013 {
00014
00015 public:
00016 long column_start_idx;
00017 IntArrayList* IndexesUfa;
00018 long Entries;
00019
00020 SparseGridColumn(IntArrayList* indexes)
00021 {
00022 Entries = 0;
00023 column_start_idx = -1;
00024 IndexesUfa = indexes;
00025 Entries = indexes->Count;
00026 }
00027
00028 ~SparseGridColumn()
00029 {
00030 if (IndexesUfa) {delete IndexesUfa;IndexesUfa=NULL;}
00031 }
00032
00033
00034
00035
00036
00037 long FindExistingBlockIndex(long bi)
00038 {
00039 long myIndex=IndexesUfa->BinarySearch(bi);
00040
00041
00042
00043 return myIndex;
00044 }
00045
00046 void SetValue(long bn,long bi, long si, long sj,double val,double* Columns_data,long &aux_idx)
00047 {
00048 if ((aux_idx>=IndexesUfa->Count) || (IndexesUfa->Items[aux_idx]!=bi))
00049 aux_idx = FindExistingBlockIndex(bi);
00050 if (aux_idx>=0)
00051 Columns_data[column_start_idx+bn*(bn*aux_idx+sj) + si] = val;
00052 }
00053
00054 double GetValue(long bn,long bi, long si, long sj,double* Columns_data,long &aux_idx)
00055 {
00056 if ((aux_idx>=IndexesUfa->Count) || aux_idx<0 || (IndexesUfa->Items[aux_idx]!=bi))
00057 aux_idx = FindExistingBlockIndex(bi);
00058 if (aux_idx<0)
00059 return 0;
00060 return Columns_data[column_start_idx+bn*(bn*aux_idx+sj) + si];
00061 }
00062
00063 void AddValue(long bn,long bi, long si, long sj,double val,double* Columns_data)
00064 {
00065 long newBlock = FindExistingBlockIndex(bi);
00066 Columns_data[column_start_idx+bn*bn*newBlock + si + sj*bn] += val;
00067 }
00068 };
00069
00070 DSS_NAMESPASE_END
00071
00072 #endif //GRIDCOLUMN_H__