Permalink
Browse files

WIP on RedBlack (probably to restructure)

this was WIP, but as I'm making the base BinaryFP stuff (which will probably be role-ified) this
will probably have a lot of the implementation removed in upcoming refactor
  • Loading branch information...
1 parent 683451a commit 17222908c4c346f5cf477440e2253de2fda3b451 Hakim Cassimally committed May 29, 2011
View
3 scratch/perl/text-piecetable/lib/Tree/RedBlackFP.pm
@@ -35,5 +35,8 @@ sub _insert {
}
sub debug_tree { '' }
+sub leaves { () }
+
+use constant is_empty => 1;
no Moose; __PACKAGE__->meta->make_immutable; 1;
View
26 scratch/perl/text-piecetable/lib/Tree/RedBlackFP/Node.pm
@@ -112,7 +112,7 @@ sub member {
my ($self, $data) = @_;
my $cmp = $self->compare($data)
- or return 1;
+ or return $self;
return $cmp > 0 ?
$self->right->member($data)
@@ -132,5 +132,29 @@ sub debug_tree {
return $left . $padding . $data . $right;
}
+sub leaves {
+ my $self = shift;
+ return (
+ $self->left->leaves,
+ $self->data,
+ $self->right->leaves
+ );
+}
+
+sub remove {
+ my ($self, $data) = @_;
+
+ my $cmp = $self->compare($data)
+ or do {
+
+
+ };
+
+ return $cmp > 0 ?
+ $self->right->remove($data)
+ : $self->left ->remove($data);
+}
+
+use constant is_empty => 0;
no Moose; __PACKAGE__->meta->make_immutable; 1;

0 comments on commit 1722290

Please sign in to comment.