00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00037 #if !defined(_DFT_SPARSE_PATTERN_H_)
00038 #define _DFT_SPARSE_PATTERN_H_ 1
00039
00040 #if !defined(BEGIN_NAMESPACE)
00041 #define BEGIN_NAMESPACE(x) namespace x {
00042 #define END_NAMESPACE(x) }
00043 #endif
00044
00045 #include <vector>
00046 #include <stdio.h>
00047
00048 #include "basisinfo.h"
00049
00050 BEGIN_NAMESPACE(Dft)
00051
00052
00053 class SparsePattern {
00054 public:
00056 struct Interval {
00057 int lo, hi;
00058 Interval(int l_, int h_) : lo(l_), hi(h_){}
00059 };
00060 typedef std::vector<Interval> IntervalList;
00061 struct Column {
00062 IntervalList list;
00063
00064 void addInterval(int lo, int hi);
00065 void addIntervals(int nIntervals, int (*intervals)[2]);
00066 struct Iterator {
00067 IntervalList::const_iterator current, end;
00068 int pos;
00069 Iterator(const IntervalList::const_iterator& beg,
00070 const IntervalList::const_iterator& end_, int p)
00071 : current(beg), end(end_), pos(p)
00072 {}
00073
00074 Iterator& operator++() {
00075 ++pos;
00076 #if 0
00077 if(pos == current->hi)
00078 printf("Iterator increased to %d current limit %d last? %s %s\n",
00079 pos, current->hi,
00080 & *current == & *end ? "YES" : "NO",
00081 current == end ? "YES" : "NO");
00082 #endif
00083 if(pos >= current->hi) {
00084 ++current;
00085 if(current != end)
00086 pos = current->lo;
00087 else pos = 0;
00088 }
00089 return *this;
00090 }
00091 bool operator!=(const Iterator& other) const {
00092 bool res = !(& *current == & *other.current && pos == other.pos);
00093 #if 0
00094 printf("Iterator::operator!=() compares %p with %p, returns %s \n",
00095 & *current, & *other.current, res ? "TRUE" : "FALSE");
00096 #endif
00097 return res;
00098 }
00099 int operator*() const {
00100
00101 return pos;
00102 }
00103 const Interval* operator->() const {
00104 return &(*current);
00105 }
00106
00107 };
00108
00109 Iterator begin() const {
00110 IntervalList::const_iterator a = list.begin();
00111 IntervalList::const_iterator b = list.end();
00112 return Iterator(a, b, a != list.end() ? a->lo : 0);
00113 }
00114
00115 Iterator end() const {
00116 return Iterator(list.end(),list.end(),0);
00117 }
00118
00119 int size() const {
00120 int result = 0;
00121 for(IntervalList::const_iterator i = list.begin();
00122 i != list.end(); ++i)
00123 result += i->hi- i->lo;
00124 return result;
00125 }
00126 };
00127
00128 private:
00129 const BasisInfoStruct& bis;
00130 Column *ranges;
00131 public:
00132 explicit SparsePattern(const BasisInfoStruct& bis_)
00133 : bis(bis_), ranges(new Column[bis_.noOfBasisFuncs])
00134 { }
00135
00136 ~SparsePattern() {
00137 delete []ranges;
00138 }
00139
00142 void add(int nRanges, const int (*range)[2]);
00143
00144 void save(FILE *f) const;
00145 void load(FILE *f);
00146 const Column& operator[](int column) const {
00147 return ranges[column];
00148 }
00149
00151 int getColumnSize(int col) const {
00152 return ranges[col].size();
00153 }
00154
00156 int size() const {
00157 return bis.noOfBasisFuncs;
00158 }
00160 int sizeTotal() const;
00161 };
00162
00163 void setupShellMap(const BasisInfoStruct& bis, int *shellMap, int *aoMap);
00164
00165 END_NAMESPACE(Dft)
00166
00167 #endif