fei_FillableVec.hpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_FillableVec_hpp_
00010 #define _fei_FillableVec_hpp_
00011 
00012 #include "fei_macros.hpp"
00013 #include "fei_Pool_alloc.hpp"
00014 #include <map>
00015 
00016 namespace fei {
00017 
00018 class FillableVec {
00019  public:
00020   FillableVec();
00021   virtual ~FillableVec();
00022 
00023   void addEntry(int index, double coef);
00024 
00025   void addEntries(unsigned numEntries,
00026                   const double* coefs,
00027                   const int* indices);
00028 
00029   void putEntry(int index, double coef);
00030 
00031   void putEntries(unsigned numEntries,
00032                   const double* coefs,
00033                   const int* indices);
00034 
00035   void setValues(double value);
00036 
00037   unsigned size() const;
00038 
00039   bool hasEntry(int index) const;
00040 
00043   double getEntry(int index) const;
00044 
00045   void removeEntry(int index);
00046 
00047   void clear();
00048 
00049   typedef
00050     std::map<int,double,std::less<int>,
00051      fei_Pool_alloc<std::pair<const int,int> > > feipoolmap;
00052 
00053   typedef feipoolmap::iterator iterator;
00054   typedef feipoolmap::const_iterator const_iterator;
00055 
00056   iterator begin() {return vecdata_.begin();}
00057   iterator end() {return vecdata_.end();}
00058 
00059   const_iterator begin() const {return vecdata_.begin();}
00060   const_iterator end() const {return vecdata_.end();}
00061 
00062   bool operator==(const FillableVec& rhs) const;
00063 
00064   bool operator!=(const FillableVec& rhs) const;
00065 
00066  private:
00067   feipoolmap vecdata_;
00068 };//class FillableVec
00069 
00070 inline void
00071 FillableVec::addEntry(int index, double coef)
00072 {
00073   feipoolmap::iterator iter = vecdata_.lower_bound(index);
00074   if (iter == vecdata_.end() || iter->first != index) {
00075     vecdata_.insert(iter, std::make_pair(index, coef));
00076   }
00077   else {
00078     iter->second += coef;
00079   }
00080 }
00081 
00082 inline void
00083 FillableVec::putEntry(int index, double coef)
00084 {
00085   feipoolmap::iterator iter = vecdata_.lower_bound(index);
00086   if (iter == vecdata_.end() || iter->first != index) {
00087     vecdata_.insert(iter, std::make_pair(index, coef));
00088   }
00089   else {
00090     iter->second = coef;
00091   }
00092 }
00093 
00094 inline
00095 bool
00096 FillableVec::operator==(const FillableVec& rhs) const
00097 {
00098   return vecdata_ == rhs.vecdata_;
00099 }
00100 
00101 inline
00102 bool
00103 FillableVec::operator!=(const FillableVec& rhs) const
00104 {
00105   return vecdata_ != rhs.vecdata_;
00106 }
00107 
00108 }//namespace fei
00109 
00110 #endif
00111 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:23 2011 for FEI by  doxygen 1.6.3