sparse_pattern.h
Go to the documentation of this file.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 #if !defined(_DFT_SPARSE_PATTERN_H_)
00028 #define _DFT_SPARSE_PATTERN_H_ 1
00029
00030 #if !defined(BEGIN_NAMESPACE)
00031 #define BEGIN_NAMESPACE(x) namespace x {
00032 #define END_NAMESPACE(x) }
00033 #endif
00034
00035 #include <vector>
00036 #include <stdio.h>
00037
00038 #include "basisinfo.h"
00039
00040 BEGIN_NAMESPACE(Dft)
00041
00042
00043 class SparsePattern {
00044 public:
00046 struct Interval {
00047 int lo, hi;
00048 Interval(int l_, int h_) : lo(l_), hi(h_){}
00049 };
00050 typedef std::vector<Interval> IntervalList;
00051 struct Column {
00052 IntervalList list;
00053
00054 void addInterval(int lo, int hi);
00055 void addIntervals(int nIntervals, int (*intervals)[2]);
00056 struct Iterator {
00057 IntervalList::const_iterator current, end;
00058 int pos;
00059 Iterator(const IntervalList::const_iterator& beg,
00060 const IntervalList::const_iterator& end_, int p)
00061 : current(beg), end(end_), pos(p)
00062 {}
00063
00064 Iterator& operator++() {
00065 ++pos;
00066 #if 0
00067 if(pos == current->hi)
00068 printf("Iterator increased to %d current limit %d last? %s %s\n",
00069 pos, current->hi,
00070 & *current == & *end ? "YES" : "NO",
00071 current == end ? "YES" : "NO");
00072 #endif
00073 if(pos >= current->hi) {
00074 ++current;
00075 if(current != end)
00076 pos = current->lo;
00077 else pos = 0;
00078 }
00079 return *this;
00080 }
00081 bool operator!=(const Iterator& other) const {
00082 bool res = !(& *current == & *other.current && pos == other.pos);
00083 #if 0
00084 printf("Iterator::operator!=() compares %p with %p, returns %s \n",
00085 & *current, & *other.current, res ? "TRUE" : "FALSE");
00086 #endif
00087 return res;
00088 }
00089 int operator*() const {
00090
00091 return pos;
00092 }
00093 const Interval* operator->() const {
00094 return &(*current);
00095 }
00096
00097 };
00098
00099 Iterator begin() const {
00100 IntervalList::const_iterator a = list.begin();
00101 IntervalList::const_iterator b = list.end();
00102 return Iterator(a, b, a != list.end() ? a->lo : 0);
00103 }
00104
00105 Iterator end() const {
00106 return Iterator(list.end(),list.end(),0);
00107 }
00108
00109 int size() const {
00110 int result = 0;
00111 for(IntervalList::const_iterator i = list.begin();
00112 i != list.end(); ++i)
00113 result += i->hi- i->lo;
00114 return result;
00115 }
00116 };
00117
00118 private:
00119 const BasisInfoStruct& bis;
00120 Column *ranges;
00121 public:
00122 explicit SparsePattern(const BasisInfoStruct& bis_)
00123 : bis(bis_), ranges(new Column[bis_.noOfBasisFuncs])
00124 { }
00125
00126 ~SparsePattern() {
00127 delete []ranges;
00128 }
00129
00132 void add(int nRanges, const int (*range)[2]);
00133
00134 void save(FILE *f) const;
00135 void load(FILE *f);
00136 const Column& operator[](int column) const {
00137 return ranges[column];
00138 }
00139
00141 int getColumnSize(int col) const {
00142 return ranges[col].size();
00143 }
00144
00146 int size() const {
00147 return bis.noOfBasisFuncs;
00148 }
00150 int sizeTotal() const;
00151 };
00152
00153 void setupShellMap(const BasisInfoStruct& bis, int *shellMap, int *aoMap);
00154
00155 END_NAMESPACE(Dft)
00156
00157 #endif