2011-10-14 10:42 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/include/hbapicdp.h
  * harbour/src/rtl/cdpapi.c
    - removed hb_cdpchrcmp() function and HB_CDP_ISBYTESORT() macro
    + added new function:
         const HB_UCHAR * hb_cdpGetSortTab( PHB_CODEPAGE cdp );
      it returns binary sort table or NULL if given CP uses more
      complicated sorting algorithm.

  * harbour/include/hbrddcdx.h
  * harbour/src/rdd/dbfcdx/dbfcdx1.c
    % use hb_cdpGetSortTab() to take binary sort table used by WA CP
      instead of creating new one for each WA.
This commit is contained in:
Przemyslaw Czerpak
2011-10-14 08:43:06 +00:00
parent d020e94ac5
commit 593b446a6a
5 changed files with 40 additions and 83 deletions

View File

@@ -16,6 +16,20 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-10-14 10:42 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbapicdp.h
* harbour/src/rtl/cdpapi.c
- removed hb_cdpchrcmp() function and HB_CDP_ISBYTESORT() macro
+ added new function:
const HB_UCHAR * hb_cdpGetSortTab( PHB_CODEPAGE cdp );
it returns binary sort table or NULL if given CP uses more
complicated sorting algorithm.
* harbour/include/hbrddcdx.h
* harbour/src/rdd/dbfcdx/dbfcdx1.c
% use hb_cdpGetSortTab() to take binary sort table used by WA CP
instead of creating new one for each WA.
2011-10-14 02:34 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* ChangeLog
! accented char in my prev commit

View File

