From ccf7f9e5b8840f57c68dec83e2153c3cc5804b61 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:07:20 +0000 Subject: Clean-up. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@912 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f5652acf2ed5eb6f11428d2907963b5d1a1359be --- .../include/gudhi/Persistent_cohomology.h | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 3875afc6..2d6a85c1 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,13 +431,14 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity. -#if 0 - std::vector> annotations_in_boundary; -#else - static std::vector> annotations_in_boundary; - annotations_in_boundary.clear(); -#endif + // with multiplicity. We used to sum the coefficients directly in + // annotations_in_boundary by using a map, we now do it later. + typedef std::pair annotation_t; + std::vector annotations_in_boundary; + /* A small speed boost is possible with the following non-thread-safe: + static std::vector> annotations_in_boundary; + annotations_in_boundary.clear(); + */ int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -454,18 +455,18 @@ class Persistent_cohomology { } sign = -sign; } - std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - auto ann_it = annotations_in_boundary.begin(); - while (ann_it != annotations_in_boundary.end()) { - auto col = ann_it->first; + for (auto ann_it = annotations_in_boundary.begin(); ann_it != annotations_in_boundary.end(); /**/) { + Column* col = ann_it->first; int coef = ann_it->second; - for (;;) { - if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) - break; + while (++ann_it != annotations_in_boundary.end() && ann_it->first == col) { coef += ann_it->second; } // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. -- cgit v1.2.3