summaryrefslogtreecommitdiff
path: root/idl/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2016-12-15 13:44:21 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2016-12-19 06:05:47 +0000
commitf9a97a5d5aca8473845bca2e17c5826b772b8f3c (patch)
tree580cb178cdcd8b3189afa8ebdf88346490467bcf /idl/source
parentf9fd6390cd88b87ca81538385da028ff5b1783c0 (diff)
drop custom hashtable implementation in idl
Change-Id: I2cdb79022e77cdcc03962d392d0d87626a090ac5 Reviewed-on: https://gerrit.libreoffice.org/32043 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'idl/source')
-rw-r--r--idl/source/cmptools/hash.cxx165
-rw-r--r--idl/source/prj/command.cxx2
-rw-r--r--idl/source/prj/database.cxx16
3 files changed, 29 insertions, 154 deletions
diff --git a/idl/source/cmptools/hash.cxx b/idl/source/cmptools/hash.cxx
index 76976b4bf3d9..17a5f25c5ed0 100644
--- a/idl/source/cmptools/hash.cxx
+++ b/idl/source/cmptools/hash.cxx
@@ -27,164 +27,47 @@
#include <tools/debug.hxx>
#include <rtl/character.hxx>
+#include <o3tl/make_unique.hxx>
-SvHashTable::SvHashTable( sal_uInt32 nMaxEntries )
+SvStringHashEntry * SvStringHashTable::Insert( const OString& rElement, sal_uInt32 * pInsertPos )
{
- nMax = nMaxEntries; // set max entries
- nFill = 0; // no entries
- lTry = 0;
- lAsk = 0;
-}
-
-SvHashTable::~SvHashTable()
-{
-}
-
-bool SvHashTable::Test_Insert( const OString& rElement, bool bInsert,
- sal_uInt32 * pInsertPos )
-{
- sal_uInt32 nHash;
- sal_uInt32 nIndex;
- sal_uInt32 nLoop;
-
- lAsk++;
- lTry++;
-
- nHash = HashFunc( rElement );
- nIndex = nHash % nMax;
-
- nLoop = 0; // divide to range
- while( (nMax != nLoop) && IsEntry( nIndex ) )
- { // is place occupied
- if( equals( rElement, nIndex ) )
- {
- if( pInsertPos )
- *pInsertPos = nIndex; // place of Element
- return true;
- }
- nLoop++;
- lTry++;
- nIndex = (sal_uInt16)(nIndex + nHash + 7) % nMax;
- }
-
- if( bInsert )
- {
- DBG_ASSERT( nMax != nLoop, "Hash table full" );
- if( nMax != nLoop )
- {
- nFill++;
- *pInsertPos = nIndex; // return free place
- return true;
- }
+ auto it = maString2IntMap.find(rElement);
+ if (it != maString2IntMap.end()) {
+ *pInsertPos = it->second;
+ return maInt2EntryMap[*pInsertPos].get();
}
- return false;
+ maString2IntMap[rElement] = mnNextId;
+ maInt2EntryMap[mnNextId] = o3tl::make_unique<SvStringHashEntry>(rElement);
+ *pInsertPos = mnNextId;
+ mnNextId++;
+ return maInt2EntryMap[*pInsertPos].get();
}
-SvStringHashTable::SvStringHashTable( sal_uInt32 nMaxEntries )
- : SvHashTable( nMaxEntries )
+bool SvStringHashTable::Test( const OString& rElement, sal_uInt32 * pInsertPos )
{
- pEntries = new SvStringHashEntry[ nMaxEntries ];
-
- // set RefCount to one
- SvStringHashEntry * pPos, *pEnd;
- pPos = pEntries;
- pEnd = pEntries + nMaxEntries;
- while( pPos != pEnd )
- {
- pPos->AddFirstRef();
- pPos++;
+ auto it = maString2IntMap.find(rElement);
+ if (it != maString2IntMap.end()) {
+ *pInsertPos = it->second;
+ return true;
}
+ return false;
}
-SvStringHashTable::~SvStringHashTable()
+SvStringHashEntry * SvStringHashTable::Get( sal_uInt32 nInsertPos ) const
{
-#ifdef DBG_UTIL
- // set RefCount to one
- SvStringHashEntry * pPos, *pEnd;
- pPos = pEntries;
- pEnd = pEntries + GetMax();
- while( pPos != pEnd )
- {
- DBG_ASSERT( pPos->GetRefCount() == 1, "Reference count != 1" );
- pPos++;
- }
-#endif
-
- delete [] pEntries;
-}
-
-sal_uInt32 SvStringHashTable::HashFunc( const OString& rElement ) const
-{
- sal_uInt32 nHash = 0; // hash value
- const char * pStr = rElement.getStr();
-
- int nShift = 0;
- while( *pStr )
- {
- if( rtl::isAsciiUpperCase( *pStr ) )
- nHash ^= sal_uInt32(*pStr - 'A' + 26) << nShift;
- else
- nHash ^= sal_uInt32(*pStr - 'a') << nShift;
- if( nShift == 28 )
- nShift = 0;
- else
- nShift += 4;
- pStr++;
- }
- return nHash;
+ auto it = maInt2EntryMap.find(nInsertPos);
+ return it->second.get();
}
OString SvStringHashTable::GetNearString( const OString& rName ) const
{
- for( sal_uInt32 i = 0; i < GetMax(); i++ )
+ for( auto const & rPair : maInt2EntryMap )
{
- SvStringHashEntry * pE = Get( i );
- if( pE )
- {
- if( pE->GetName().equalsIgnoreAsciiCase( rName ) && !pE->GetName().equals( rName ) )
- return pE->GetName();
- }
+ SvStringHashEntry * pE = rPair.second.get();
+ if( pE->GetName().equalsIgnoreAsciiCase( rName ) && !pE->GetName().equals( rName ) )
+ return pE->GetName();
}
return OString();
}
-bool SvStringHashTable::IsEntry( sal_uInt32 nIndex ) const
-{
- if( nIndex >= GetMax() )
- return false;
- return pEntries[ nIndex ].HasId();
-}
-
-bool SvStringHashTable::Insert( const OString& rName, sal_uInt32 * pIndex )
-{
- sal_uInt32 nIndex;
-
- if( !pIndex ) pIndex = &nIndex;
-
- if( !SvHashTable::Test_Insert( rName, true, pIndex ) )
- return false;
-
- if( !IsEntry( *pIndex ) )
- pEntries[ *pIndex ] = SvStringHashEntry( rName );
- return true;
-}
-
-bool SvStringHashTable::Test( const OString& rName, sal_uInt32 * pPos ) const
-{
- return const_cast<SvStringHashTable*>(this)->Test_Insert( rName, false, pPos );
-}
-
-SvStringHashEntry * SvStringHashTable::Get( sal_uInt32 nIndex ) const
-{
- if( IsEntry( nIndex ) )
- return pEntries + nIndex;
- return nullptr;
-}
-
-bool SvStringHashTable::equals( const OString& rElement,
- sal_uInt32 nIndex ) const
-{
- return rElement.equals( pEntries[ nIndex ].GetName() );
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/idl/source/prj/command.cxx b/idl/source/prj/command.cxx
index 54e23ab53b32..057c49505a1e 100644
--- a/idl/source/prj/command.cxx
+++ b/idl/source/prj/command.cxx
@@ -110,7 +110,7 @@ char CommandLineSyntax[] =
void Init()
{
if( !GetIdlApp().pHashTable )
- GetIdlApp().pHashTable = new SvStringHashTable( 2801 );
+ GetIdlApp().pHashTable = new SvStringHashTable;
if( !GetIdlApp().pGlobalNames )
GetIdlApp().pGlobalNames = new SvGlobalHashNames();
}
diff --git a/idl/source/prj/database.cxx b/idl/source/prj/database.cxx
index 2b45e6e157e2..15c21a388fbf 100644
--- a/idl/source/prj/database.cxx
+++ b/idl/source/prj/database.cxx
@@ -125,18 +125,13 @@ bool SvIdlDataBase::FindId( const OString& rIdName, sal_uLong * pVal )
return false;
}
-bool SvIdlDataBase::InsertId( const OString& rIdName, sal_uLong nVal )
+void SvIdlDataBase::InsertId( const OString& rIdName, sal_uLong nVal )
{
if( !pIdTable )
- pIdTable = new SvStringHashTable( 20003 );
+ pIdTable = new SvStringHashTable;
sal_uInt32 nHash;
- if( pIdTable->Insert( rIdName, &nHash ) )
- {
- pIdTable->Get( nHash )->SetValue( nVal );
- return true;
- }
- return false;
+ pIdTable->Insert( rIdName, &nHash )->SetValue( nVal );
}
bool SvIdlDataBase::ReadIdFile( const OString& rOFileName )
@@ -211,10 +206,7 @@ bool SvIdlDataBase::ReadIdFile( const OString& rOFileName )
}
if( bOk )
{
- if( !InsertId( aDefName, nVal ) )
- {
- throw SvParseException( "hash table overflow: ", rTok );
- }
+ InsertId( aDefName, nVal );
}
}
else if( rTok.Is( SvHash_include() ) )