Skip to Content
数据压缩入门
book

数据压缩入门

by Colt McAnlis, Aleks Haecky
April 2020
Intermediate to advanced
210 pages
4h 47m
Chinese
Posts & Telecom Press
Content preview from 数据压缩入门
序列化数据
165
13.3.2
 重构列表以获得更好的压缩
下面这点很有意思:当你对数据进行序列化时,其实大多数时间,你所做的只是将数据内
容映射为内存对象形式。我们来看看下面这段代码,想想左边的结构体是怎样序列化为右
边的
JSON
代码的。
struct { {
int id; "id": 25,
char* name; "name": "Hooty McOwlface",
int gender; "gender": 27,
int age; "age": 88,
char* address; "address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043"
int employeeID; "employeeID": 3025
} },
JSON
文件中属性的排序往往与内存中相应结构的表示相同,虽然这对程序员来说易于维
护,但是由此生成的整个结构的列表不能产生最好的压缩结果。
首先,由于
JSON
对象(可以随便选一个观察一分钟)是由键值对组成的,由于该结构体
的每个实例中都包含相同的属性,因此对整个文件来说包含大量的冗余信息。在下面这个
包含人名及国籍的列表中,对每个人都必须重复“
name
”和“
country
”这两个关键字。
...
{
"name": "Joanna",
"country": "USA"
}{
"name": "Alex",
"country": "AUS"
},
{
"name": "Colt",
"country": "USA"
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

解密金融数据

解密金融数据

Justin Pauley
人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar
神经网络算法与Java编程

神经网络算法与Java编程

Posts & Telecom Press, Fabio M. Soares, Alan M. F. Souza
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉

Publisher Resources

ISBN: 9787115534170