- or download this
+-------+--------+----------+
| order | insert | retrieve |
...
|binary tree | yes | fast | fast |
|DAG tree | yes | fast | slow |
+------------+-------+--------+----------+
- or download this
company
/ | \
...
/ \ / \
net store | |
research development
- or download this
#!/usr/bin/perl -w
use strict;
...
my $pm = Tree::DAG_Node->new;
$pm->name('PerlMonks');
- or download this
my $tutorials = Tree::DAG_Node->new;
$tutorials->name('tutorials');
...
$tutorials->new_daughter->name('syntax');
$tutorials->new_daughter->name('references');
$tutorials->new_daughter->name('data');
- or download this
$pm->add_daughter($tutorials);
- or download this
my $reviews = Tree::DAG_Node->new;
...
my $SOPW = Tree::DAG_Node->new;
$SOPW->name('SOPW');
$pm->add_daughter($reviews, $SOPW);
- or download this
print map "$_\n", @{$pm->draw_ascii_tree};
- or download this
$pm->new_daughter->name('Meditations');
- or download this
print $pm->dump_names;
- or download this
|
<PerlMonks>
...
'modules'
'SOPW'
'Meditations'
- or download this
$pm->walk_down({
callback => sub {
...
_depth => 0,
treename => 'PerlMonks'
});
- or download this
(*) PerlMonks
tutorials
...
modules
SOPW
Meditations
- or download this
basics
syntax
...
SOPW
Meditations
(*) PerlMonks
- or download this
sub traverse {
my $node = shift;
...
....modules 0:1:1
..SOPW 0:2
..Meditations 0:3
- or download this
$pm->attributes (['The', ['best', 'Perl'],['site']]);
$tutorials->attributes ({
...
$pm->walk_down({callback=>sub{
print $_[0]->name," ", ref $_[0]->attributes,"\n";
}});
- or download this
|
<root>
...
/---\ /---\ /---+---\
| | | | | | |
<i> <j> <k> <l> <5> <6> <7>
- or download this
my @daughters = $root->daughters; # <a> and <b>
my @b_daughthers = $daughters[1]->daughters; # <b>'s daughters
...
my @right = $third->right_sisters; # <s>, <t> <u>
my $mama = $third->mother; # <b>
my @ancestors = $third->ancestors; # <b> <root>
- or download this
my @descnames = map {$_->name} $node1->descendants;
# @descnames = qw(w i j x k l);
- or download this
#!/usr/bin/perl -w
use strict;
...
$self->attributes($options);
return $self;
}
- or download this
sub employees {
my $node = shift;
...
1}});
return wantarray? @found : @found ? $found[0] : undef;
}
- or download this
sub clear_totals {
$_[0]->walk_down({ callback => sub {
...
$node->budget
}, _depth => 0 });
}
- or download this
package main;
...
$company->sum_up;
$company->print_wealth;
print map "$_\n", @{$company->draw_ascii_tree};
- or download this
company empl: 43 budget: 290000
sales empl: 14 budget: 90000
...
R&D empl: 25 budget: 190000
res empl: 10 budget: 100000
dev empl: 15 budget: 90000
- or download this
|
<company>
...
/-----\ /-----\
| | | |
<net> <str> <res> <dev>
- or download this
my $node = $root->address('0:2:1');
- or download this
my $node = $root->address('0:2:1');
$node->mother->new_daughter_left;
# now $node's address is '0:2:2'
- or download this
sub by_attribute {
my ($self, $key, $id) = @_;
...
1}});
return $found;
}
- or download this
my $node = $root->by_attribute( 'ID', 'nutcracker');
- or download this
#!/usr/bin/perl -w
use strict;
...
}
}
print map "$_\n", @{$root->draw_ascii_tree};
- or download this
|
<root>
...
/---+---\ /---+---\ /---+---\
| | | | | | | | |
<a> <b> <c> <d> <e> <f> <g> <h> <i>
- or download this
my $node = $root->address('0:1');
$node->replace_with_daughters;
print map "$_\n", @{$root->draw_ascii_tree};
- or download this
|
<root>
...
/---+---\ /---+---\
| | | | | |
<a> <b> <c> <g> <h> <i>
- or download this
$node = $root->address('0:4');
my $dest = $root->address('0:2');
$dest->add_daughter($node);
print map "$_\n", @{$root->draw_ascii_tree};
- or download this
|
<root>
...
<a> <b> <c> /---+---\
| | |
<g> <h> <i>