diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2015-09-09 08:47:19 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2015-09-09 08:47:19 +0000 |
commit | bc9c3de6cf45a44666ca3ac0a5a2c2151a4996d9 (patch) | |
tree | 7fdaa7e06f1aedd8ee503c2a75a64e17881e5939 | |
parent | c71a91c4192c82c464c8300a1b7b2e9de8fb2ca9 (diff) |
Issue fix for operator==. Replaced by is_equal function (constify is required first for operator==)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/copy_move@775 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 90d5e30caafb0679117be1ea40a12753847e9ab7
-rw-r--r-- | src/Simplex_tree/include/gudhi/Simplex_tree.h | 35 | ||||
-rw-r--r-- | src/Simplex_tree/test/simplex_tree_unit_test.cpp | 6 |
2 files changed, 20 insertions, 21 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 5588cafd..e9b12fd7 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -347,32 +347,31 @@ class Simplex_tree { public: /** \brief Checks if two simplex trees are equal. */ - bool operator==(Simplex_tree st2) { - return (this->null_vertex_ == st2.null_vertex_ - && this->threshold_ == st2.threshold_ - && this->dimension_ == st2.dimension_ - && rec_equal(&root_, &st2.root_)); - } - - /** \brief Checks if two simplex trees are different. */ - bool operator!=(Simplex_tree st2) { - return (!(*this == st2)); + // TODO: constify is required to make an operator== + bool is_equal(Simplex_tree& st2) + { + if ((null_vertex_ != st2.null_vertex_) || + (threshold_ != st2.threshold_) || + (dimension_ != st2.dimension_)) + return false; + return rec_equal(&root_, &st2.root_); } - + /** rec_equal: Checks recursively whether or not two simplex trees are equal, using depth first search. */ private: - bool rec_equal(Siblings * s1, Siblings * s2) { + bool rec_equal(Siblings* s1, Siblings* s2) { if (s1->members().size() != s2->members().size()) return false; - for (auto sh1 = s1->members().begin(), sh2 = s2->members().begin(); sh1 != s1->members().end(); ++sh1, ++sh2) { + for (auto sh1 = s1->members().begin(), sh2 = s2->members().begin(); + (sh1 != s1->members().end() && sh2 != s2->members().end()); ++sh1, ++sh2) { if (sh1->first != sh2->first || sh1->second.filtration() != sh2->second.filtration()) return false; - if (has_children(sh1)) - return rec_equal(sh1->second.children(), sh2->second.children()); - else if (has_children(sh2)) + if (((!has_children(sh1)) && (has_children(sh2))) || ((has_children(sh1)) && (!has_children(sh2)))) return false; - else - return true; + // Recursivity on children only if both have children + else if (has_children(sh1) && has_children(sh2)) + if (!rec_equal(sh1->second.children(), sh2->second.children())) + return false; } return true; } diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index d9666c52..6be6d4f3 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -657,7 +657,7 @@ BOOST_AUTO_TEST_CASE(copy_move_on_simplex_tree) { //std::cout << st_copy << std::endl; // Check the data are the same - BOOST_CHECK(st == st_copy); + BOOST_CHECK(st.is_equal(st_copy)); // Check there is a new simplex tree reference BOOST_CHECK(&st != &st_copy); @@ -667,14 +667,14 @@ BOOST_AUTO_TEST_CASE(copy_move_on_simplex_tree) { //std::cout << st_move << std::endl; // Check the data are the same - BOOST_CHECK(st_move == st_copy); + BOOST_CHECK(st_move.is_equal(st_copy)); // Check there is a new simplex tree reference BOOST_CHECK(&st_move != &st_copy); BOOST_CHECK(&st_move != &st); typeST st_empty; // Check st has been emptied by the move - BOOST_CHECK(st == st_empty); + BOOST_CHECK(st.is_equal(st_empty)); BOOST_CHECK(st.filtration() == 0); BOOST_CHECK(st.dimension() == -1); BOOST_CHECK(st.num_simplices() == 0); |