From 13e9c4ecc222efe0ffc3588eb8f559f7cd1d761d Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 22 Dec 2017 17:41:54 +0000 Subject: Prettify find_simplex(). git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/misc-glisse@3105 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 34ce3d49fb8f9e64df8b492b2e9091e5e0ca6be4 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/Simplex_tree') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 1a6a72a3..92add101 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -530,31 +530,30 @@ class Simplex_tree { Simplex_handle find_simplex(const std::vector & simplex) { Siblings * tmp_sib = &root_; Dictionary_it tmp_dit; - Vertex_handle last = simplex.back(); auto vi = simplex.begin(); if (Options::contiguous_vertices) { + // Equivalent to the first iteration of the normal loop GUDHI_CHECK(contiguous_vertices(), "non-contiguous vertices"); Vertex_handle v = *vi++; if(v < 0 || v >= static_cast(root_.members_.size())) return null_simplex(); tmp_dit = root_.members_.begin() + v; - if (!has_children(tmp_dit) && v != last) { + if (vi == simplex.end()) + return tmp_dit; + if (!has_children(tmp_dit)) return null_simplex(); - } tmp_sib = tmp_dit->second.children(); } - for (; vi != simplex.end(); ++vi) { - Vertex_handle v = *vi; - tmp_dit = tmp_sib->members_.find(v); - if (tmp_dit == tmp_sib->members_.end()) { + for (;;) { + tmp_dit = tmp_sib->members_.find(*vi++); + if (tmp_dit == tmp_sib->members_.end()) return null_simplex(); - } - if (!has_children(tmp_dit) && v != last) { + if (vi == simplex.end()) + return tmp_dit; + if (!has_children(tmp_dit)) return null_simplex(); - } tmp_sib = tmp_dit->second.children(); } - return tmp_dit; } /** \brief Returns the Simplex_handle corresponding to the 0-simplex -- cgit v1.2.3