Inheritance: implements Iterato\Iterator, implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements JsonSerializabl\JsonSerializable
 public function testLoadBigSet()
 {
     $startMem = ini_get('memory_limit');
     ini_set('memory_limit', '50M');
     // Big
     $bigSet = ImmArray::fromItems(new MD5Iterator(200000));
     $this->assertCount(200000, $bigSet);
     ini_set('memory_limit', $startMem);
 }
Exemple #2
0
<?php 
/**
 * Simple tests for now, to verify basic functionality.
 * This should soon be PHPUnit.
 */
require_once __DIR__ . '/../vendor/autoload.php';
use Qaribou\Collection\ImmArray;
use Qaribou\Iterator\SliceIterator;
$ia = ImmArray::fromArray(['a', 'b', 'c', 'd', 'e']);
$slice = new SliceIterator($ia, 1, -1);
foreach ($slice as $i => $el) {
    echo $i . ': ' . $el, PHP_EOL;
}
echo 'Count: ' . count($slice), PHP_EOL;
echo '1st index: ' . $slice[2], PHP_EOL;
Exemple #3
-1
echo 'Sorted: ' . $sorted->join(', '), PHP_EOL;
// Slice
$firstThree = $numberSet->slice(0, 3);
echo 'Sliced: ' . $firstThree->join(), PHP_EOL;
// Reduce
$summed = $numberSet->reduce(function ($last, $cur) {
    return $last + $cur;
}, 0);
echo 'Reduced (summed): ' . $summed, PHP_EOL;
$concatted = $sorted->reduce(function ($last, $cur, $i) {
    return $last . '{"' . $i . '":"' . $cur . '"},';
}, '');
echo 'Reduced (concat): ' . $concatted, PHP_EOL;
// Big
$bigSet = ImmArray::fromArray(array_map(function ($el) {
    return md5($el);
}, range(0, 200000)));
// Time the filter function
$t = microtime(true);
$bigSet->filter(function ($el) {
    return strpos($el, 'a8') > -1;
});
echo 'filter: ' . (microtime(true) - $t) . 's', PHP_EOL;
// Time the map function
$t = microtime(true);
$mem = memory_get_usage();
$big = $bigSet->map(function ($el) {
    return '{' . $el . '}';
});
echo 'ImmArray::map() ' . (microtime(true) - $t) . 's' . ', mem: ' . (memory_get_usage(true) - $mem), PHP_EOL;
$bigArr = $bigSet->toArray();