Skip to content

Commit

Permalink
code review: DRY for nodes_by_label
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentRouvreau committed Oct 23, 2024
1 parent 0f8a7b8 commit f8de11a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Simplex_tree/include/gudhi/Simplex_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2378,17 +2378,15 @@ class Simplex_tree {
std::unordered_map<Vertex_handle, List_max_vertex> nodes_label_to_list_;

List_max_vertex* nodes_by_label(Vertex_handle v) {
if constexpr (Options::link_nodes_by_label) {
auto it_v = nodes_label_to_list_.find(v);
if (it_v != nodes_label_to_list_.end()) {
return &(it_v->second);
} else {
return nullptr;
}
}
return nullptr;
// Scott Meyers in Effective C++ 3rd Edition. On page 23, Item 3: a non const method can safely call a const one
// Doing it the other way is not safe
return const_cast<List_max_vertex*>(_nodes_by_label(v));
}
List_max_vertex const* nodes_by_label(Vertex_handle v) const {
return _nodes_by_label(v);
}

List_max_vertex const* _nodes_by_label(Vertex_handle v) const {
if constexpr (Options::link_nodes_by_label) {
auto it_v = nodes_label_to_list_.find(v);
if (it_v != nodes_label_to_list_.end()) {
Expand Down

0 comments on commit f8de11a

Please sign in to comment.