您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

LZW压缩算法

2024/3/16 11:55:43发布15次查看
php实现的lzw压缩算法 (1 $bits++; } while ($rest_length > 7) { $rest_length -= 8; $return .= chr($rest >> $rest_length); $rest &= (1 } } return $return . ($rest_length ? chr($rest }/** lzw decompression* @param string compressed binary data* @return string original data*/function lzw_decompress($binary) { // convert binary string to codes $dictionary_count = 256; $bits = 8; // ceil(log($dictionary_count, 2)) $codes = array(); $rest = 0; $rest_length = 0; for ($i=0; $i $rest = ($rest $rest_length += 8; if ($rest_length >= $bits) { $rest_length -= $bits; $codes[] = $rest >> $rest_length; $rest &= (1 $dictionary_count++; if ($dictionary_count > (1 $bits++; } } } // decompression $dictionary = range(\0, \xff); $return = ; foreach ($codes as $i => $code) { $element = $dictionary[$code]; if (!isset($element)) { $element = $word . $word[0]; } $return .= $element; if ($i) { $dictionary[] = $word . $element[0]; } $word = $element; } return $return;}$data = ;$compressed = lzw_compress($data);var_dump($data === lzw_decompress($compressed));?>
复制代码
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product