Skip to content

slava-vishnyakov/php-map-reduce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

To install:

composer require slava-vishnyakov/map-reduce
use \SlavaVishnyakov\MapReduce\MapReduceMemory;

$m = new MapReduceMemory(); // or MapReduceProcess
$m->send('a', 1);
$m->send('b', 1);
$m->send('a', 2);

foreach($m->iter() as $key => $groups) {
// yields
$key = 'a', $groups = [1,2]
$key = 'b', $groups = [1]

Also can be done via next() calls:

$m = new MapReduceMemory(); // or MapReduceProcess
$m->send('a', 1);
$m->send('b', 1);
$m->send('a', 2);
$m->send('a', new stdClass);

$m->next() ==> ['a', [1, 2, new stdClass]] 
$m->next() ==> ['b', [1]]
$m->next() ==> null

There are two implementations MapReduceMemory and MapReduceProcess.

The first does all sorting in memory, the second is for memory-hungry workloads, uses /usr/bin/sort to process basically unlimited amount of data.

About

MapReduce simple implementation

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages