Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Simplex tree] Const Simplex_tree #1119

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

hschreiber
Copy link
Collaborator

Possibility to have a const Simplex_tree, but still be able to iterate over it or access information.

It is a draft, as it probably needs more testing (ignore the tests added to simplex_tree_unit_test.cpp). But I would like to have an opinion on it and see if I didn't forgot something obvious.

The modifications should not impact old code, if I didn't missed something important. The only big difference is that Simplex_handle is now a const_iterator instead of an iterator. If the users used the interface as expected, than there should be no problems. It will only be a problem if a user used the Simplex_handle as an iterator instead of an handle, ie, directly did sh->second.assign_filtration(1) instead of using st.assign_filtration(sh, 1). Which is a bit risky and therefore unlikely?

Copy link
Member

@mglisse mglisse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought you wanted to make it more similar to standard containers that have both iterator and const_iterator, but here you are basically moving from nothing is const to everything is const (Dictionary_it is not public). It doesn't look bad, but I'll need to think a bit.

src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Show resolved Hide resolved
src/Simplex_tree/include/gudhi/Simplex_tree.h Outdated Show resolved Hide resolved
@@ -1489,7 +1590,7 @@ class Simplex_tree {
{
Node& node_u = static_cast<Node&>(node_as_hook); //corresponding node, has label u
Simplex_handle sh_u = simplex_handle_from_node(node_u);
Siblings * sib_u = self_siblings(sh_u);
Siblings* sib_u = const_cast<Siblings*>(self_siblings(sh_u));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needing const_cast here looks ugly. Maybe self_siblings should still return a non-const pointer, at least if the Simplex_tree is not const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the simplex handle points to a constant Node, we need somehow to "unconst" it. But I could hide the const_cast in self_siblings. Or make simplex_handle_from_node return a non const iterator instead of a simplex handle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants