Parallel::MapReduce::Testing - MapReduce Infrastructure, single-threaded, local


Parallel-MapReduce documentation Contained in the Parallel-MapReduce distribution.

Index


Code Index:

NAME

Top

Parallel::MapReduce::Testing - MapReduce Infrastructure, single-threaded, local

SYNOPSIS

Top

  use Parallel::MapReduce::Testing;
  my $mri = new Parallel::MapReduce::Testing;

  # rest like in Parallel::MapReduce

DESCRIPTION

Top

This subclass of Parallel::MapReduce implements MapReduce, but only as a single thread. Unlike its superclass, there is no need (or use) to provide lists of servers or workers.

This is great for testing your algorithm itself.

SEE ALSO

Top

Parallel::MapReduce

COPYRIGHT AND LICENSE

Top


Parallel-MapReduce documentation Contained in the Parallel-MapReduce distribution.
package Parallel::MapReduce::Testing;

use strict;
use warnings;

use base 'Parallel::MapReduce';

our $log;

sub new {
    my $class = shift;
    return bless {}, $class;
}

sub mapreduce {
    my $mri    = shift;
    my $map    = shift;
    my $reduce = shift;
    my $h1     = shift;

    $log ||= $Parallel::MapReduce::log;                                 # just a local short, I hate typing
    my %h3;
    while (my ($k, $v) = each %$h1) {
	my %h2 = &$map ($k => $v);
	map { push @{ $h3{$_} }, $h2{$_} } keys %h2;
    }
    my %h4;
    while (my ($k, $v) = each %h3) {
	$h4{$k} = &$reduce ($k => $v);
    }
    return \%h4;
}

our $VERSION = 0.04;

1;