/**
* 查找需要的汉字内码(gb2312) 对应的拼音字符( 二分法 )
*
* @param int $code
* @return int
*/
private function _search( $code )
{
$data = array_keys($this->_pinyins);
$lower = 0;
$upper = sizeof($data)-1;
$middle = (int) round(($lower + $upper) / 2);
if ( $code < $data[0] ) return -1;
for (;;) {
if ( $lower > $upper ){
return $data[$lower-1];
}
$tmp = (int) round(($lower + $upper) / 2);
if ( !isset($data[$tmp]) ){
return $data[$middle];
}else{
$middle = $tmp;
}
if ( $data[$middle] < $code ){
$lower = (int)$middle + 1;
}else if ( $data[$middle] == $code ) {
return $data[$middle];
}else{
$upper = (int)$middle - 1;
}
}
}
}
?>
您可能感兴趣的文章: