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()
This commit is contained in:
Petr Chornyj
2010-12-11 20:58:21 +00:00
parent dabb1748d8
commit 5d7a5c376b
3 changed files with 80 additions and 13 deletions

View File

@@ -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.

View File

@@ -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 );
}

View File

@@ -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