summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoranmoreau <anmoreau@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-06-25 14:00:07 +0000
committeranmoreau <anmoreau@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-06-25 14:00:07 +0000
commit227cadacd804fead2222cf2897a04262fd430dcf (patch)
treee5b0f58160ae9a378bef862356dc0871ece498b3 /src
parente50c1af62d8ede46e151c898beec37c2dda4b142 (diff)
operator == instead of print_tree
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/copy_move@652 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f3848ccb53d732eb6a0059ca7f7c453b30391c1c
Diffstat (limited to 'src')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h187
-rw-r--r--src/Simplex_tree/test/simplex_tree_unit_test.cpp12
2 files changed, 105 insertions, 94 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 81867a25..79c7cd2e 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -361,36 +361,45 @@ class Simplex_tree {
}
public:
- /** \brief print_tree: prints the tree in a hierarchical manner. */
- void print_tree()
+
+
+ /** \brief Checks whether or not two simplex trees are equal. */
+ bool operator ==(Simplex_tree st2)
{
- for (auto sh = root_.members().begin(); sh != root_.members().end(); ++sh)
+ if (root_.members().size() != st2.root()->members().size())
+ return false;
+ for (auto sh1 = root_.members().begin(), sh2 = st2.root()->members().begin(); sh1 != root_.members().end(); ++sh1, ++sh2)
{
- std::cout << sh->first << " ";
- if (has_children(sh))
- {
- std::cout << "(";
- rec_print(sh->second.children());
- std::cout << ")";
- }
- std::cout << std::endl;
+ if (sh1->first != sh2->first)
+ return false;
+ if (has_children(sh1))
+ return rec_equal(sh1->second.children(), sh2->second.children());
+ else if (has_children(sh2))
+ return false;
+ else
+ return true;
}
+ return true;
}
- /** rec_print: prints the tree recursively, using DFS. */
+ /** rec_equal: Checks recursively whether or not two simplex trees are equal, using DFS. */
private:
- void rec_print(Siblings * sib)
+ bool rec_equal(Siblings * s1, Siblings * s2)
{
- for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh)
+ 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)
{
- std::cout << sh->first << " ";
- if (has_children(sh))
- {
- std::cout << "(";
- rec_print(sh->second.children());
- std::cout << ")";
- }
+ if (sh1->first != sh2->first)
+ return false;
+ if (has_children(sh1))
+ return rec_equal(sh1->second.children(), sh2->second.children());
+ else if (has_children(sh2))
+ return false;
+ else
+ return true;
}
+ return true;
}
public:
@@ -404,82 +413,82 @@ class Simplex_tree {
*
* The filtration must be initialized. */
Simplex_handle simplex(Simplex_key key) {
- return filtration_vect_[key];
+ return filtration_vect_[key];
}
/** \brief Returns the filtration value of a simplex.
*
* Called on the null_simplex, returns INFINITY. */
Filtration_value filtration(Simplex_handle sh) {
- if (sh != null_simplex()) {
- return sh->second.filtration();
- } else {
- return INFINITY;
- } // filtration(); }
- }
- /** \brief Returns an upper bound of the filtration values of the simplices. */
- Filtration_value filtration() {
- return threshold_;
- }
- /** \brief Returns a Simplex_handle different from all Simplex_handles
- * associated to the simplices in the simplicial complex.
- *
- * One can call filtration(null_simplex()). */
- Simplex_handle null_simplex() {
- return Dictionary_it(NULL);
- }
- /** \brief Returns a key different for all keys associated to the
- * simplices of the simplicial complex. */
- Simplex_key null_key() {
- return -1;
- }
- /** \brief Returns a Vertex_handle different from all Vertex_handles associated
- * to the vertices of the simplicial complex. */
- Vertex_handle null_vertex() {
- return null_vertex_;
- }
- /** \brief Returns the number of vertices in the complex. */
- size_t num_vertices() {
- return root_.members_.size();
- }
- /** \brief Returns the number of simplices in the complex.
- *
- * Does not count the empty simplex. */
- const unsigned int& num_simplices() const {
- return num_simplices_;
- }
+ if (sh != null_simplex()) {
+ return sh->second.filtration();
+ } else {
+ return INFINITY;
+ } // filtration(); }
+}
+/** \brief Returns an upper bound of the filtration values of the simplices. */
+Filtration_value filtration() {
+ return threshold_;
+}
+/** \brief Returns a Simplex_handle different from all Simplex_handles
+ * associated to the simplices in the simplicial complex.
+ *
+ * One can call filtration(null_simplex()). */
+Simplex_handle null_simplex() {
+ return Dictionary_it(NULL);
+}
+/** \brief Returns a key different for all keys associated to the
+ * simplices of the simplicial complex. */
+Simplex_key null_key() {
+ return -1;
+}
+/** \brief Returns a Vertex_handle different from all Vertex_handles associated
+ * to the vertices of the simplicial complex. */
+Vertex_handle null_vertex() {
+ return null_vertex_;
+}
+/** \brief Returns the number of vertices in the complex. */
+size_t num_vertices() {
+ return root_.members_.size();
+}
+/** \brief Returns the number of simplices in the complex.
+ *
+ * Does not count the empty simplex. */
+const unsigned int& num_simplices() const {
+ return num_simplices_;
+}
- /** \brief Returns the dimension of a simplex.
- *
- * Must be different from null_simplex().*/
- int dimension(Simplex_handle sh) {
- Siblings * curr_sib = self_siblings(sh);
- int dim = 0;
- while (curr_sib != NULL) {
- ++dim;
- curr_sib = curr_sib->oncles();
- }
- return dim - 1;
- }
- /** \brief Returns an upper bound on the dimension of the simplicial complex. */
- int dimension() {
- return dimension_;
- }
+/** \brief Returns the dimension of a simplex.
+ *
+ * Must be different from null_simplex().*/
+int dimension(Simplex_handle sh) {
+ Siblings * curr_sib = self_siblings(sh);
+ int dim = 0;
+ while (curr_sib != NULL) {
+ ++dim;
+ curr_sib = curr_sib->oncles();
+ }
+ return dim - 1;
+}
+/** \brief Returns an upper bound on the dimension of the simplicial complex. */
+int dimension() {
+ return dimension_;
+}
- /** \brief Returns true iff the node in the simplex tree pointed by
- * sh has children.*/
- bool has_children(Simplex_handle sh) {
- return (sh->second.children()->parent() == sh->first);
- }
+/** \brief Returns true iff the node in the simplex tree pointed by
+ * sh has children.*/
+bool has_children(Simplex_handle sh) {
+ return (sh->second.children()->parent() == sh->first);
+}
- /** \brief Given a range of Vertex_handles, returns the Simplex_handle
- * of the simplex in the simplicial complex containing the corresponding
- * vertices. Return null_simplex() if the simplex is not in the complex.
- *
- * The type RandomAccessVertexRange must be a range for which .begin() and
- * .end() return random access iterators, with <CODE>value_type</CODE>
- * <CODE>Vertex_handle</CODE>.
- */
- template<class RandomAccessVertexRange>
+/** \brief Given a range of Vertex_handles, returns the Simplex_handle
+ * of the simplex in the simplicial complex containing the corresponding
+ * vertices. Return null_simplex() if the simplex is not in the complex.
+ *
+ * The type RandomAccessVertexRange must be a range for which .begin() and
+ * .end() return random access iterators, with <CODE>value_type</CODE>
+ * <CODE>Vertex_handle</CODE>.
+ */
+template<class RandomAccessVertexRange>
Simplex_handle find(RandomAccessVertexRange & s) {
std::vector<Vertex_handle> copy = s;
sort(s.begin(), s.end());
diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
index b5c201d9..1e05f8e8 100644
--- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp
+++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
@@ -592,18 +592,20 @@ BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion )
std::cout << "Printing st" << std::endl;
std::cout << &st << std::endl;
std::cout << st; // Vertices test
- st.print_tree(); // Hierarchy test
- typeST st3 = st, st_move = std::move(st);
+// st.print_tree(); // Hierarchy test
+ typeST st3 = st;
+ BOOST_CHECK(st == st3);
+ typeST st_move = std::move(st);
std::cout << "Printing a copy of st" << std::endl;
std::cout << &st3 << std::endl;
std::cout << st3;
- st3.print_tree();
+// st3.print_tree();
std::cout << "Printing a move of st" << std::endl;
std::cout << &st_move << std::endl;
std::cout << st_move;
- st_move.print_tree();
+// st_move.print_tree();
std::cout << "Printing st again" << std::endl;
std::cout << &st << std::endl;
std::cout << st;
- st.print_tree();
+// st.print_tree();
}