GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  TREE::BINARY::VISITOR::PREORDERTRAVERSAL (3)

.ds Aq ’

NAME

Tree::Binary::Visitor::PreOrderTraversal - Visitor object for Tree::Binary objects

CONTENTS

SYNOPSIS



  use Tree::Binary;
  use Tree::Binary::Visitor::PreOrderTraversal;
 
  # create a visitor instance
  my $visitor = Tree::Binary::Visitor::PreOrderTraversal->new();                                                        
 
  # create a tree to visit
  # this is an expression tree
  # representing ((2 + 2) * (4 + 5))
  my $btree = Tree::Binary->new("*")
                    ->setLeft(Tree::Binary->new("+")
                                ->setLeft(Tree::Binary->new("2"))
                                ->setRight(Tree::Binary->new("2")))
                    ->setRight(Tree::Binary->new("+")
                                ->setLeft(Tree::Binary->new("4"))
                                ->setRight(Tree::Binary->new("5")));

  # by default this will collect all the
  # node values in depth-first order into
  # our results
  $tree->accept($visitor);       
 
  # get our results and print them
  print join ", ", $visitor->getResults();  # prints "*, +, 2, 2, + 4, 5"
 
  # for more complex node objects, you can specify
  # a node filter which will be used to extract the
  # information desired from each node
  $visitor->setNodeFilter(sub {
                my ($t) = @_;
                return $t->getNodeValue()->description();
                });



DESCRIPTION

For the most part, this class is just a wrapper around <B>Tree::BinaryB>’s traverse method.

METHODS

<B>newB> There are no arguments to the constructor the object will be in its default state. You can use the setNodeFilter method to customize its behavior.
<B>getNodeFilterB> This method returns the CODE reference set with setNodeFilter argument.
<B>clearNodeFilterB> This method clears node filter field.
<B>setNodeFilter ($filter_function)B> This method accepts a CODE reference as its $filter_function argument. This code reference is used to filter the tree nodes as they are collected. This can be used to customize output, or to gather specific information from a more complex tree node. The filter function should accept a single argument, which is the current Tree::Binary object.
<B>getResultsB> This method returns the accumulated results of the application of the node filter to the tree.
<B>setResultsB> This method should not really be used outside of this class, as it just would not make any sense to. It is included in this class and in this documenation to facilitate subclassing of this class for your own needs. If you desire to clear the results, then you can simply call setResults with no argument.
<B>visit ($tree)B> The visit method accepts a Tree::Binary and applies the function set in new or setNodeFilter appropriately. The results of this application can be retrieved with getResults

BUGS

None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it.

CODE COVERAGE

See the CODE COVERAGE section of Tree::Binary for details.

AUTHOR

stevan little, <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Copyright 2004, 2005 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 TREE::BINARY::VISITOR::PREORDERTRAVERSAL (3) 2014-09-18

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.