T SparseVectorTemplate<T>::dot(const MyT& b) const { Assert(this->n==b.n); const_iterator k=this->begin(),bk=b.begin(); int i,bi; T sum=Zero; while(k!=this->end() || bk!=b.end()) { i = (k!=this->end()? k->first : this->n); bi = (bk!=b.end()? bk->first : this->n); if(i < bi) k++; else if (bi < i) bk++; else { sum+=k->second*bk->second; k++; bk++; } } return sum; }
void SparseVectorTemplate<T>::copySubVector(int i,const MyT& x) { Assert(i >= 0); Assert(i+x.n <= this->n); //erase entries between i and i+x.n typename MyT::iterator first,last; first = this->entries.lower_bound(i); last = this->entries.upper_bound(i+x.n); if(first != this->entries.end() && last != this->entries.end()) this->entries.erase(first,last); //insert new entries typename MyT::const_iterator j; for(j=x.begin();j!=x.end();j++) { this->insert(i+j->first,j->second); } }