IntegerSetIterableImplementation   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B partialIntersection() 0 24 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\PartialIntersection;
6
7
use Smoren\PartialIntersection\Util\IteratorFactory;
8
9
class IntegerSetIterableImplementation
10
{
11
    /**
12
     * @param int $m
13
     * @param iterable<int> ...$sets
14
     *
15
     * @return \Generator<int>
16
     */
17 105
    public static function partialIntersection(int $m, iterable ...$sets): \Generator
18
    {
19 105
        $iterator = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);
20
21 105
        foreach ($sets as $set) {
22 97
            $iterator->attachIterator(IteratorFactory::makeIterator($set));
23
        }
24
25 105
        $usageMap = [];
26
27 105
        foreach ($iterator as $values) {
28 77
            foreach ($values as $value) {
29 77
                if ($value === null) {
30 25
                    continue;
31
                }
32
33 77
                if (!isset($usageMap[$value])) {
34 77
                    $usageMap[$value] = 0;
35
                }
36
37 77
                $usageMap[$value]++;
38
39 77
                if ($usageMap[$value] === $m) {
40 48
                    yield $value;
41
                }
42
            }
43
        }
44
    }
45
}
46