Change adaptive modes.

This commit is contained in:
Moinak Ghosh 2012-06-01 22:04:08 +05:30
parent e46d3d10b3
commit 7e9f636f8d
2 changed files with 29 additions and 32 deletions

View file

@ -143,7 +143,7 @@ adapt_compress(void *src, size_t srclen, void *dst,
int rv, rv1, rv2;
unsigned int *inc;
size_t dst2len, dst3len, smaller_dstlen;
uchar_t *dst2, *smaller_dst, *larger_dst;
uchar_t *dst2, *smaller_dst;
void *tmp;
dst2 = slab_alloc(NULL, *dstlen);
@ -152,37 +152,35 @@ adapt_compress(void *src, size_t srclen, void *dst,
return (-1);
}
rv = COMPRESS_LZMA;
inc = &lzma_count;
rv = COMPRESS_PPMD;
inc = &ppmd_count;
dst2len = *dstlen;
dst3len = *dstlen;
rv1 = bzip2_compress(src, srclen, dst2, &dst2len, level, data);
if (rv1 < 0) dst2len = dst3len;
rv2 = lzma_compress(src, srclen, dst, dstlen, level, adat->lzma_data);
if (rv2 < 0) *dstlen = dst3len;
if (dst2len < *dstlen) {
rv = COMPRESS_BZIP2;
larger_dst = dst;
smaller_dstlen = dst2len;
smaller_dst = dst2;
inc = &bzip2_count;
} else {
larger_dst = dst2;
smaller_dstlen = *dstlen;
smaller_dst = dst;
}
rv1 = ppmd_compress(src, srclen, dst, dstlen, level, adat->ppmd_data);
if (rv1 < 0) *dstlen = dst3len;
if (adat->adapt_mode == 2) {
rv2 = ppmd_compress(src, srclen, larger_dst, &dst2len,
level, adat->ppmd_data);
rv2 = lzma_compress(src, srclen, dst2, &dst2len, level, adat->lzma_data);
if (rv2 < 0) dst2len = dst3len;
if (dst2len < smaller_dstlen) {
rv = COMPRESS_PPMD;
smaller_dstlen = dst2len;
smaller_dst = larger_dst;
inc = &ppmd_count;
if (dst2len < *dstlen) {
inc = &lzma_count;
rv = COMPRESS_LZMA;
}
} else {
rv2 = bzip2_compress(src, srclen, dst2, &dst2len, level, NULL);
if (rv2 < 0) dst2len = dst3len;
if (dst2len < *dstlen) {
inc = &bzip2_count;
rv = COMPRESS_BZIP2;
}
}
if (dst2len < *dstlen) {
smaller_dstlen = dst2len;
smaller_dst = dst2;
} else {
smaller_dstlen = *dstlen;
smaller_dst = dst;
}
*inc += 1;

11
main.c
View file

@ -95,13 +95,12 @@ usage(void)
" bzip2 - Bzip2 Algorithm from libbzip2.\n"
" ppmd - The PPMd algorithm excellent for textual data. PPMd requires\n"
" at least 64MB X CPUs more memory than the other modes.\n"
" adapt - Adaptive mode where lzma or bzip2 will be used per chunk,\n"
" adapt - Adaptive mode where ppmd or bzip2 will be used per chunk,\n"
" depending on which one produces better compression. This mode\n"
" is obviously fairly slow and requires double the memory of\n"
" standalone bzip2 or lzma modes.\n"
" adapt2 - Adaptive mode which includes lzma, bzip2 and ppmd. This requires\n"
" even more memory than adapt mode, is more slower and potentially\n"
" produces the best compression.\n"
" is obviously fairly slow and requires lots of memory.\n"
" adapt2 - Adaptive mode which includes ppmd and lzma. This requires\n"
" more memory than adapt mode, is slower and potentially gives\n"
" the best compression.\n"
" <chunk_size> - This can be in bytes or can use the following suffixes:\n"
" g - Gigabyte, m - Megabyte, k - Kilobyte.\n"
" Larger chunks produce better compression at the cost of memory.\n"