
Nicolas Ballas <ballas@lrde.epita.fr> writes:
Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr>
sparse_encode working.
* oln/core/encode/sparse_encode.hh: Update
``Update'' is quite general; please write more descriptive sentences. And don't forget the ending period. :)
Index: oln/core/encode/sparse_encode.hh --- oln/core/encode/sparse_encode.hh (revision 879) +++ oln/core/encode/sparse_encode.hh (working copy) @@ -33,6 +33,8 @@
# include <oln/core/sparse/sparse_image.hh>
+# include <vector> + namespace oln {
@@ -45,13 +47,44 @@ */ template <typename I> sparse_image<typename I::point, typename I::value> - sparse_encode(const Image<I> input) + sparse_encode(const Image<I>& input) { sparse_image<typename I::point, typename I::value> output; typename I::piter p (input.points()); - // typename I::coord len = 1; + unsigned len = 1; + typename I::coord old = 1; /*!< old point first dim coordinate */ typename I::point rstart; /*!< range pointstart */ - typename I::value rvalue; /*!< range value */ + std::vector<typename I::value> values; /*!< range value */
80 columns; aligned arguments.
+ + p.start(); + if (!p.is_valid()) + return output; + + rstart = p; + //FIXME: is it generall ?
Typo; missing space after `//'.
+ old = (p.to_point())[0]; + values.push_back(input(p.to_point()));
Can't we write input(p) directly instead?
+ p.next(); + while (p.is_valid()) + { + if ((p.to_point())[0] - 1 == old) + { + ++len; + values.push_back(input(p.to_point())); + } + else + { + output.insert(rstart, len, values); + rstart = p; + len = 1; + values.clear(); + values.push_back(input(p.to_point())); + } + old = (p.to_point())[0]; + p.next(); + } + output.insert(rstart, len, values); + return output; } }
Good! It's a good idea to write a test for each kind of image you add to the library, even if this test is dead simple. It helps to track regression, notably using the Build Farm (https://build.lrde.org/).