PHP Classes

File: src/Search/Bitap/createPatternAlphabet.php

Recommend this page to a friend!
  Classes of AccountKiller   Fuse   src/Search/Bitap/createPatternAlphabet.php   Download  
File: src/Search/Bitap/createPatternAlphabet.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Fuse
Fuzzy search of arrays using the Bitap algorithm
Author: By
Last change:
Date: 2 years ago
Size: 316 bytes
 

Contents

Class file image Download
<?php

namespace Fuse\Search\Bitap;

function
createPatternAlphabet(string $pattern): array
{
   
$mask = [];

    for (
$i = 0, $len = mb_strlen($pattern); $i < $len; $i += 1) {
       
$char = mb_substr($pattern, $i, 1);
       
$mask[$char] = ($mask[$char] ?? 0) | (1 << $len - $i - 1);
    }

    return
$mask;
}