summaryrefslogtreecommitdiff
path: root/rsc
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2005-01-03 16:31:09 +0000
committerOliver Bolte <obo@openoffice.org>2005-01-03 16:31:09 +0000
commitc2a7b3c9ad105f664c3d46eba5cec42572f23593 (patch)
tree43dc01adfb731ec78a94ebaa0c33947f44b943e2 /rsc
parent5ad16c9d127e311709de7a18e198b25710104502 (diff)
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
Diffstat (limited to 'rsc')
-rw-r--r--rsc/source/tools/rschash.cxx335
1 files changed, 27 insertions, 308 deletions
diff --git a/rsc/source/tools/rschash.cxx b/rsc/source/tools/rschash.cxx
index 6020e503e501..2ecba5abfa92 100644
--- a/rsc/source/tools/rschash.cxx
+++ b/rsc/source/tools/rschash.cxx
@@ -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>
-// Programmabhngige 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 );
-}
-
-/*************************************************************************
-|*
-|* 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 );
+ m_aStringToID[ OString() ] = 0;
+ m_aIDToString[ 0 ] = OString();
+ m_nNextID = 1;
}
-/*************************************************************************
-|*
-|* 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 );
+AtomContainer::~AtomContainer()
+{
}
-/*************************************************************************
-|*
-|* 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 );
+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;
- nMax = nMaxEntries; // set maximum of characters
- nFill = 0; // no character in tabel
-}
+ if( bOnlyIfExists )
+ return InvalidAtom;
-/*************************************************************************
-|*
-|* StringCon::~StringCon()
-|*
-|* Beschreibung HASHTAB.DOC
-|* Ersterstellung MM 02.06.91
-|* Letzte Aenderung MM 02.06.91
-|*
-*************************************************************************/
-StringCon::~StringCon(){
- // free character field
- RscMem::Free( pField );
+ Atom aRet = m_nNextID;
+ m_aStringToID[ aKey ] = m_nNextID;
+ m_aIDToString[ m_nNextID ] = rStr;
+ m_nNextID++;
+ return aRet;
}
-/*************************************************************************
-|*
-|* StringCon::Put()
-|*
-|* Beschreibung HASHTAB.DOC
-|* Ersterstellung MM 20.03.90
-|* Letzte Aenderung MM 27.06.90
-|*
-*************************************************************************/
-char * StringCon :: Put( const char * pStr )
+const OString& AtomContainer::getString( Atom nAtom )
{
-// 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
+ std::hash_map< Atom, OString >::const_iterator it =
+ m_aIDToString.find( nAtom );
+ return (it != m_aIDToString.end()) ? it->second : m_aIDToString[0];
}