Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
93 - 1
<?php namespace Fuse\Bitap;
2
 
3
function matched_indices($matchmask = [], $minMatchCharLength = 1)
4
{
5
    $matchedIndices = [];
6
    $start = -1;
7
    $end = -1;
8
    $i = 0;
9
 
10
    for ($len = sizeof($matchmask); $i < $len; $i++) {
11
        $match = $matchmask[$i];
12
        if ($match && $start === -1) {
13
            $start = $i;
14
        } elseif (!$match && $start !== -1) {
15
            $end = $i - 1;
16
            if (($end - $start) + 1 >= $minMatchCharLength) {
17
                $matchedIndices[] = [ $start, $end ];
18
            }
19
            $start = -1;
20
        }
21
    }
22
 
23
    // (i-1 - start) + 1 => i - start
24
    if (isset($matchmask[$i - 1]) && $matchmask[$i - 1] && ($i - $start) >= $minMatchCharLength) {
25
        $matchedIndices[] = [ $start, $i - 1 ];
26
    }
27
 
28
    return $matchedIndices;
29
}