| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::OnlineCode::Decoder; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 27039 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 42 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 6 | use Carp; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 111 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 807 | use Net::OnlineCode; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 54 |  | 
| 9 | 1 |  |  | 1 |  | 628 | use Net::OnlineCode::GraphDecoder; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 42 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 1 |  |  | 1 |  | 7 | use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $VERSION); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 495 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | require Exporter; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | # Inherit from base class | 
| 16 |  |  |  |  |  |  | @ISA = qw(Net::OnlineCode Exporter); | 
| 17 |  |  |  |  |  |  | @EXPORT_OK = qw(); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | $VERSION = '0.02'; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub new { | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 |  |  | 0 | 1 |  | my $class = shift; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 |  |  |  |  |  | my %opts = ( | 
| 26 |  |  |  |  |  |  | # decoder-specific arguments: | 
| 27 |  |  |  |  |  |  | initial_rng => undef, | 
| 28 |  |  |  |  |  |  | # user-supplied arguments: | 
| 29 |  |  |  |  |  |  | @_ | 
| 30 |  |  |  |  |  |  | ); | 
| 31 | 0 | 0 |  |  |  |  | unless (ref($opts{initial_rng})) { | 
| 32 | 0 |  |  |  |  |  | carp "$class->new requires an initial_rng => \$rng parameter\n"; | 
| 33 | 0 |  |  |  |  |  | return undef; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # Send all arguments to the base class. It does basic parameter | 
| 37 |  |  |  |  |  |  | # handling/mangling, calculates the number of auxiliary blocks based | 
| 38 |  |  |  |  |  |  | # on them and generates a probability distribution. | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 |  |  |  |  |  | my $self = $class->SUPER::new(@_); | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | # This sub-class needs to use the rng to generate the initial graph | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | # print "decoder mblocks: $self->{mblocks}\n"; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 0 |  |  |  |  |  | my $graph = Net::OnlineCode::GraphDecoder->new | 
| 47 |  |  |  |  |  |  | ( | 
| 48 |  |  |  |  |  |  | $self->{mblocks}, | 
| 49 |  |  |  |  |  |  | $self->{ablocks}, | 
| 50 |  |  |  |  |  |  | $self->auxiliary_mapping($opts{initial_rng}), | 
| 51 |  |  |  |  |  |  | $self->{expand_aux}, | 
| 52 |  |  |  |  |  |  | ); | 
| 53 | 0 |  |  |  |  |  | $self->{graph} = $graph; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | # print "Decoder: returning from constructor\n"; | 
| 56 | 0 |  |  |  |  |  | return $self; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub accept_check_block { | 
| 61 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 62 | 0 |  |  |  |  |  | my $rng  = shift; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # print "Decoder: calling checkblock_mapping\n"; | 
| 65 | 0 |  |  |  |  |  | my $composite_blocks = $self->checkblock_mapping($rng); | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | # print "Decoder: Adding check block to graph\n"; | 
| 68 | 0 |  |  |  |  |  | my $check_node = $self->{graph}->add_check_block($composite_blocks); | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | # short-circuit check blocks that don't have any unsolved neighbours | 
| 71 | 0 | 0 |  |  |  |  | return (0) unless $check_node; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | # print "Decoder: Resolving graph\n"; | 
| 74 | 0 |  |  |  |  |  | my ($done, @which) = ($self->{graph}->resolve($check_node)); | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | # print "Decoder: Returning from accept_check_block\n"; | 
| 77 | 0 | 0 |  |  |  |  | if ($self->{expand_aux}) { | 
| 78 |  |  |  |  |  |  | # user doesn't care about aux blocks if expand_aux is on | 
| 79 | 0 |  |  |  |  |  | return ($done, grep { $_ < $self->{mblocks} } @which ); | 
|  | 0 |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | } else { | 
| 81 | 0 |  |  |  |  |  | return ($done, @which); | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | # expand_aux already handled in graph object | 
| 86 |  |  |  |  |  |  | sub xor_list { | 
| 87 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 88 | 0 |  |  |  |  |  | my $i = shift; | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 0 |  |  |  |  |  | return ($self->{graph}->xor_list($i)); | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | # algorithm will no longer return just composite blocks | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 0 |  |  |  |  |  | my $coblocks = $self->get_coblocks; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | # the graph object assigns check blocks indexes after the composite | 
| 98 |  |  |  |  |  |  | # blocks, but the user would prefer to count them from zero: | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 0 |  |  |  |  |  | my @list = map { $_ - $coblocks } ($self->{graph}->xor_list($i)); | 
|  | 0 |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 0 | 0 |  |  |  |  | foreach (@list) { die "xor_list: $_ is negative!\n" if $_ < 0; } | 
|  | 0 |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 0 |  |  |  |  |  | return @list; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | 1; | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | __END__ |