All pastes #260582 Raw Edit

Anonymous

public cpp v1 · immutable
#260582 ·published 2006-11-28 14:43 UTC
rendered paste body
#include <iostream>#include <map>#include <stdexcept>#include <cmath>#include <boost/numeric/ublas/vector_sparse.hpp>#include <boost/numeric/ublas/io.hpp>#include <boost/assert.hpp>using namespace std ;using namespace boost::numeric::ublas ;typedef unsigned int AFF_index ;typedef mapped_vector<AFF_index> 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 ;	}} ;