summaryrefslogtreecommitdiff
path: root/decoder/sparse_vector.h
diff options
context:
space:
mode:
Diffstat (limited to 'decoder/sparse_vector.h')
-rw-r--r--decoder/sparse_vector.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h
index 8fc0f520..207489c5 100644
--- a/decoder/sparse_vector.h
+++ b/decoder/sparse_vector.h
@@ -60,6 +60,11 @@ class SparseVector {
SPARSE_VECTOR_MAP_RESERVED(values_,-1,-2);
}
public:
+ T const& get_singleton() const {
+ assert(values_.size()==1);
+ return values_.begin()->second;
+ }
+
typedef SparseVector<T> Self;
typedef SPARSE_VECTOR_MAP<int, T> MapType;
typedef typename MapType::const_iterator const_iterator;
@@ -113,7 +118,7 @@ public:
return values_[index];
}
- void set_value(int index, const T &value) {
+ inline void set_value(int index, const T &value) {
values_[index] = value;
}
@@ -236,6 +241,15 @@ public:
values_.erase(found);*/
}
+ template <class T2>
+ void set_from(SparseVector<T2> const& other) {
+ for (typename MapType::const_iterator
+ it = other.values_.begin(); it != other.values_.end(); ++it)
+ {
+ values_[it->first]=it->second;
+ }
+ }
+
SparseVector<T> &operator+=(const SparseVector<T> &other) {
for (typename MapType::const_iterator
it = other.values_.begin(); it != other.values_.end(); ++it)