summaryrefslogtreecommitdiff
path: root/decoder/sparse_vector.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-16 22:48:09 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-16 22:48:09 +0000
commitceeac641b346ed462b802e2fee9091a6c0eb0dbb (patch)
tree82956218ff9810fb0beba881ab861d849d203513 /decoder/sparse_vector.h
parente79efced08b7cc4dc692954061f433e01fa7e137 (diff)
small/sparse vector fixes
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@304 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/sparse_vector.h')
-rw-r--r--decoder/sparse_vector.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h
index 43880014..f41bedf5 100644
--- a/decoder/sparse_vector.h
+++ b/decoder/sparse_vector.h
@@ -11,6 +11,7 @@
#include <valarray>
#include "fdict.h"
+#include "small_vector.h"
template <class T>
inline T & extend_vector(std::vector<T> &v,int i) {
@@ -310,10 +311,20 @@ private:
// doesn't support fast indexing directly
template <class T>
class SparseVectorList {
- typedef std::vector<const int,T> ListType;
- typedef typename ListType::value_type pair_type;
- typedef typename ListType::const_iterator const_iterator;
+ typedef typename std::pair<int,T> Pair;
+ typedef SmallVector<Pair,1> List;
+ typedef typename List::const_iterator const_iterator;
SparseVectorList() { }
+ template <class I>
+ SparseVectorList(I i,I const& end) {
+ const T z=T(0);
+ int c=0;
+ for (;i<end;++i,++c) {
+ if (*i!=z)
+ p.push_back(pair_type(c,*i));
+ }
+ p.compact();
+ }
explicit SparseVectorList(std::vector<T> const& v) {
const T z=T(0);
for (unsigned i=0;i<v.size();++i) {
@@ -321,10 +332,10 @@ class SparseVectorList {
if (t!=z)
p.push_back(pair_type(i,t));
}
- p.resize(p.size());
+ p.compact();
}
private:
- ListType p;
+ List p;
};