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

Question about obtaining a node_type pointer to the root node #25

Open
ranchmed opened this issue Aug 22, 2020 · 2 comments
Open

Question about obtaining a node_type pointer to the root node #25

ranchmed opened this issue Aug 22, 2020 · 2 comments

Comments

@ranchmed
Copy link

I am thinking about using st_tree on a new project, and have been doing some preliminary testing.

I have one question about obtaining a pointer to the root node to help me construct a tree using node_type iterators.

In an earlier issue, you commented that you could get a node_type iterator from the tree by doing:

st_tree::tree<int> tree;
int a{1};
auto it = tree.root().insert(a);

Upon execution, I get an empty tree exception. This makes sense as the insert is done after the root() is dereferenced.

I can make it work by inserting a placeholder as follows:

st_tree::tree<int> tree;
int a{1};
tree.insert(0);  // Placeholder!
auto it = tree.root().insert(a);

But then we have an extra ply that really isn't part of the tree.

Is there another way to insert a root node in a tree, and then to get an node_type iterator for that node?

Thanks,
Mark

@erikerlandson
Copy link
Owner

Hi Mark! My memory of some design decisions is a bit rusty (I wrote this 10 years ago) but IIRC this is a consequence of some assymetries from trying to support a tree<> that could be either empty or have one root element. In more modern FP parlance it's really the analog of something like scala Option[T] acting like a sequence that is either empty or has one element.

It's slightly hinky under the hood, but I think it might be well defined to have tree<> return begin/end in either the empty or non empty case.

@erikerlandson
Copy link
Owner

I see this has been open nearly a year 😬

However, I'm going to leave this open in the event that either I have the bandwidth to work on it, or someone else wants to contribute an implementation.

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

No branches or pull requests

2 participants