fra*_*yer 7 ruby compression sqlite iphone
编辑:非常感谢所有的答案.以下是目前应用优化后的结果:
非常好的部分是这不需要在iphone代码中进行任何更改
我有一个iphone应用程序,其中包含一个以sqlite格式保存的大型字典(只读).我正在寻找减少DB文件大小的想法,目前这个文件非常大.
以下是sqlite DB的条目数和结果大小:
franks-macbook:DictionaryMaker frank$ ls -lh dictionary.db
-rw-r--r-- 1 frank staff 59M 8 Oct 23:08 dictionary.db
franks-macbook:DictionaryMaker frank$ wc -l dictionary.txt
453154 dictionary.txt
Run Code Online (Sandbox Code Playgroud)
...每个条目平均大约135个字节.
这是我的数据库架构:
create table words (word text primary key, sowpods boolean, twl boolean, signature text)
create index sowpods_idx on words(sowpods)
create index twl_idx on words(twl)
create index signature_idx on words(signature)
Run Code Online (Sandbox Code Playgroud)
以下是一些示例数据:
photoengrave|1|1|10002011000001210101010000
photoengraved|1|1|10012011000001210101010000
photoengraver|1|1|10002011000001210201010000
photoengravers|1|1|10002011000001210211010000
photoengraves|1|1|10002011000001210111010000
photoengraving|1|1|10001021100002210101010000
Run Code Online (Sandbox Code Playgroud)
最后一个字段表示字谜检索的字母频率(每个位置在0..9范围内).两个布尔代表子词典.
我需要做以下的查询:
select signature from words where word = 'foo'
select word from words where signature = '10001021100002210101010000' order by word asc
select word from words where word like 'foo' order by word asc
select word from words where word = 'foo' and (sowpods='1' or twl='1')
Run Code Online (Sandbox Code Playgroud)
我的一个想法是更有效地编码字母频率,例如将它们二进制编码为blob(可能有RLE,因为有很多零?).有关如何最好地实现这一点的想法,或其他减少尺寸的想法?我正在用ruby构建数据库,并在目标C中通过电话阅读它.
还有什么方法可以获得数据库的统计数据,所以我可以看到什么是使用最多的空间?
| 归档时间: |
|
| 查看次数: |
11223 次 |
| 最近记录: |