Adobe Source Libraries 1.49.0
A collection of C++ libraries.
|
Last updated January 25, 2005
A
connects to both nodes B
and C
as children. The blue dashed lines are the possible "positions" the forest::iterator
will be over this forest. The best way to think of the forest::iterators
is not so much the node that they point to but rather the nodes they "sit" in between. For instance, forest::begin()
"sits" in between the forest head and node A
in the above example.A
. The iterator will then move onto node B
, where something interesting happens. You'll see a "pivot" take place where the iterator doesn't actually move on from node B
to C
. Instead, it "changes edges", notably from the leading edge of node B
to the trailing edge of B
. The next step takes us to the leading edge of C
, then another pivot to the trailing edge of C
. The iterator will then move back up to A
's trailing edge, then to the top, forest::end()
. adobe::forest
. They are:forest::iterator
: (also known as the fullorder iterator.) Visits the nodes by <parent><children><children><parent>. Each node in the forest is visted twice.forest::preorder_iterator
: Visits the nodes by <parent><children>. Each node in the forest is visted once.forest::postorder_iterator
: Visits the nodes by <children><parent>. Each node in the forest is visted once.forest::child_iterator
: From any given node, child_iterator
is a bidirectional iterator that walks a range of siblings (not the node's children) by "pivoting" on each node. There is a child_begin()
and child_end()
function to give you a range for the children of any node. Thus the child_iterator
only applies to the first level of siblings, not to grandchildren or beyond. reverse_
versions of the fullorder
and child
iterators, and const_
versions of the fullorder
and child
iterators. O(N)
where N
is the number of nodes in the forest.D
, somewhere around any given node in the tree (in this case we'll use node A
). Given node A
there are four distinct relationships D
will have to A
after insertion. The four possible relationships are:A
. Note the iterator is pointing to A
.A
. Note the iterator is pointing to forest::end()
.A
, or the previous sibling of B
. Note the iterator is pointing to B
.A
, or the next sibling of C
. Note the iterator is pointing to A
. A
. Don't forget that the dashed lines represent the position of any given iterator at any given time in the forest. In the case of a leaf node, the leading out and trailing in lines (iterator positions) are the same line (the loop), so the principle still applies. Insertion of nodes will always take place on top of one of these dashed lines, and never anywhere else. [first, last)
sequence, allowing you to insert more than one node essentially at the same location. Doing so makes the inserted sequence all "siblinging" on the same arc. It is the same as if you inserted each item, first
to last - 1
, at the same location. So let's say I have a fullorder iterator to the leading edge of node A
and I want to add a vector of items as children of A
. One can write: ++iter
the vector's elements would be added before A
, as siblings of A
.A
and B
and at forest::end()
. The nodes B
and C
will be deleted because the iterator will go through both of those nodes twice while traversing from the start to the end of the deletion range. Note that even though the deletion iterator will pass through A
it is not deleted because it only passes through once. Another way to think about it is if you were to "pinch" the forest with you fingers at the start and end of the range, and any node that isn't held back by the pinching at those two locations "drops" off the forest and is deleted. In the above case A
would be dropped by one of the pinches but not the other, so it remains.output
: <grandmother> <mother> <me> </me> <sister> </sister> <brother> </brother> </mother> <aunt> <cousin> </cousin> </aunt> <uncle> </uncle> </grandmother>
<grandmother> <uncle> </uncle> <aunt> <cousin> </cousin> </aunt> <mother> <me> </me> <sister> </sister> <brother> </brother> </mother> </grandmother>
<grandmother> <uncle> </uncle> <aunt> <cousin> </cousin> </aunt> <mother> <brother> </brother> <sister> </sister> <me> </me> </mother> </grandmother>
<grandmother> <mother> <me> </me> <sister> </sister> <brother> </brother> </mother> </grandmother>
Size of f4 pre-splice: 8 Size of f5 pre-splice: 8 <grandmother> <mother> <me> </me> <sister> </sister> <brother> </brother> </mother> <grandmother> <mother> <me> </me> <sister> </sister> <brother> </brother> </mother> <aunt> <cousin> </cousin> </aunt> <uncle> </uncle> </grandmother> <aunt> <cousin> </cousin> </aunt> <uncle> </uncle> </grandmother> Size of f4 post-splice: 16 Size of f5 post-splice: 0
Size of f6 pre-splice: 8 Size of f7 pre-splice: 8 <grandmother> <mother> <me> </me> <sister> </sister> <brother> </brother> </mother> <aunt> <cousin> </cousin> <grandmother> <mother> <me> </me> <sister> </sister> <brother> </brother> </mother> <aunt> <cousin> </cousin> </aunt> <uncle> </uncle> </grandmother> </aunt> <uncle> </uncle> </grandmother> Size of f6 post-splice: 16 Size of f7 post-splice: 0