Recently I was reading the book "Large Scale WEB Service Development Technology". The book mentions the data compression algorithm of "Variable Length Bytecode Algorithm" to compress data and reduce disk IO.
Variable length bytecode algorithm:
The highest bit of any byte (subscript 7) is only used as a flag bit, and it needs to be multiplied by the corresponding power of 128 according to the position of the byte;
This is his pseudo code
After careful study , I translated it into the PHP version:
<code><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><?php function codeNumber<span>(<span>$n</span>)</span>{ <span>$bytes</span> = []; while <span>(true)</span>{ array_unshift<span>(<span>$bytes</span>, bcmod<span>(<span>$n</span>, <span>128</span>)</span>)</span>; if<span>(<span>$n</span> 128</span>)</span>{ break; }else{ <span>$n</span> = intval<span>(<span>$n</span>/<span>128</span>)</span>; } } <span>$bytes</span>[count<span>(<span>$bytes</span>)</span> - <span>1</span>] += <span>128</span>; return <span>$bytes</span>; } function encode<span>(<span>$numbers</span>)</span>{ <span>$bytestream</span> = []; foreach <span>(<span>$numbers</span> as <span>$n</span>)</span>{ <span>$bytestream</span> = array_merge<span>(<span>$bytestream</span>, codeNumber<span>(<span>$n</span>)</span>)</span>; } return <span>$bytestream</span>; } function decode<span>(<span>$bytestream</span>)</span>{ <span>$numbers</span> = []; <span>$n</span> = <span>0</span>; for <span>(<span>$i</span> = <span>0</span>; <span>$i</span> (<span>$bytestream</span>)</span>; <span>$i</span>++)</span>{ if<span>(<span>$bytestream</span>[<span>$i</span>] 128</span>)</span>{ <span>$n</span> = <span>128</span> * <span>$n</span> + <span>$bytestream</span>[<span>$i</span>]; }else{ <span>$n</span> = <span>128</span> * <span>$n</span> + <span>(<span>$bytestream</span>[<span>$i</span>] - <span>128</span>)</span>; array_push<span>(<span>$numbers</span>, <span>$n</span>)</span>; <span>$n</span> = <span>0</span>; } } return <span>$numbers</span>; } <span>$a</span> = encode<span>([<span>5</span>, <span>130</span>, <span>288</span>])</span>; var_dump<span>(<span>$a</span>)</span>; var_dump<span>(decode<span>(<span>$a</span>)</span>)</span>; 打印出来的内容是: array<span>(<span>5</span>)</span> { [<span>0</span>]=> int<span>(<span>133</span>)</span> [<span>1</span>]=> string<span>(<span>1</span>)</span><span>"1"</span> [<span>2</span>]=> int<span>(<span>130</span>)</span> [<span>3</span>]=> string<span>(<span>1</span>)</span><span>"2"</span> [<span>4</span>]=> int<span>(<span>160</span>)</span> } array<span>(<span>3</span>)</span> { [<span>0</span>]=> int<span>(<span>5</span>)</span> [<span>1</span>]=> int<span>(<span>130</span>)</span> [<span>2</span>]=> int<span>(<span>288</span>)</span> } //写二进制 <span>$h</span> = fopen<span>(<span>'ejz3.txt'</span>, <span>'wb'</span>)</span>; foreach <span>(<span>$a</span> as <span>$k</span> => <span>$v</span>)</span> { <span>$str3</span> = pack<span>(<span>'H*'</span>, sprintf<span>(<span>"%02x"</span>, <span>$v</span>)</span>)</span>; fwrite<span>(<span>$h</span>, <span>$str3</span>)</span>; } fclose<span>(<span>$h</span>)</span>; //读二进制 <span>$str2</span> = file_get_contents<span>(<span>'ejz3.txt'</span>)</span>; <span>$str2</span> = unpack<span>(<span>"H*"</span>, <span>$str2</span>)</span>; <span>$value</span> = str_split<span>(<span>$str2</span>[<span>1</span>], <span>2</span>)</span>; foreach <span>(<span>$value</span> as <span>$k</span> => <span>$v</span>)</span> { <span>$value</span>[<span>$k</span>] = base_convert<span>(<span>$v</span>, <span>16</span>, <span>10</span>)</span>; } </span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
The above has introduced the variable length bytecode algorithm, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

