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
00028
00029
00030
00031
00032
00033 #ifndef _parttype_h_
00034 #define _parttype_h_
00035
00036 #include <vector>
00037 #include <string>
00038 #include <algorithm>
00039 #include "chomp/struct/bitfield.h"
00040 #include "maptype.h"
00041
00042
00043 namespace unifexp {
00044
00045
00046
00047
00048
00049
00050
00051 template <class numType>
00052 class partType
00053 {
00054 public:
00055
00056 partType ();
00057
00058
00059 virtual ~partType ();
00060
00061
00062 virtual std::string name () const = 0;
00063
00064
00065
00066
00067 virtual void create (const mapType<numType> &theMap, int partCount,
00068 const numType &delta) = 0;
00069
00070
00071
00072
00073
00074
00075 int find (const numType &number) const;
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 const numType &operator [] (int n) const;
00086
00087
00088
00089
00090
00091 const numType &at (int n) const;
00092
00093
00094
00095
00096
00097 bool isCritical (int n) const;
00098
00099
00100
00101
00102 int getCritical (int n = 0) const;
00103
00104 protected:
00105
00106
00107 void allocate (int n);
00108
00109
00110 void addCritical (int n);
00111
00112
00113
00114
00115 numType &operator [] (int n);
00116
00117 private:
00118
00119
00120
00121
00122 numType *intBounds;
00123
00124
00125
00126 int intCount;
00127
00128
00129 std::vector<int> critical;
00130
00131
00132
00133 chomp::homology::BitField b;
00134
00135
00136 partType (const partType<numType> &);
00137
00138
00139 partType<numType> &operator = (const partType<numType> &);
00140
00141 };
00142
00143
00144
00145 template <class numType>
00146 inline partType<numType>::partType (): intBounds (0), intCount (0)
00147 {
00148 return;
00149 }
00150
00151 template <class numType>
00152 inline partType<numType>::partType (const partType<numType> &)
00153 {
00154 throw "Copy constructor not implemented for partitions.";
00155 return;
00156 }
00157
00158 template <class numType>
00159 inline partType<numType> &partType<numType>::operator =
00160 (const partType<numType> &)
00161 {
00162 throw "Assignment operator not implemented for partitions.";
00163 return *this;
00164 }
00165
00166 template <class numType>
00167 inline partType<numType>::~partType ()
00168 {
00169 if (intBounds)
00170 {
00171 delete [] intBounds;
00172 b. free ();
00173 }
00174 return;
00175 }
00176
00177 template <class numType>
00178 inline const numType &partType<numType>::operator [] (int n) const
00179 {
00180 return intBounds [n];
00181 }
00182
00183 template <class numType>
00184 inline numType &partType<numType>::operator [] (int n)
00185 {
00186 return intBounds [n];
00187 }
00188
00189 template <class numType>
00190 inline const numType &partType<numType>::at (int n) const
00191 {
00192 if (!intBounds || (n < 0) || (n > intCount))
00193 throw "Partition element out of range requested.";
00194 return intBounds [n];
00195 }
00196
00197 template <class numType>
00198 inline bool partType<numType>::isCritical (int n) const
00199 {
00200 return !!b. test (n);
00201
00202
00203 }
00204
00205 template <class numType>
00206 inline int partType<numType>::getCritical (int n) const
00207 {
00208 if ((n < 0) || (n >= static_cast<int> (critical. size ())))
00209 throw "Critical interval number out of range.";
00210 return critical [n];
00211 }
00212
00213
00214
00215 template <class numType>
00216 inline int partType<numType>::find (const numType &number) const
00217 {
00218 if (!intBounds)
00219 throw "Partition not allocated.";
00220 if (number < intBounds [0])
00221 return -1;
00222 if (number >= intBounds [intCount])
00223 return intCount;
00224 int lowerbound = 0, upperbound = intCount + 1;
00225 while (upperbound - lowerbound > 1)
00226 {
00227 int middle = (lowerbound + upperbound) >> 1;
00228 if (number < intBounds [middle])
00229 upperbound = middle;
00230 else
00231 lowerbound = middle;
00232 }
00233 return lowerbound;
00234 }
00235
00236 template <class numType>
00237 inline void partType<numType>::addCritical (int n)
00238 {
00239 critical. push_back (n);
00240 b. set (n);
00241 return;
00242 }
00243
00244 template <class numType>
00245 inline void partType<numType>::allocate (int n)
00246 {
00247 if (n <= 0)
00248 {
00249 throw "A non-positive number of partition intervals "
00250 "requested.";
00251 }
00252 if (intBounds)
00253 {
00254 delete [] intBounds;
00255 b. free ();
00256 }
00257 intBounds = new numType [n + 1];
00258 intCount = n;
00259 b. allocate (n);
00260 b. clearall (n);
00261 critical. clear ();
00262 return;
00263 }
00264
00265
00266 }
00267
00268 #endif // _parttype_h_
00269
00270
00271