#include #include #include #include #include #include #include using namespace std ; using namespace boost::numeric::ublas ; typedef unsigned int AFF_index ; typedef mapped_vector AFF_noise_internal ; class AFF_noise : public AFF_noise_internal { public: const AFF_index power() const { AFF_index tot = 0 ; AFF_noise::const_iterator it(begin()) ; for(;it!=end();++it) tot += *it ; return tot ; } const AFF_index operator()(const AFF_index& i) const { if(i >= size()) return 0 ; return AFF_noise_internal::operator()(i) ; } const AFF_index operator[](const AFF_index& i) const { if(i >= size()) return 0 ; return AFF_noise_internal::operator[](i) ; } AFF_index& operator()(const AFF_index& i) { if(i >= size()) resize(i+1, true) ; return AFF_noise_internal::operator()(i) ; } AFF_index& operator[](const AFF_index& i) { if(i >= size()) resize(i+1, true) ; return AFF_noise_internal::operator[](i) ; } AFF_noise() : AFF_noise_internal() { } ; AFF_noise(const AFF_index& i) : AFF_noise_internal(i+i, 1) { operator()(i) = 1 ; } AFF_noise(const AFF_noise& i) : AFF_noise_internal(i) { } AFF_noise& operator+=(const AFF_noise& other) { AFF_noise::const_iterator it ; if (size() < other.size()) resize(other.size(), true) ; for(it=other.begin(); it!=other.end(); ++it) { operator()(it.index()) += *it ; } return *this ; } inline AFF_noise operator+(const AFF_noise& other) const { AFF_noise sum = AFF_noise(*this) ; sum += other ; return sum ; } // Lexicographical sorting bool operator<(const AFF_noise& other) const { AFF_noise::const_iterator it ; for(it=begin(); it!=end(); ++it) { if(*it < other(it.index())) return true ; if(*it > other(it.index())) return false ; } return false ; } bool operator==(const AFF_noise& other) const { if (this->size() != other.size()) return false ; AFF_noise::const_iterator it ; for(it=begin(); it!=end(); ++it) { if(*it != other(it.index())) return false ; } return true ; } } ;