LocARNA-2.0.0
sparse_vector.hh
1 #ifndef SPARSE_VECTOR_HH
2 #define SPARSE_VECTOR_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <iosfwd>
9 #include <unordered_map>
10 
11 #include "aux.hh"
12 #include "sparse_vector_base.hh"
13 
14 namespace LocARNA {
15 
23  template <typename T>
24  class SparseVector : public SparseVectorBase<SparseVector<T>,T> {
25  public:
27  friend parent_t;
28 
29  using size_type = typename parent_t::size_type;
30  using value_type = T;
31  using key_type = size_type;
32  using map_type = std::unordered_map<key_type, value_type>;
33 
39  explicit
41 
42  SparseVector(): parent_t(value_type()) {}
43  };
44 
53  template <class T>
54  inline std::ostream &
55  operator<<(std::ostream &out, const SparseVector<T> &v) {
56  for (typename SparseVector<T>::const_iterator it = v.begin();
57  v.end() != it; ++it) {
58  out << it->first << ":" << it->second << " ";
59  }
60  out << std::endl;
61  return out;
62  }
63 
64 } // end namespace LocARNA
65 
66 #endif // SPARSE_VECTOR_HH
Base class template for sparse vector and matrix.
Definition: sparse_vector_base.hh:23
size_t size_type
usual definition of size_type
Definition: sparse_vector_base.hh:30
const value_type & def() const
Default value.
Definition: sparse_vector_base.hh:272
const_iterator begin() const
Begin const iterator over vector entries.
Definition: sparse_vector_base.hh:251
const_iterator end() const
End const iterator over vector entries.
Definition: sparse_vector_base.hh:262
typename map_type::const_iterator const_iterator
Stl-compatible constant iterator over vector elements.
Definition: sparse_vector_base.hh:37
Represents a sparse vector.
Definition: sparse_vector.hh:24
T value_type
type of vector entries
Definition: sparse_vector.hh:30
typename parent_t::size_type size_type
usual definition of size_type
Definition: sparse_vector.hh:29
SparseVector(const value_type &def)
Construct with default value.
Definition: sparse_vector.hh:40
size_type key_type
type of vector index
Definition: sparse_vector.hh:31
std::unordered_map< key_type, value_type > map_type
map type
Definition: sparse_vector.hh:32
Definition: aligner.cc:15
std::ostream & operator<<(std::ostream &out, const AlignerRestriction &r)
Definition: aligner_restriction.hh:135