From 5ea1f5a9e96a3c937531516176cabc7226bed9da Mon Sep 17 00:00:00 2001 From: glisse Date: Tue, 6 Oct 2015 15:31:40 +0000 Subject: Introduce Options::contiguous_vertices. For now only used and checked in find_vertex. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@833 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ceee8ba85eb21991a836b8f1d1117bcaafeb8c1b --- src/Simplex_tree/concept/SimplexTreeOptions.h | 2 ++ src/Simplex_tree/include/gudhi/Simplex_tree.h | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/Simplex_tree') diff --git a/src/Simplex_tree/concept/SimplexTreeOptions.h b/src/Simplex_tree/concept/SimplexTreeOptions.h index a50a2bf1..4a88f936 100644 --- a/src/Simplex_tree/concept/SimplexTreeOptions.h +++ b/src/Simplex_tree/concept/SimplexTreeOptions.h @@ -37,5 +37,7 @@ struct SimplexTreeOptions { static constexpr bool store_key; /// If true, each simplex has extra storage for one `Filtration_value`, and this value is propagated by operations like `Gudhi::Simplex_tree::expansion`. Without it, `Persistent_cohomology` degenerates to computing usual (non-persistent) cohomology. static constexpr bool store_filtration; + /// If true, the list of vertices present in the complex must always be 0, ..., num_vertices-1, without any hole. + static constexpr bool contiguous_vertices; }; diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 96565ff1..d19071fb 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -85,6 +85,7 @@ struct Simplex_tree_options_full_featured { typedef int Simplex_key; static const bool store_key = true; static const bool store_filtration = true; + static const bool contiguous_vertices = true; }; /** @@ -564,9 +565,21 @@ class Simplex_tree { /** \brief Returns the Simplex_handle corresponding to the 0-simplex * representing the vertex with Vertex_handle v. */ Simplex_handle find_vertex(Vertex_handle v) { - return root_.members_.begin() + v; + if (Options::contiguous_vertices) { + assert(contiguous_vertices()); + return root_.members_.begin() + v; + } else { + return root_.members_.find(v); + } + } + + /** \private \brief Test if the vertices have contiguous numbering: 0, 1, etc. */ + bool contiguous_vertices() const { + if(root_.members_.empty()) return true; + if(root_.members_.front()!=0) return false; + if(root_.members_.back()!=root_.members_.size()-1) return false; + return true; } - //{ return root_.members_.find(v); } private: /** \brief Inserts a simplex represented by a vector of vertex. -- cgit v1.2.3