summaryrefslogtreecommitdiff
path: root/decoder/sparse_vector.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-21 22:09:50 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-21 22:09:50 +0000
commit8700e2ee96a71ed267617ce1ebd4ef3a002a1f6c (patch)
treefa4bb7fd70fbd422a3a7a9564fa8ba86aff2797f /decoder/sparse_vector.h
parentc9416968b391f10891733a00cc57bda27b4d323d (diff)
disabled TD reserved stuff - debug init assertion later
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@364 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/sparse_vector.h')
-rw-r--r--decoder/sparse_vector.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h
index 9894d662..b42e001a 100644
--- a/decoder/sparse_vector.h
+++ b/decoder/sparse_vector.h
@@ -332,7 +332,7 @@ class SparseVectorList {
int c=0;
for (;i<end;++i,++c) {
if (*i!=z)
- p.push_back(pair_type(c,*i));
+ p.push_back(Pair(c,*i));
}
p.compact();
}
@@ -341,10 +341,27 @@ class SparseVectorList {
for (unsigned i=0;i<v.size();++i) {
T const& t=v[i];
if (t!=z)
- p.push_back(pair_type(i,t));
+ p.push_back(Pair(i,t));
}
p.compact();
}
+ // unlike SparseVector, this doesn't overwrite - but conversion to SparseVector will use last value, which is the same
+ void set_value(int i,T const& val) {
+ p.push_back(Pair(i,val));
+ }
+ void overlay(SparseVector<T> *to) const {
+ for (int i=0;i<p.size();++i)
+ to->set_value(p[i].first,p[i].second);
+ }
+ void copy_to(SparseVector<T> *to) const {
+ to->clear();
+ overlay(to);
+ }
+ SparseVector<T> sparse() const {
+ SparseVector<T> r;
+ copy_to(r);
+ return r;
+ }
private:
List p;
};