INTEGRATION: CWS res32bit (1.3.16); FILE MERGED

2004/10/26 09:53:47 pl 1.3.16.2: hash lowercase as before
2004/10/22 13:54:41 pl 1.3.16.1: #i34513# free rsc of 32 bit constraints
This commit is contained in:
Oliver Bolte 2005-01-03 16:31:09 +00:00
parent 5ad16c9d12
commit c2a7b3c9ad

View file

@ -2,9 +2,9 @@
*
* $RCSfile: rschash.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: hjs $ $Date: 2004-06-26 20:27:06 $
* last change: $Author: obo $ $Date: 2005-01-03 17:31:09 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -58,326 +58,45 @@
*
*
************************************************************************/
/****************** I N C L U D E S **************************************/
// C and C++ Includes.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
// Programmabh„ngige Includes.
#ifndef _RSCHASH_HXX
#include <rschash.hxx>
#endif
/****************** C O D E **********************************************/
/*************************************************************************
|*
|* HashTabel::HashTabel()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
HashTabel :: HashTabel( USHORT nMaxEntries ){
nMax = nMaxEntries; // set max entries
nFill = 0; // no entries
lTry = 0;
lAsk = 0;
}
using namespace rtl;
/*************************************************************************
|*
|* HashTabel::~HashTabel()
|*
|* Beschreibung
|* Ersterstellung MM 17.07.91
|* Letzte Aenderung MM 17.07.91
|*
*************************************************************************/
HashTabel :: ~HashTabel(){
#ifdef DOS
/*
printf( "Maximum: %d, Fuellung: %d\n", nMax, nFill );
printf( "Anfragen: %ld, Versuche: %ld", lAsk, lTry );
if( lTry != 0 )
printf( ", V/E = %ld\n", lTry / lAsk );
*/
#endif
}
/*************************************************************************
|*
|* HashTabel::Test_Insert()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
HASHID HashTabel::Test_Insert( const void * pElement, BOOL bInsert )
AtomContainer::AtomContainer()
{
USHORT nHash;
USHORT nIndex;
USHORT nLoop;
lAsk++;
lTry++;
nHash = HashFunc( pElement );
nIndex = nHash % nMax;
nLoop = 0; // divide to range
while( (nMax != nLoop) && IsEntry( nIndex ) )
{ // is place occupied
if( EQUAL == Compare( pElement, nIndex ) ) // is element in tabel
return( nIndex ); // place of Element
nLoop++;
lTry++;
nIndex = (USHORT)(nIndex + nHash + 7) % nMax;
}
if( bInsert )
{
if( nMax == nLoop ) // is tabel full
RscExit( 11 );
nFill++;
return( nIndex ); // return free place
}
return( HASH_NONAME );
m_aStringToID[ OString() ] = 0;
m_aIDToString[ 0 ] = OString();
m_nNextID = 1;
}
/*************************************************************************
|*
|* HashTabel::Test()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 15.05.91
|* Letzte Aenderung MM 15.05.91
|*
*************************************************************************/
HASHID HashTabel::Test( const void * pElement ){
return( Test_Insert( pElement, FALSE ) );
}
/*************************************************************************
|*
|* HashTabel::Insert()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
HASHID HashTabel::Insert( const void * pElement ){
// return free place in Tabel or the place, if Element is in the tabel
return( Test_Insert( pElement, TRUE ) );
}
/*************************************************************************
|*
|* HashString::HashString()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
HashString::HashString( USHORT nMaxEntries ) : HashTabel( nMaxEntries ){
if( (long)nMaxEntries * sizeof( char * ) >= 0x10000 ){
// can't allocate more then 64k - 1 Bytes
RscExit( 12 );
}
// allocate
ppStr = (char **)RscMem::Malloc( nMaxEntries * sizeof( char * ) );
memset( ppStr, 0, nMaxEntries * sizeof( char * ) );
paSC = new StringCon( (USHORT)40000 );
}
/*************************************************************************
|*
|* ~HashString::HashString()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 02.06.91
|* Letzte Aenderung MM 02.06.91
|*
*************************************************************************/
HashString::~HashString(){
delete paSC;
RscMem::Free( (void *)ppStr );
}
/*************************************************************************
|*
|* HashString::HashFunc()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
USHORT HashString :: HashFunc( const void * pElement ){
return( Hash_Func( pElement ));
}
USHORT HashString :: Hash_Func( const void * pElement ){
const char *pStr;
USHORT nHash = 0; // hash value
pStr = (const char *)pElement;
while( *pStr ){
nHash ^= toupper( *pStr ) - 'A';
if( *++pStr ){
nHash ^= (toupper( *pStr ) - 'A') << 4;
if( *++pStr )
nHash ^= (toupper( *pStr ) - 'A') << 8;
}
}
return( nHash );
}
/*************************************************************************
|*
|* HashString::IsEntry()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
BOOL HashString :: IsEntry( HASHID nIndex ){
// return TRUE if place is occupied
// return FALSE if place is FREE
// ppStr[ nIndex ] == pointer to stringtabel
return( NULL != ppStr[ nIndex ] );
}
/*************************************************************************
|*
|* HashString::Insert()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
HASHID HashString :: Insert( const char * pElement ){
HASHID nIndex;
nIndex = HashTabel::Insert( (const void *)pElement );
if( !IsEntry( nIndex ) )// is place not occupied ?
// put string in the string tabel
ppStr[ nIndex ] = paSC->Put( pElement );
return( nIndex );
}
/*************************************************************************
|*
|* HashString::Test()
|*
|* Beschreibung
|* Ersterstellung MM 05.11.91
|* Letzte Aenderung MM 05.11.91
|*
*************************************************************************/
HASHID HashString :: Test( const char * pElement ){
return HashTabel::Test( (const void *)pElement );
}
/*************************************************************************
|*
|* HashString::Get()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
char * HashString :: Get( HASHID nIndex ){
// return pointer to string
if( nIndex != HASH_NONAME )
return( ppStr[ nIndex ] );
else
return( NULL );
}
/*************************************************************************
|*
|* HashString::Get()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
COMPARE HashString :: Compare( const void * pElement, HASHID nIndex ){
short nCmp; // Vergleichsresultat
nCmp = rsc_stricmp( (const char *)pElement, ppStr[ nIndex ] );
if( 0 < nCmp )
return( GREATER );
else if( 0 == nCmp )
return( EQUAL );
else
return( LESS );
}
/*************************************************************************
|*
|* StringCon::StringCon()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
StringCon::StringCon( USHORT nMaxEntries ){
// allocate character field
pField = (char * )RscMem::Malloc( nMaxEntries );
nMax = nMaxEntries; // set maximum of characters
nFill = 0; // no character in tabel
}
/*************************************************************************
|*
|* StringCon::~StringCon()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 02.06.91
|* Letzte Aenderung MM 02.06.91
|*
*************************************************************************/
StringCon::~StringCon(){
// free character field
RscMem::Free( pField );
}
/*************************************************************************
|*
|* StringCon::Put()
|*
|* Beschreibung HASHTAB.DOC
|* Ersterstellung MM 20.03.90
|* Letzte Aenderung MM 27.06.90
|*
*************************************************************************/
char * StringCon :: Put( const char * pStr )
AtomContainer::~AtomContainer()
{
// put string into the tabel
char * pReturn = pField + nFill; // set return value
while( nMax > (USHORT)(nFill +1) && *pStr ) // strcpy in tabel
pField[ nFill++ ] = *pStr++;
if( nMax == nFill +1 ){ // buffer overflow ?
RscExit( 13 );
}
else
pField[ nFill++ ] = '\0'; // terminate with zero.
return( pReturn ); // return pointer to string
}
Atom AtomContainer::getID( const OString& rStr, bool bOnlyIfExists )
{
OString aKey = rStr.toAsciiLowerCase();
std::hash_map< OString, Atom, OStringHash >::const_iterator it =
m_aStringToID.find( aKey );
if( it != m_aStringToID.end() )
return it->second;
if( bOnlyIfExists )
return InvalidAtom;
Atom aRet = m_nNextID;
m_aStringToID[ aKey ] = m_nNextID;
m_aIDToString[ m_nNextID ] = rStr;
m_nNextID++;
return aRet;
}
const OString& AtomContainer::getString( Atom nAtom )
{
std::hash_map< Atom, OString >::const_iterator it =
m_aIDToString.find( nAtom );
return (it != m_aIDToString.end()) ? it->second : m_aIDToString[0];
}