function MorfFindHash($Word) { if (!is_integer($Word)) { $Word = mb_strtoupper($Word, 'utf8'); $Word = str_replace('Ё', 'Е', $Word); $CS = crc32_Stable($Word); } else { $CS = $Word; } static $fp = NULL; if ($fp === NULL) { $fp = fopen(dirname(__FILE__) . '/hmboh_ind.bin', 'rb'); } $Hash = abs($CS) % 4999999; $Index0 = pack('N', $CS); fseek($fp, 4 * $Hash); while (true) { $res = fread($fp, 4); if ($res === _N0) { return NULL; } if ($res === $Index0) { return $Hash; } $Hash++; if ($Hash === 4999999) { $Hash = 0; fseek($fp, 0); } } }
$Lines = file('SFBase02.txt'); //$fp1=fopen('hmb1.bin','r+b');//Основной файл //$fp2=fopen('hmb2.bin','r+b');//В этом файле храняться коллизии хешей $str1 = str_repeat(_N0, 4999999); $str2 = str_repeat(_N0, 4999999); $c = 0; $col = 0; $st = microtime(true); foreach ($Lines as $Line0) { if (trim($Line0)) { //Записываем в Файл $c++; //if($c===1000) // break; $Line = explode('%', $Line0); $CS = crc32_Stable($Line[0]); $Hash = abs($CS) % 4999999; $Group = (int) $Line[1]; $line1 = pack('N', $CS); $line2 = pack('N', $Group); while (true) { $s = 4 * $Hash; $CS2 = substr($str1, $s, 4); if ($CS2 === _N0) { for ($i = 0; $i < strlen($line1); $i++) { $str1[$s + $i] = $line1[$i]; } for ($i = 0; $i < strlen($line2); $i++) { $str2[$s + $i] = $line2[$i]; } break;