@@ -376,7 +376,6 @@ extern HB_EXPORT void hb_vmSetCDP( PHB_CODEPAGE pCDP );
#define HB_CDP_ENDIAN_BIG 2
#define HB_CDP_ISBINSORT(cdp) ( ( cdp )->sort == NULL )
#define HB_CDP_ISBYTESORT(cdp) ( ( cdp )->nMulti == 0 && ( cdp )->nACSort == 0 )
extern HB_EXPORT HB_BOOL hb_cdpRegisterRaw( PHB_CODEPAGE cdp );
extern HB_EXPORT HB_BOOL hb_cdpRegisterNew( const char * id,
@@ -401,7 +400,7 @@ extern HB_EXPORT HB_BOOL hb_cdpIsLower( PHB_CODEPAGE cdp, int iChar );
extern HB_EXPORT HB_BOOL hb_cdpIsUpper( PHB_CODEPAGE cdp, int iChar );
extern HB_EXPORT int hb_cdpcmp( const char * szFirst, HB_SIZE nLenFirst, const char * szSecond, HB_SIZE nLenSecond, PHB_CODEPAGE cdp, HB_BOOL fExact );
extern HB_EXPORT int hb_cdpicmp( const char * szFirst, HB_SIZE nLenFirst, const char * szSecond, HB_SIZE nLenSecond, PHB_CODEPAGE cdp, HB_BOOL fExact );
extern HB_EXPORT int hb_cdpchrcmp( char cFirst, char cSecond, PHB_CODEPAGE cdp );
extern HB_EXPORT const HB_UCHAR * hb_cdpGetSortTab( PHB_CODEPAGE cdp );
extern HB_EXPORT char * hb_cdpDup( const char *, PHB_CODEPAGE, PHB_CODEPAGE );
extern HB_EXPORT char * hb_cdpnDup( const char *, HB_SIZE *, PHB_CODEPAGE, PHB_CODEPAGE );

View File

@@ -463,7 +463,7 @@ typedef struct _CDXAREA
LPCDXSORTINFO pSort; /* Index build structure */
LPCDXINDEX lpIndexes; /* Pointer to indexes array */
HB_BYTE * bCdxSortTab; /* Table with sorted characters */
const HB_UCHAR * sortTab; /* Table with sorted characters */
HB_BOOL fCdxAppend; /* Appended record changed */
HB_BOOL fSortCDP; /* Use CDP functions for sorting */
HB_USHORT uiTag; /* current tag focus */

View File

@@ -227,41 +227,11 @@ static void hb_cdxMakeSortTab( CDXAREAP pArea )
{
if( pArea->dbfarea.area.cdPage &&
!HB_CDP_ISBINSORT( pArea->dbfarea.area.cdPage ) &&
!( pArea->fSortCDP || pArea->bCdxSortTab ) )
!( pArea->fSortCDP || pArea->sortTab ) )
{
if( !HB_CDP_ISBYTESORT( pArea->dbfarea.area.cdPage ) )
pArea->sortTab = hb_cdpGetSortTab( pArea->dbfarea.area.cdPage );
if( !pArea->sortTab )
pArea->fSortCDP = HB_TRUE;
else
{
int i, j, l;
HB_BYTE * pbSort;
HB_BYTE b;
pArea->bCdxSortTab = ( HB_BYTE * ) hb_xgrab( 256 );
pbSort = ( HB_BYTE * ) hb_xgrab( 256 );
/* this table should be allready quite good sorted so this simple
algorithms is one of the most efficient one. */
for( i = 0; i <= 255; i++ )
pbSort[i] = ( HB_BYTE ) i;
l = 255;
do
{
j = l;
for( i = 0; i < j; i++ )
{
if( hb_cdpchrcmp( pbSort[i], pbSort[i+1], pArea->dbfarea.area.cdPage ) > 0 )
{
b = pbSort[i+1];
pbSort[i+1] = pbSort[i];
pbSort[i] = b;
l = i;
}
}
} while( j != l );
for( i = 0; i <= 255; i++ )
pArea->bCdxSortTab[ pbSort[i] ] = ( HB_BYTE ) i;
hb_xfree( pbSort );
}
}
}
@@ -395,26 +365,29 @@ static int hb_cdxValCompare( LPCDXTAG pTag, const HB_BYTE * val1, int len1,
if( pTag->uiType == 'C' )
{
if( pTag->pIndex->pArea->bCdxSortTab )
if( iLimit > 0 )
{
HB_BYTE * pSort = pTag->pIndex->pArea->bCdxSortTab;
int iPos = 0;
while( iPos < iLimit )
if( pTag->pIndex->pArea->sortTab )
{
iResult = pSort[ val1[ iPos ] ] - pSort[ val2[ iPos ] ];
if( iResult != 0 )
break;
iPos++;
const HB_UCHAR * sortTab = pTag->pIndex->pArea->sortTab;
int iPos = 0;
while( iPos < iLimit )
{
iResult = sortTab[ val1[ iPos ] ] - sortTab[ val2[ iPos ] ];
if( iResult != 0 )
break;
iPos++;
}
}
else if( pTag->pIndex->pArea->fSortCDP )
{
return - hb_cdpcmp( ( const char * ) val2, ( HB_SIZE ) len2,
( const char * ) val1, ( HB_SIZE ) len1,
pTag->pIndex->pArea->dbfarea.area.cdPage, 0 );
}
else
iResult = memcmp( val1, val2, iLimit );
}
else if( pTag->pIndex->pArea->fSortCDP )
{
return - hb_cdpcmp( ( const char * ) val2, ( HB_SIZE ) len2,
( const char * ) val1, ( HB_SIZE ) len1,
pTag->pIndex->pArea->dbfarea.area.cdPage, 0 );
}
else if( iLimit > 0 )
iResult = memcmp( val1, val2, iLimit );
if( iResult == 0 )
{
@@ -7019,11 +6992,6 @@ static HB_ERRCODE hb_cdxClose( CDXAREAP pArea )
}
hb_cdxOrdListClear( pArea, HB_TRUE, NULL );
if( pArea->bCdxSortTab )
{
hb_xfree( pArea->bCdxSortTab );
pArea->bCdxSortTab = NULL;
}
#ifdef HB_CDX_DBGTIME
printf( "\r\ncdxTimeIntBld=%f, cdxTimeExtBld=%f, cdxTimeBld=%f\r\n"
"cdxTimeGetKey=%f, cdxTimeFreeKey=%f\r\n"

View File

@@ -557,33 +557,9 @@ char * hb_strUpper( char * szText, HB_SIZE nLen )
/*
* comparison
*/
int hb_cdpchrcmp( char cFirst, char cSecond, PHB_CODEPAGE cdp )
const HB_UCHAR * hb_cdpGetSortTab( PHB_CODEPAGE cdp )
{
if( cFirst == cSecond )
return 0;
if( cdp->sort )
{
int n1 = cdp->sort[ ( HB_UCHAR ) cFirst ],
n2 = cdp->sort[ ( HB_UCHAR ) cSecond ];
if( cdp->nMulti == 0 || ( n1 != 0 && n2 != 0 ) )
{
if( n1 == n2 )
{
if( cdp->acc )
{
n1 = cdp->acc[ ( HB_UCHAR ) cFirst ];
n2 = cdp->acc[ ( HB_UCHAR ) cSecond ];
}
else
return 0;
}
return ( n1 < n2 ) ? -1 : 1;
}
}
return ( ( HB_UCHAR ) cFirst < ( HB_UCHAR ) cSecond ) ? -1 : 1;
return ( cdp->nMulti == 0 && cdp->nACSort == 0 ) ? cdp->sort : NULL;
}
static int hb_cdpMultiWeight( PHB_CODEPAGE cdp, const char * szChar )