diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f25f02ce66..1ad49096e8 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,12 @@ The license applies to all entries newer than 2009-04-28. */ +2010-12-11 22:55 UTC+0200 Petr Chornyj (myorg63 at mail.ru) + * contrib/hblzf/hblzf.c + ! Fixed the algorithm used in HB_LZF_COMPRESSBOUND(), HB_LZF_COMPRESS() + + contrib/hblzf/tests/test2.prg + + added yet another simple test for HB_LZF_[DE]COMPRESS() + 2010-12-11 18:33 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * config/hbc.cfg + More adjustment for Harbour. diff --git a/harbour/contrib/hblzf/hblzf.c b/harbour/contrib/hblzf/hblzf.c index 4490089fe3..e71a253a10 100644 --- a/harbour/contrib/hblzf/hblzf.c +++ b/harbour/contrib/hblzf/hblzf.c @@ -62,6 +62,23 @@ #include "hblzf.ch" +static HB_SIZE hb_lzf_compressbound( HB_SIZE nLen ) +{ + HB_SIZE nBuffSize = ( HB_SIZE ) ( nLen * 1.04 + 1 ); + return ( nBuffSize >= 32 ) ? nBuffSize : 32; +} + +HB_FUNC( HB_LZF_COMPRESSBOUND ) +{ + if( HB_ISCHAR( 1 ) || HB_ISNUM( 1 ) ) + { + HB_SIZE nLen = HB_ISCHAR( 1 ) ? hb_parclen( 1 ) : ( HB_SIZE ) hb_parns( 1 ); + hb_retns( hb_lzf_compressbound( nLen ) ); + } + else + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + /* Return a LZF_VERSION, API version */ HB_FUNC( HB_LZF_VERSION ) { @@ -78,17 +95,6 @@ HB_FUNC( HB_LZF_OPTIMIZED_FOR_SPEED ) #endif } -HB_FUNC( HB_LZF_COMPRESSBOUND ) -{ - if( HB_ISCHAR( 1 ) || HB_ISNUM( 1 ) ) - { - HB_SIZE nLen = HB_ISCHAR( 1 ) ? hb_parclen( 1 ) : hb_parns( 1 ); - hb_retns( ( HB_SIZE ) ( nLen * 1.04 + 1 ) ); - } - else - hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); -} - /* Return a string compressed with LZF */ HB_FUNC( HB_LZF_COMPRESS ) { @@ -113,8 +119,8 @@ HB_FUNC( HB_LZF_COMPRESS ) else { out_len = ( HB_ISNUM( 2 ) && hb_parns( 2 ) >= 0 ) ? - hb_parns( 2 ) : - ( HB_SIZE ) ( in_len * 1.04 + 1 ); + ( HB_SIZE ) hb_parns( 2 ) : + hb_lzf_compressbound( in_len ); out_data = ( char * ) hb_xalloc( out_len + 1 ); } diff --git a/harbour/contrib/hblzf/tests/test2.prg b/harbour/contrib/hblzf/tests/test2.prg new file mode 100644 index 0000000000..05514348ba --- /dev/null +++ b/harbour/contrib/hblzf/tests/test2.prg @@ -0,0 +1,55 @@ +/* + * $Id: test2.prg 14179 2010-12-08 23:34:33Z petr_ch $ + */ + +/* hbmk2 testz.prg -lhbbz2 -lbz2 -lhblzf -llzf -es2 -w3 */ + +#include "simpleio.ch" + +#define _NREPL_ 50 + +PROCEDURE Main() + LOCAL cStr := Replicate( hb_memoRead( hb_argv( 0 ) ), _NREPL_ ) + LOCAL aCompressedData := { NIL, NIL, NIL, NIL } + LOCAL hFuncs := { ; + "GZIP" => @hb_gzCompress(), ; + "ZLIB" => @hb_zCompress(), ; + "BZ2 " => @hb_bz2_compress(), ; + "LZF " => @hb_lzf_compress(); + } + LOCAL hFuncs2 := { ; + "GZIP" => @hb_zUncompress(), ; + "ZLIB" => @hb_zUncompress(), ; + "BZ2 " => @hb_bz2_uncompress(), ; + "LZF " => @hb_lzf_decompress(); + } + + MakeTest( @hFuncs, @aCompressedData, @cStr ) + MakeTest( @hFuncs2, @aCompressedData ) + + RETURN + +STATIC PROCEDURE MakeTest( ... ) + LOCAL e, e2, cRes, cFmt + LOCAL nResult := 0 + LOCAL nBegin, nEnd + LOCAL lCmp := ( PCount() > 2 ) + + FOR EACH e, e2 IN hb_pValue( 1 ), hb_pValue( 2 ) + nBegin := hb_secondsCPU() + cRes := Eval( e:__enumValue(), iif( lCmp, hb_pValue( 3 ), e2 ), NIL, @nResult ) + nEnd := hb_secondsCPU() + IF lCmp + e2 := cRes + ENDIF + cFmt := hb_strFormat( ; + "%s: %d -> %d, Ratio %.2f%%, Times %.2f", ; + e:__enumKey(), ; + Len( IIf( lCmp, hb_pValue( 3 ), e2 ) ), Len( cRes ), ; + ( Len( cRes ) / Len( IIf( lCmp, hb_pValue( 3 ), e2 ) ) ) * 100, ; + nEnd - nBegin; + ) + ? cFmt + NEXT + ? + RETURN