11 BinaryTree->meta->add_attribute('$:uid' => (
16 ("$instance" =~ /\((.*?)\)$/);
20 BinaryTree->meta->add_attribute('$:node' => (
21 reader => 'getNodeValue',
22 writer => 'setNodeValue',
26 BinaryTree->meta->add_attribute('$:parent' => (
27 predicate => 'hasParent',
28 reader => 'getParent',
32 BinaryTree->meta->add_attribute('$:left' => (
33 predicate => 'hasLeft',
37 my ($self, $tree) = @_;
38 $tree->setParent($self) if defined $tree;
39 $self->{'$:left'} = $tree;
45 BinaryTree->meta->add_attribute('$:right' => (
46 predicate => 'hasRight',
50 my ($self, $tree) = @_;
51 $tree->setParent($self) if defined $tree;
52 $self->{'$:right'} = $tree;
60 $class->meta->new_object(':node' => shift);
65 my $left = $self->getLeft();
66 $left->setParent(undef);
67 $self->setLeft(undef);
73 my $right = $self->getRight;
74 $right->setParent(undef);
75 $self->setRight(undef);
81 return (!$self->hasLeft && !$self->hasRight);
86 return !$self->hasParent;
90 my ($self, $func) = @_;
92 $self->getLeft->traverse($func) if $self->hasLeft;
93 $self->getRight->traverse($func) if $self->hasRight;
99 my $left = $self->getLeft;
100 $self->setLeft($self->getRight());
101 $self->setRight($left);
103 $self->getLeft->mirror() if $self->hasLeft();
104 $self->getRight->mirror() if $self->hasRight();
111 $size += $self->getLeft->size() if $self->hasLeft();
112 $size += $self->getRight->size() if $self->hasRight();
118 my ($left_height, $right_height) = (0, 0);
119 $left_height = $self->getLeft->height() if $self->hasLeft();
120 $right_height = $self->getRight->height() if $self->hasRight();
121 return 1 + (($left_height > $right_height) ? $left_height : $right_height);