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

11
main.c
View file

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