summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-15 09:03:52 +0000
committerglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-15 09:03:52 +0000
commitf98b5a5f13d9657eb6ca924ca9909d4d29c9641a (patch)
tree27484da5e4b35787b5fcd6cfa94cfc1db9630283
parente91d128cf0a7b35d6a0caaae7066ad34d412c4be (diff)
Optionally provide a dummy key/filtration interface instead of storing them for real.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST-options@734 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ea7237a7b5c3d8e2dde49ea8356b142f3efa8089
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h54
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h42
2 files changed, 51 insertions, 45 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 153401d6..11c41d1b 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -85,35 +85,71 @@ namespace Gudhi {
* \implements FilteredComplex
*
*/
-template<typename IndexingTag = linear_indexing_tag,
-typename FiltrationValue = double, typename SimplexKey = int // must be a signed integer type
-, typename VertexHandle = int // must be a signed integer type, int convertible to it
->
+
+struct Simplex_tree_options_full_featured {
+ typedef linear_indexing_tag Indexing_tag;
+ typedef int Vertex_handle;
+ typedef double Filtration_value;
+ typedef int Simplex_key;
+ static constexpr bool store_key = true;
+ static constexpr bool store_filtration = true;
+};
+
+template<typename Options = Simplex_tree_options_full_featured>
class Simplex_tree {
public:
- typedef IndexingTag Indexing_tag;
+ typedef typename Options::Indexing_tag Indexing_tag;
/** \brief Type for the value of the filtration function.
*
* Must be comparable with <. */
- typedef FiltrationValue Filtration_value;
+ typedef typename Options::Filtration_value Filtration_value;
/** \brief Key associated to each simplex.
*
* Must be a signed integer type. */
- typedef SimplexKey Simplex_key;
+ typedef typename Options::Simplex_key Simplex_key;
/** \brief Type for the vertex handle.
*
* Must be a signed integer type. It admits a total order <. */
- typedef VertexHandle Vertex_handle;
+ typedef typename Options::Vertex_handle Vertex_handle;
/* Type of node in the simplex tree. */
typedef Simplex_tree_node_explicit_storage<Simplex_tree> Node;
/* Type of dictionary Vertex_handle -> Node for traversing the simplex tree. */
+ // FIXME: this wastes space when Vertex_handle is 32 bits and Node is aligned on 64 bits. It would be better to use a flat_set (with our own comparator) where we can control the layout of the struct (put Vertex_handle and Simplex_key next to each other).
typedef typename boost::container::flat_map<Vertex_handle, Node> Dictionary;
/* \brief Set of nodes sharing a same parent in the simplex tree. */
/* \brief Set of nodes sharing a same parent in the simplex tree. */
typedef Simplex_tree_siblings<Simplex_tree, Dictionary> Siblings;
+ struct Key_simplex_base_real {
+ Key_simplex_base_real() : key_(-1) {}
+ void assign_key(Simplex_key k) { key_ = k; }
+ Simplex_key key() const { return key_; }
+ private:
+ Simplex_key key_;
+ };
+ struct Key_simplex_base_dummy {
+ Key_simplex_base_dummy() {}
+ void assign_key(Simplex_key) { }
+ Simplex_key key() const { assert(false); return -1; }
+ };
+ typedef typename std::conditional<Options::store_key, Key_simplex_base_real, Key_simplex_base_dummy>::type Key_simplex_base;
+
+ struct Filtration_simplex_base_real {
+ Filtration_simplex_base_real() : filt_(0) {}
+ void assign_filtration(Filtration_value f) { filt_ = f; }
+ Filtration_value filtration() const { return filt_; }
+ private:
+ Filtration_value filt_;
+ };
+ struct Filtration_simplex_base_dummy {
+ Filtration_simplex_base_dummy() {}
+ void assign_filtration(Filtration_value f) { assert(f == 0); }
+ Filtration_value filtration() const { return 0; }
+ };
+ typedef typename std::conditional<Options::store_filtration, Filtration_simplex_base_real, Filtration_simplex_base_dummy>::type Filtration_simplex_base;
+
public:
/** \brief Handle type to a simplex contained in the simplicial complex represented
* by the simplex tree. */
@@ -456,7 +492,7 @@ class Simplex_tree {
* .end() return random access iterators, with 'value_type' Vertex_handle. */
template<class RandomAccessVertexRange>
std::pair<Simplex_handle, bool> insert_simplex(RandomAccessVertexRange & simplex,
- Filtration_value filtration) {
+ Filtration_value filtration = 0) {
if (simplex.empty()) {
return std::pair<Simplex_handle, bool>(null_simplex(), true);
}
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h
index 1f1a34cc..26d18098 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h
@@ -39,62 +39,32 @@ namespace Gudhi {
* It stores explicitely its own filtration value and its own Simplex_key.
*/
template<class SimplexTree>
-class Simplex_tree_node_explicit_storage {
+struct Simplex_tree_node_explicit_storage : SimplexTree::Filtration_simplex_base, SimplexTree::Key_simplex_base {
public:
typedef typename SimplexTree::Siblings Siblings;
typedef typename SimplexTree::Filtration_value Filtration_value;
typedef typename SimplexTree::Simplex_key Simplex_key;
- // Default constructor.
- Simplex_tree_node_explicit_storage()
- : children_(NULL),
- simplex_key_(-1),
- filtration_(0) {
- }
-
- Simplex_tree_node_explicit_storage(Siblings * sib,
- Filtration_value filtration)
- : children_(sib),
- simplex_key_(-1),
- filtration_(filtration) {
- }
-
- void assign_key(Simplex_key key) {
- simplex_key_ = key;
+ Simplex_tree_node_explicit_storage(Siblings * sib = nullptr,
+ Filtration_value filtration = 0)
+ : children_(sib) {
+ this->assign_filtration(filtration);
}
/*
- * Assign a children to the node
+ * Assign children to the node
*/
void assign_children(Siblings * children) {
children_ = children;
}
- /*
- *
- */
- void assign_filtration(double filtration_value) {
- filtration_ = filtration_value;
- }
-
- Filtration_value filtration() {
- return filtration_;
- }
/* Careful -> children_ can be NULL*/
Siblings * children() {
return children_;
}
- Simplex_key key() {
- return simplex_key_;
- }
-
private:
Siblings * children_;
-
- // Data attached to simplex, explicit storage
- Simplex_key simplex_key_;
- Filtration_value filtration_; // value in the filtration
};
/* @} */ // end addtogroup simplex_tree