Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Create OOP API.

  • Loading branch information...
commit d5969b527f2831ade953aa733d8c9d030741bb33 1 parent 830759d
@hiratara authored
Showing with 19 additions and 3 deletions.
  1. +17 −1 lib/Algorithm/Simpath.pm
  2. +2 −2 t/basic.t
View
18 lib/Algorithm/Simpath.pm
@@ -122,7 +122,23 @@ sub solve(@) {
@active_nodes = values %next_nodes_map;
}
- return $top_node;
+ bless {node => $top_node} => __PACKAGE__ . "::Zdd";
+}
+
+package Algorithm::Simpath::Zdd;
+use strict;
+use warnings;
+
+sub _count($); sub _count($) {
+ my $node = shift;
+ return 0 unless $node;
+ return 1 unless ref $node;
+ $node->{count} //= _count($node->{low}) + _count($node->{high});
+}
+
+sub count {
+ my $self = shift;
+ _count($self->{node});
}
1;
View
4 t/basic.t
@@ -16,7 +16,7 @@ sub count($); sub count($) {
goal => 'C',
edges => [[qw(A B)], [qw(C A)], [qw(D A)], [qw(B D)], [qw(B C)], [qw(C D)]],
);
- is +(count $zdd), 5;
+ is +($zdd->count), 5;
}
{
@@ -25,7 +25,7 @@ sub count($); sub count($) {
goal => 'C',
edges => [[qw(A B)], [qw(B C)], [qw(C A)], [qw(D A)], [qw(C D)], [qw(B D)]],
);
- is +(count $zdd), 5;
+ is +($zdd->count), 5;
}
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.