这适用于想要执行手动激活的用户。如果需要帮助,为您执行此操作的工具,然后检查此处。我们可以将手动激活过程分为两部分。1-从现成的批处理文件确保已启用互联网。以管理员身份打开WindowsPowershell,然后输入以下内容按给出命令的顺序列出命令。输入密钥,(替换为密钥从上面的列表中)使用以下命令<key>slmgr/ipk<key>从这里下载通用门票并提取下载的文件。现在在Powershell中输入以下代码(Get-ItemProper

标题:C#中使用Array.Sort函数对数组进行排序的示例正文:在C#中,数组是一种常用的数据结构,经常需要对数组进行排序操作。C#提供了Array类,其中有Sort方法可以方便地对数组进行排序。本文将演示如何使用C#中的Array.Sort函数对数组进行排序,并提供具体的代码示例。首先,我们需要了解一下Array.Sort函数的基本用法。Array.So

在Go语言中,bytes包是一个用于操作字节类型的包,并且它包含了许多有用的方法,比如Split()方法。不过,在使用Split()方法时,你可能会遇到“undefined:bytes.Split”的错误。这种错误通常是由于Go版本不兼容或缺少必要的依赖库等原因引起的。这篇文章将介绍一些解决这种错误的方法。方法一:升级Go版本如

在进行PHP编程时,我们常常需要对数组进行合并。PHP提供了array_merge()函数来完成数组合并的工作,不过当数组中存在相同的键时,该函数会覆盖原有的值。为了解决这个问题,PHP在语言中还提供了一个array_merge_recursive()函数,该函数可以合并数组并保留相同键的值,使得程序的设计变得更加灵活。array_merge

在PHP中,有许多强大的数组函数可以使数组的操作更加方便和快捷。当我们需要将两个数组拼成一个关联数组时,可以使用PHP的array_combine函数来实现这一操作。这个函数实际上是用来将一个数组的键作为另一个数组的值,合并成一个新的关联数组。接下来,我们将会讲解如何使用PHP中的array_combine函数将两个数组拼成关联数组。了解array_comb

在PHP编程中,数组是一种非常重要的数据结构,能够轻松地处理大量数据。PHP中提供了许多数组相关的函数,array_fill()就是其中之一。本篇文章将详细介绍array_fill()函数的用法,以及在实际应用中的一些技巧。一、array_fill()函数概述array_fill()函数的作用是创建一个指定长度的、由相同的值组成的数组。具体来说,该函数的语法

Python中的array模块是一个预定义的数组,因此其在内存中占用的空间比标准列表小得多,同时也可以执行快速的元素级别操作,例如添加、删除、索引和切片等操作。此外,数组中的所有元素都是同一种类型,因此可以使用数组提供的高效数值运算函数,例如计算平均值、最大值和最小值等。另外,array模块还支持将数组对象直接写入和读取到二进制文件中,这使得在处理大量数值数据时更加高效。因此,如果您需要处理大量同质数据,可以考虑使用Python的array模块来优化代码的执行效率。要使用array模块,首先需要

在Java编程中,数组是一种重要的数据结构。数组可以在一个变量中存储多个值,更重要的是可以使用索引访问每个值。但是在使用数组时,可能会出现一些异常,其中之一是ArrayStoreException。本文将讨论ArrayStoreException异常的常见原因。1.类型不匹配数组在创建时必须指定元素类型。当我们试图将不兼容的数据类型存储到一个数组中时,就会抛


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor
