#dictionary #relative #compressor #factor #text #static #input

rlz

Relative Lempel-Ziv (RLZ): a LZ based compressor against a large static dictionary

2 unstable releases

0.2.0 Sep 12, 2022
0.1.0 Sep 12, 2022

#324 in Compression

MIT license

58KB
1.5K SLoC

Relative-Lempel Ziv (RLZ) Crates.io Docs.rs MIT licensed

A Relative-Lempel Ziv (RLZ) based LZ compressor that compresses against a large static dictionary.

This code implements the RLZ compressor, as described in:

@article{DBLP:journals/pvldb/HoobinPZ11,
  author    = {Christopher Hoobin and
               Simon J. Puglisi and
               Justin Zobel},
  title     = {Relative Lempel-Ziv Factorization for Efficient Storage 
                and Retrieval of Web Collections},
  journal   = {Proc. {VLDB} Endow.},
  volume    = {5},
  number    = {3},
  pages     = {265--273},
  year      = {2011},
}
@article{DBLP:journals/corr/PetriMNW16,
  author    = {Matthias Petri and
               Alistair Moffat and
               P. C. Nagesh and
               Anthony Wirth},
  title     = {Access Time Tradeoffs in Archive Compression},
  journal   = {CoRR},
  volume    = {abs/1602.08829},
  year      = {2016},
  url       = {http://arxiv.org/abs/1602.08829},
  eprinttype = {arXiv},
}
@inproceedings{DBLP:conf/www/LiaoPMW16,
  author    = {Kewen Liao and
               Matthias Petri and
               Alistair Moffat and
               Anthony Wirth},
  title     = {Effective Construction of Relative Lempel-Ziv 
               Dictionaries},
  booktitle = {Proceedings of {WWW}},
  pages     = {807--816},
  publisher = {{ACM}},
  year      = {2016},
}

What is RLZ (taken from the paper)

The Relative Lempel-Ziv (RLZ) scheme is a hybrid of several phrase-based compression mechanisms. Encoding is based on a fixed-text dictionary, with all substrings within the dictionary available for use as factors, in the style of LZ77. But the dictionary is constructed in a semi-static manner, and hence needs to be representative of the entire text being coded if compression effectiveness is not to be compromised. Furthermore, because RLZ is intended for large web-based archives when constructing the dictionary, it is infeasible to have the whole input text in memory.

Usage

use rlz::RlzCompressor;
use rlz::Dictionary;

let dict = Dictionary::from(&b"banana"[..]);
let rlz_compressor = RlzCompressor::builder().build_from_dict(dict);

let mut output = Vec::new();

let text = b"banana$aba";
let encoded_len = rlz_compressor.encode(&text[..],&mut output).unwrap();
assert_eq!(encoded_len,output.len());

let mut stored_decoder = Vec::new();
rlz_compressor.store(&mut stored_decoder).unwrap();
let loaded_decoder = RlzCompressor::load(&stored_decoder[..]).unwrap();

let mut recovered = Vec::new();
loaded_decoder.decode(&output[..],&mut recovered).unwrap();
assert_eq!(recovered,text);

License

MIT

Dependencies

~5–11MB
~111K SLoC