diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-24 07:35:40 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-24 07:35:40 +0000 |
commit | 99a4c322f30b39726787b96ea59d3159dc3d0d13 (patch) | |
tree | 9fd5749cf995ad96e5ed46b852bd9388fbb2e3e4 /decoder/sparse_vector.h | |
parent | 33dcd4ddadbebbf65be501dedfd87586f34b7e6a (diff) |
minor - disable hash sparse_vector for now
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@396 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/sparse_vector.h')
-rw-r--r-- | decoder/sparse_vector.h | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h index 1733a4bd..e58485c0 100644 --- a/decoder/sparse_vector.h +++ b/decoder/sparse_vector.h @@ -370,10 +370,26 @@ private: MapType values_; }; +//like a pair but can live in a union, because it lacks default+copy ctors, dtor. +template <class T> +struct feature_val { + int fid; + T val; +}; + +template <class T> +inline feature_val<T> featval(int fid,T const &val) { + feature_val<T> f; + f.fid=fid; + f.val=val; + return f; +} + + // doesn't support fast indexing directly template <class T> class SparseVectorList { - typedef typename std::pair<int,T> Pair; + typedef feature_val<T> Pair; typedef SmallVector<Pair,1> List; typedef typename List::const_iterator const_iterator; SparseVectorList() { } @@ -383,7 +399,7 @@ class SparseVectorList { int c=0; for (;i<end;++i,++c) { if (*i!=z) - p.push_back(Pair(c,*i)); + p.push_back(featval(c,*i)); } p.compact(); } @@ -392,7 +408,7 @@ class SparseVectorList { for (unsigned i=0;i<v.size();++i) { T const& t=v[i]; if (t!=z) - p.push_back(Pair(i,t)); + p.push_back(featval(i,t)); } p.compact(); } @@ -402,7 +418,7 @@ class SparseVectorList { } void overlay(SparseVector<T> *to) const { for (int i=0;i<p.size();++i) - to->set_value(p[i].first,p[i].second); + to->set_value(p[i].fid,p[i].val); } void copy_to(SparseVector<T> *to) const { to->clear(); |