summaryrefslogtreecommitdiff
path: root/ripser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ripser.cpp')
-rw-r--r--ripser.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/ripser.cpp b/ripser.cpp
index 6241eb3..6502f63 100644
--- a/ripser.cpp
+++ b/ripser.cpp
@@ -240,17 +240,18 @@ public:
class simplex_coboundary_enumerator {
private:
- index_t idx, modified_idx, v, k;
+ index_t idx_below, idx_above, v, k;
const binomial_coeff_table& binomial_coeff;
public:
simplex_coboundary_enumerator(index_t _idx, index_t _dim, index_t _n, const binomial_coeff_table& _binomial_coeff)
- : idx(_idx), modified_idx(_idx), v(_n - 1), k(_dim + 1), binomial_coeff(_binomial_coeff) {}
+ : idx_below(_idx), idx_above(0), v(_n - 1), k(_dim + 1), binomial_coeff(_binomial_coeff) {}
bool has_next() {
- while ((v != -1) && (binomial_coeff(v, k) <= idx)) {
- idx -= binomial_coeff(v, k);
- modified_idx += binomial_coeff(v, k + 1) - binomial_coeff(v, k);
+ while ((v != -1) && (binomial_coeff(v, k) <= idx_below)) {
+ idx_below -= binomial_coeff(v, k);
+ idx_above += binomial_coeff(v, k + 1);
+
--v;
--k;
assert(k != -1);
@@ -259,7 +260,7 @@ public:
}
std::pair<entry_t, index_t> next() {
- auto result = std::make_pair(make_entry(modified_idx + binomial_coeff(v, k + 1), k & 1 ? -1 : 1), v);
+ auto result = std::make_pair(make_entry(idx_above + binomial_coeff(v, k + 1) + idx_below, k & 1 ? -1 : 1), v);
--v;
return result;
}