Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 17222908c4c346f5cf477440e2253de2fda3b451 1 parent 683451a
Hakim Cassimally authored
3  scratch/perl/text-piecetable/lib/Tree/RedBlackFP.pm
View
@@ -35,5 +35,8 @@ sub _insert {
}
sub debug_tree { '' }
+sub leaves { () }
+
+use constant is_empty => 1;
no Moose; __PACKAGE__->meta->make_immutable; 1;
26 scratch/perl/text-piecetable/lib/Tree/RedBlackFP/Node.pm
View
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.