diff options
author | Ulrich Bauer <mail@ulrich-bauer.org> | 2020-11-25 09:45:39 +0100 |
---|---|---|
committer | Ulrich Bauer <mail@ulrich-bauer.org> | 2020-11-25 09:45:39 +0100 |
commit | 3e5137e14496bde8758320ae428d8f2837a0d9ca (patch) | |
tree | f06febd7f7141f8af40bc599bbce54477d1d21b8 | |
parent | 58444a462f658fa5c492f0f8ec816bf3b4f0a47e (diff) |
binary search for sparse distance matrix random access
-rw-r--r-- | ripser.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
@@ -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(); } |