summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-24 07:35:40 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-24 07:35:40 +0000
commit16ca40c21a4b2dcff30fe1b94c67bf3f58aeaba5 (patch)
tree224b6b3cc245eea60f582c5c2f965f1a0b2fd79e /decoder
parentc4eac4b98cb147c6949d655e1e137687a4f38690 (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')
-rw-r--r--decoder/small_vector.h1
-rw-r--r--decoder/sparse_vector.h24
2 files changed, 20 insertions, 5 deletions
diff --git a/decoder/small_vector.h b/decoder/small_vector.h
index b5d86231..4183cde2 100644
--- a/decoder/small_vector.h
+++ b/decoder/small_vector.h
@@ -168,7 +168,6 @@ public:
ptr_to_small();
}
-
void compact() {
compact(size_);
}
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();