summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-07-11 15:43:50 +0000
committerglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-07-11 15:43:50 +0000
commit8e75cf8acd691c22ca972a5c0c5bf12580af2e78 (patch)
treefae7bd72250f3a0ef379688f9cdda5c696553ec4 /src
parent16ff459809374b1d8616a81dda2340c7f3942912 (diff)
Clean-ups
Avoid duplicate search with find+insert. No need to store 0 and 1 and return them by reference. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@702 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 28403136284a9fe2044b9d51bc2f10861b3a09e7
Diffstat (limited to 'src')
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h18
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h6
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h14
3 files changed, 14 insertions, 24 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
index 2a4c8692..a12019f8 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
@@ -41,9 +41,7 @@ class Field_Zp {
Field_Zp()
: Prime(0),
- inverse_(),
- mult_id_all(1),
- add_id_all(0) {
+ inverse_() {
}
void init(int charac) {
@@ -81,14 +79,14 @@ class Field_Zp {
}
/** \brief Returns the additive idendity \f$0_{\Bbbk}\f$ of the field.*/
- const Element& additive_identity() const {
- return add_id_all;
+ Element additive_identity() const {
+ return 0;
}
/** \brief Returns the multiplicative identity \f$1_{\Bbbk}\f$ of the field.*/
- const Element& multiplicative_identity(Element = 0) const {
- return mult_id_all;
+ Element multiplicative_identity(Element = 0) const {
+ return 1;
}
- /** Returns the inverse in the field. Modifies P.*/
+ /** Returns the inverse in the field. Modifies P. ??? */
std::pair<Element, Element> inverse(Element x, Element P) {
return std::pair<Element, Element>(inverse_[x], P);
} // <------ return the product of field characteristic for which x is invertible
@@ -101,7 +99,7 @@ class Field_Zp {
}
/** \brief Returns the characteristic \f$p\f$ of the field.*/
- const int& characteristic() const {
+ int characteristic() const {
return Prime;
}
@@ -109,8 +107,6 @@ class Field_Zp {
int Prime;
/** Property map Element -> Element, which associate to an element its inverse in the field.*/
std::vector<Element> inverse_;
- const Element mult_id_all;
- const Element add_id_all;
};
} // namespace persistent_cohomology
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h
index c6fd5282..555d696f 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h
@@ -142,7 +142,7 @@ class Multi_field {
return prod_characteristics_;
}
- /** Returns the inverse in the field. Modifies P.*/
+ /** Returns the inverse in the field. Modifies P. ??? */
std::pair<Element, Element> inverse(Element x, Element QS) {
Element QR;
mpz_gcd(QR.get_mpz_t(), x.get_mpz_t(), QS.get_mpz_t()); // QR <- gcd(x,QS)
@@ -153,12 +153,12 @@ class Multi_field {
mpz_invert(inv_qt.get_mpz_t(), x.get_mpz_t(), QT.get_mpz_t());
assert(prod_characteristics_ > 0); // division by zero + non negative values
- return std::pair<Element, Element>(
- (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT);
+ return { (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT };
}
/** Returns -x * y.*/
Element times_minus(const Element& x, const Element& y) {
assert(prod_characteristics_ > 0); // division by zero + non negative values
+ /* This assumes that (x*y)%pc cannot be zero, but Field_Zp has specific code for the 0 case ??? */
return prod_characteristics_ - ((x * y) % prod_characteristics_);
}
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h
index d6cbacaa..de350f2d 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h
@@ -90,18 +90,12 @@ class Simplex_tree_siblings {
* present in the node.
*/
void insert(Vertex_handle v, Filtration_value filtration_value) {
- typename Dictionary::iterator sh = members_.find(v);
- if (sh != members_.end() && sh->second.filtration() > filtration_value) {
- sh->second.assign_filtration(filtration_value);
- return;
- }
- if (sh == members_.end()) {
- members_.emplace(v, Node(this, filtration_value));
- return;
- }
+ auto ins = members_.emplace(v, Node(this, filtration_value));
+ if (!ins.second && filtration(ins.first) > filtration_value)
+ ins.first->second.assign_filtration(filtration_value);
}
- typename Dictionary::iterator find(Vertex_handle v) {
+ Dictionary_it find(Vertex_handle v) {
return members_.find(v);
}