vbl_sparse_array_1d.h
Go to the documentation of this file.
1 // This is core/vbl/vbl_sparse_array_1d.h
2 #ifndef vbl_sparse_array_1d_h_
3 #define vbl_sparse_array_1d_h_
4 //:
5 // \file
6 // \brief Sparse array allowing space efficient access of the form s[3000]=2.
7 // \author Andrew W. Fitzgibbon, Oxford RRG
8 // \date 02 Oct 96
9 //
10 // \verbatim
11 // Modifications
12 // Ian Scott (Manchester, ISBE) rewritten to use vbl_sparse_array_base
13 // \endverbatim
14 //---------------------------------------------------------------------------
15 
16 #include <iostream>
18 #ifdef _MSC_VER
19 # include <vcl_msvc_warnings.h>
20 #endif
21 
22 //: Sparse array allowing space efficient access of the form s[3000] = 2;
23 template <class T>
24 class vbl_sparse_array_1d: public vbl_sparse_array_base<T, unsigned>
25 {
26  public:
28 
29  //: Print the Array to a stream in "(i,j): value" format.
30  std::ostream& print(std::ostream& out) const
31  {
32  for (const_iterator p = this->begin(); p != this->end(); ++p)
33  out << '(' << (*p).first << "): " << (*p).second << std::endl;
34  return out;
35  }
36 };
37 
38 //: Stream operator - print the Array to a stream in "(i,j): value" format.
39 template <class T>
40 inline std::ostream& operator<< (std::ostream& s, const vbl_sparse_array_1d<T>& a)
41 {
42  return a.print(s);
43 }
44 
45 #ifndef VBL_SPARSE_ARRAY_BASE_INSTANTIATE
46 #define VBL_SPARSE_ARRAY_BASE_INSTANTIATE(T) \
47 extern "please include vbl/vbl_sparse_array_base.hxx instead"
48 #endif // VBL_SPARSE_ARRAY_BASE_INSTANTIATE
49 #define VBL_SPARSE_ARRAY_1D_INSTANTIATE(T) \
50 extern "please include vbl/vbl_sparse_array_1d.hxx instead"
51 
52 #endif // vbl_sparse_array_1d_h_
Sparse array allowing space efficient access of the form s[3000] = 2;.
Definition: vbl_fwd.h:8
const_iterator end() const
A bidirectional iterator pointing just beyond last non-empty element.
const_iterator begin() const
A bidirectional iterator pointing at the first non-empty element.
base class for sparse arrays.
std::ostream & print(std::ostream &out) const
Print the Array to a stream in "(i,j): value" format.
std::ostream & operator<<(std::ostream &s, const vbl_sparse_array_1d< T > &a)
Stream operator - print the Array to a stream in "(i,j): value" format.
A fully featured sparse array which devolves indexing to its templated type.
vbl_sparse_array_base< T, unsigned >::const_iterator const_iterator