summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Bauer <mail@ulrich-bauer.org>2020-11-25 09:45:39 +0100
committerUlrich Bauer <mail@ulrich-bauer.org>2020-11-25 09:45:39 +0100
commit3e5137e14496bde8758320ae428d8f2837a0d9ca (patch)
treef06febd7f7141f8af40bc599bbce54477d1d21b8
parent58444a462f658fa5c492f0f8ec816bf3b4f0a47e (diff)
binary search for sparse distance matrix random access
-rw-r--r--ripser.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/ripser.cpp b/ripser.cpp
index 62eb848..69ce97b 100644
--- a/ripser.cpp
+++ b/ripser.cpp
@@ -280,9 +280,8 @@ struct sparse_distance_matrix {
}
value_t operator()(const index_t i, const index_t j) const {
- for (auto neighbor: neighbors[i])
- if (get_index(neighbor) == j) return get_diameter(neighbor);
- return std::numeric_limits<value_t>::infinity();
+ auto neighbor = std::lower_bound(neighbors[i].begin(), neighbors[i].end(), index_diameter_t{j,0});
+ return (neighbor != neighbors[i].end() && get_index(*neighbor) == j) ? get_diameter(*neighbor) : std::numeric_limits<value_t>::infinity();
}
size_t size() const { return neighbors.size(); }