I've been recently using the Tree::Simple package and I think that the observed behavior is consistent with the documentation. Consider, for example, the 'getDepth' function. In the documentation it says.
I've been recently using the Tree::Simple package and I think that the observed behavior is consistent with the documentation. Consider, for example, the 'getDepth' function. In the documentation it says: getDepth Returns a number representing the invocant's depth within the hierarchy of Tree::Simple objects.
NOTE: A ROOT tree has the depth of -1. This be because Tree::Simple assumes that a tree's root will usually not contain data, but just be an anchor for the data-containing branches. This may not be intuitive in all cases, so I mention it here.
From this, it seems to me that you need and "anchor" that must not contain data. In other words, your tree should look like this: # Tree: # anchor # | # a # _________ | ________ # / | \ # be c d # / \ # e f # \ # g # Then, the 'anchor' will be depth -1, 'a' will be depth 0, and 'b', 'c', 'd' will be depth 1. Hope this helps.
Yes, the anchor will now be the node that is not visited, but the previous root-node (which is supposed to be the root) will now not have the predicate 'isRoot' returning true. This is a problem, and the module is inconsistent with any other example tree datastructure. This is also clear when the depth of a root tree is -1.
A depth is a distance, and so, it can not be negative. – ath88 Oct 18 '11 at 1:11 May it be solved by fixing 'isRoot', to return TRUE on the node which contains 'a'? – deps_stats Oct 18 '11 at 14:08 How would you do that?
Change the module to detect the root based on the node's parent not having a parent? Currently it detects if the node has a parent. But, would it then be possible for a root-node to have siblings?
Because that is, currently, not possible. This will require a major rewrite of the module anyway. – ath88 Oct 18 '11 at 16:43.
You are right. The root should be included in a tree traversal. This is especially clear if you try an inorder traversal, since (considering your root has two children) the root should be inbetween the two children.
Google it, you'll see the same behavior everywhere. I even checked my book on algorithms. I'd make sure I have the newest version of the module, and report it as an error.
I was not sure if it is an error because Tree::Simple appeared to me a stable well known module. – katastrophos Oct 6 '11 at 15:51 I used the current version 1.18 – katastrophos Oct 6 '11 at 15:51 1 There are advantages to being able to skip the topic node, so I disagree that it should also visit the topic node. – ikegami Oct 6 '11 at 19:07 Could you give an example when there is a need to skip the topic node?
In my case I want the topic node. I'd say, if there are both cases, the user should be able to choose, which behaviour to use. – katastrophos 1.181 at 7:25.
So, I agree with all the posters here, that this can be a little confusing. However, the module is well establish and is currently being used in a number of places/codebases so a radical behavior change like changing how \&traverse works is not something I would entertain. That said, it was my view at the time (and kind of still is), that there is a difference between traversal (implemented with the \&traverse method) and visitation.
If you take a look at the Tree::Simple::Visitor module, you will be able to accomplish exactly what you are are after by setting the \&includeTrunk method accordingly. Additionally there are a number of other visitor implementations in that module that you might find useful. I would also encourage you to take a look at the Forest module, which is a modern re-write of Tree::Simple that uses Moose .
It too has a \&traverse method which behaves in this way, but it also has a \&fmap_cont method which is much more powerful. Additionally Forest has support for immutable (pure) trees as well as default reader/writer classes for serializing/deserializing your trees, indexing your trees, JSON serialization and more.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.