From 5c7cf31fc827f99b015c94c90f7e6eeac397c628 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov <borisk@apache.org> Date: Thu, 24 Jul 2008 10:28:29 +0000 Subject: [PATCH] Port other hash tables not to use HashBase interface. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@679340 13f79535-47bb-0310-9956-ffa450edef68 --- doc/Doxyfile | 5 +- .../XercesLib/XercesLib.xcode/project.pbxproj | 42 +--- .../BCB6/Xerces-all/XercesLib/XercesLib.bpr | 4 - .../MemHandlerTest/MemHandlerTest.mak | 2 +- .../Xerces-all/XercesLib/XercesLib.mak | 2 - .../MemHandlerTest/MemHandlerTest.dsp | 8 - .../MemHandlerTest/MemHandlerTest.mak | 15 -- .../VC6/xerces-all/XercesLib/XercesLib.dsp | 22 +-- .../VC6/xerces-all/XercesLib/XercesLib.mak | 28 --- .../MemHandlerTest/MemHandlerTest.vcproj | 6 - .../xerces-all/XercesLib/XercesLib.vcproj | 17 +- .../MemHandlerTest/MemHandlerTest.vcproj | 8 - .../VC8/xerces-all/XercesLib/XercesLib.vcproj | 22 +-- .../MemHandlerTest/MemHandlerTest.vcproj | 8 - .../VC9/xerces-all/XercesLib/XercesLib.vcproj | 22 +-- src/Makefile.am | 7 +- src/xercesc/dom/impl/DOMDeepNodeListPool.c | 102 +++++----- src/xercesc/dom/impl/DOMDeepNodeListPool.hpp | 34 +--- src/xercesc/dom/impl/DOMDocumentImpl.cpp | 7 +- src/xercesc/dom/impl/DOMDocumentImpl.hpp | 2 +- src/xercesc/internal/DGXMLScanner.cpp | 1 - src/xercesc/internal/IGXMLScanner.cpp | 1 - src/xercesc/internal/SGXMLScanner.cpp | 1 - src/xercesc/internal/XMLScanner.hpp | 2 +- src/xercesc/internal/XSObjectFactory.cpp | 1 - src/xercesc/internal/XSerializeEngine.cpp | 2 - src/xercesc/internal/XTemplateSerializer.cpp | 1 - src/xercesc/util/HashBase.hpp | 74 ------- src/xercesc/util/HashCMStateSet.hpp | 77 -------- src/xercesc/util/HashPtr.cpp | 40 ---- src/xercesc/util/HashPtr.hpp | 54 ------ src/xercesc/util/HashXMLCh.cpp | 41 ---- src/xercesc/util/HashXMLCh.hpp | 54 ------ src/xercesc/util/Hashers.hpp | 95 +++++++++ src/xercesc/util/RefHash2KeysTableOf.c | 164 ++++++++++------ src/xercesc/util/RefHash2KeysTableOf.hpp | 100 +++++----- src/xercesc/util/RefHash3KeysIdPool.c | 183 +++++++++++------- src/xercesc/util/RefHash3KeysIdPool.hpp | 93 +++++---- src/xercesc/util/RefHashTableOf.hpp | 37 +--- src/xercesc/util/ValueHashTableOf.c | 100 ++++++---- src/xercesc/util/ValueHashTableOf.hpp | 99 +++++----- .../validators/common/DFAContentModel.cpp | 1 - .../validators/schema/SchemaGrammar.cpp | 1 - .../validators/schema/TraverseSchema.cpp | 1 - .../schema/identity/FieldActivator.cpp | 12 +- .../schema/identity/FieldActivator.hpp | 13 +- .../schema/identity/ValueStoreCache.cpp | 4 +- .../schema/identity/ValueStoreCache.hpp | 2 +- tests/Makefile.am | 2 - tests/src/MemHandlerTest/MemoryMonitor.hpp | 9 +- tests/src/MemHandlerTest/SimpleHashPtr.cpp | 41 ---- tests/src/MemHandlerTest/SimpleHashPtr.hpp | 38 ---- .../MemHandlerTest/SimpleValueHashTableOf.hpp | 149 +++++++------- 53 files changed, 670 insertions(+), 1186 deletions(-) delete mode 100644 src/xercesc/util/HashBase.hpp delete mode 100644 src/xercesc/util/HashCMStateSet.hpp delete mode 100644 src/xercesc/util/HashPtr.cpp delete mode 100644 src/xercesc/util/HashPtr.hpp delete mode 100644 src/xercesc/util/HashXMLCh.cpp delete mode 100644 src/xercesc/util/HashXMLCh.hpp create mode 100644 src/xercesc/util/Hashers.hpp delete mode 100644 tests/src/MemHandlerTest/SimpleHashPtr.cpp delete mode 100644 tests/src/MemHandlerTest/SimpleHashPtr.hpp diff --git a/doc/Doxyfile b/doc/Doxyfile index d20ce3941..3c7f3155e 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -428,10 +428,7 @@ EXCLUDE_PATTERNS = *Impl.hpp \ TransENameMap.hpp \ EncodingValidator.hpp \ FlagJanitor.hpp \ - HashCMStateSet.hpp \ - HashBase.hpp \ - HashPtr.hpp \ - HashXMLCh.hpp \ + Hashers.hpp \ KeyValuePair.hpp \ KeyRefPair.hpp \ KVStringPair.hpp \ diff --git a/projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj b/projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj index a4dfe614c..767181c98 100644 --- a/projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj +++ b/projects/MacOS/Xcode/XercesLib/XercesLib.xcode/project.pbxproj @@ -1168,39 +1168,7 @@ fileEncoding = 30; isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; - path = HashBase.hpp; - refType = 4; - sourceTree = "<group>"; - }; - 02058DE2FF8AF8CD7F000001 = { - fileEncoding = 30; - isa = PBXFileReference; - lastKnownFileType = sourcecode.cpp.cpp; - path = HashPtr.cpp; - refType = 4; - sourceTree = "<group>"; - }; - 02058DE3FF8AF8CD7F000001 = { - fileEncoding = 30; - isa = PBXFileReference; - lastKnownFileType = sourcecode.cpp.h; - path = HashPtr.hpp; - refType = 4; - sourceTree = "<group>"; - }; - 02058DE4FF8AF8CD7F000001 = { - fileEncoding = 30; - isa = PBXFileReference; - lastKnownFileType = sourcecode.cpp.cpp; - path = HashXMLCh.cpp; - refType = 4; - sourceTree = "<group>"; - }; - 02058DE5FF8AF8CD7F000001 = { - fileEncoding = 30; - isa = PBXFileReference; - lastKnownFileType = sourcecode.cpp.h; - path = HashXMLCh.hpp; + path = Hashers.hpp; refType = 4; sourceTree = "<group>"; }; @@ -14009,14 +13977,6 @@ refType = 4; sourceTree = "<group>"; }; - F5A6C93701B968C801000102 = { - fileEncoding = 30; - isa = PBXFileReference; - lastKnownFileType = sourcecode.cpp.h; - path = HashCMStateSet.hpp; - refType = 4; - sourceTree = "<group>"; - }; F5A6C93801B968C801000102 = { fileEncoding = 30; isa = PBXFileReference; diff --git a/projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr b/projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr index 7286b8ee1..265ca7dad 100644 --- a/projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr +++ b/projects/Win32/BCB6/Xerces-all/XercesLib/XercesLib.bpr @@ -44,8 +44,6 @@ ..\..\..\..\..\Build\Win32\BCB6\obj\BinMemInputStream.obj ..\..\..\..\..\Build\Win32\BCB6\obj\BitSet.obj ..\..\..\..\..\Build\Win32\BCB6\obj\EncodingValidator.obj - ..\..\..\..\..\Build\Win32\BCB6\obj\HashPtr.obj - ..\..\..\..\..\Build\Win32\BCB6\obj\HashXMLCh.obj ..\..\..\..\..\Build\Win32\BCB6\obj\HeaderDummy.obj ..\..\..\..\..\Build\Win32\BCB6\obj\HexBin.obj ..\..\..\..\..\Build\Win32\BCB6\obj\KVStringPair.obj @@ -413,8 +411,6 @@ <FILE FILENAME="..\..\..\..\..\src\xercesc\util\BinMemInputStream.cpp" FORMNAME="" UNITNAME="BinMemInputStream" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\util\BitSet.cpp" FORMNAME="" UNITNAME="BitSet" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\util\EncodingValidator.cpp" FORMNAME="" UNITNAME="EncodingValidator" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> - <FILE FILENAME="..\..\..\..\..\src\xercesc\util\HashPtr.cpp" FORMNAME="" UNITNAME="HashPtr" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> - <FILE FILENAME="..\..\..\..\..\src\xercesc\util\HashXMLCh.cpp" FORMNAME="" UNITNAME="HashXMLCh" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\util\HeaderDummy.cpp" FORMNAME="" UNITNAME="HeaderDummy" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\util\HexBin.cpp" FORMNAME="" UNITNAME="HexBin" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="..\..\..\..\..\src\xercesc\util\KVStringPair.cpp" FORMNAME="" UNITNAME="KVStringPair" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> diff --git a/projects/Win32/BCC.551/Xerces-all/MemHandlerTest/MemHandlerTest.mak b/projects/Win32/BCC.551/Xerces-all/MemHandlerTest/MemHandlerTest.mak index 4d2f7328a..2c4f76e85 100755 --- a/projects/Win32/BCC.551/Xerces-all/MemHandlerTest/MemHandlerTest.mak +++ b/projects/Win32/BCC.551/Xerces-all/MemHandlerTest/MemHandlerTest.mak @@ -5,7 +5,7 @@ BCB = $(MAKEDIR)\.. # --------------------------------------------------------------------------- TARGETPATH=..\..\..\..\..\Build\Win32\BCC.551 PROJECT = $(TARGETPATH)\MemHandlerTest.exe -OBJFILES = $(TARGETPATH)\obj\MemoryMonitor.obj $(TARGETPATH)\obj\SimpleHashPtr.obj $(TARGETPATH)\obj\MemHandlerTest.obj +OBJFILES = $(TARGETPATH)\obj\MemoryMonitor.obj $(TARGETPATH)\obj\MemHandlerTest.obj RESFILES = MAINSOURCE = MemHandlerTest.cpp RESDEPEN = $(RESFILES) diff --git a/projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak b/projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak index ad1c76bd6..702e426a5 100644 --- a/projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak +++ b/projects/Win32/BCC.551/Xerces-all/XercesLib/XercesLib.mak @@ -41,8 +41,6 @@ OBJFILES = $(TARGETPATH)\obj\XercesLib.obj \ $(TARGETPATH)\obj\BinInputStream.obj \ $(TARGETPATH)\obj\BinMemInputStream.obj \ $(TARGETPATH)\obj\BitSet.obj \ - $(TARGETPATH)\obj\HashPtr.obj \ - $(TARGETPATH)\obj\HashXMLCh.obj \ $(TARGETPATH)\obj\HeaderDummy.obj \ $(TARGETPATH)\obj\HexBin.obj \ $(TARGETPATH)\obj\KVStringPair.obj \ diff --git a/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.dsp b/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.dsp index 797a9dea1..6002b53bf 100755 --- a/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.dsp +++ b/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.dsp @@ -141,10 +141,6 @@ LINK32=link.exe SOURCE=..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.cpp # End Source File -# Begin Source File - -SOURCE=..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.cpp -# End Source File # End Group # Begin Group "Header Files" @@ -155,10 +151,6 @@ SOURCE=..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.hpp # End Source File # Begin Source File -SOURCE=..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.hpp -# End Source File -# Begin Source File - SOURCE=..\..\..\..\..\tests\src\MemHandlerTest\SimpleValueHashTableOf.hpp # End Source File # End Group diff --git a/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.mak b/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.mak index 3223c8005..64c3057fc 100755 --- a/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.mak +++ b/projects/Win32/VC6/xerces-all/MemHandlerTest/MemHandlerTest.mak @@ -54,7 +54,6 @@ CLEAN :"XercesLib - Win32 ReleaseCLEAN" CLEAN : !ENDIF -@erase "$(INTDIR)\MemoryMonitor.obj" - -@erase "$(INTDIR)\SimpleHashPtr.obj" -@erase "$(INTDIR)\vc60.idb" -@erase "$(OUTDIR)\MemHandlerTest.exe" @@ -73,7 +72,6 @@ LINK32=link.exe LINK32_FLAGS=kernel32.lib user32.lib xerces-c_3.lib /version:1.0 /subsystem:console /incremental:no /pdb:"$(OUTDIR)\MemHandlerTest.pdb" /machine:I386 /out:"$(OUTDIR)\MemHandlerTest.exe" /libpath:"..\..\..\..\..\Build\Win32\VC6\Release" LINK32_OBJS= \ "$(INTDIR)\MemoryMonitor.obj" \ - "$(INTDIR)\SimpleHashPtr.obj" \ "$(OUTDIR)\xerces-c_3.lib" "$(OUTDIR)\MemHandlerTest.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) @@ -105,7 +103,6 @@ CLEAN :"XercesLib - Win32 DebugCLEAN" CLEAN : !ENDIF -@erase "$(INTDIR)\MemoryMonitor.obj" - -@erase "$(INTDIR)\SimpleHashPtr.obj" -@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.pdb" -@erase "$(OUTDIR)\MemHandlerTest.exe" @@ -127,7 +124,6 @@ LINK32=link.exe LINK32_FLAGS=kernel32.lib user32.lib xerces-c_3D.lib /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\MemHandlerTest.pdb" /debug /machine:I386 /out:"$(OUTDIR)\MemHandlerTest.exe" /pdbtype:sept /libpath:"..\..\..\..\..\Build\Win32\VC6\Debug" LINK32_OBJS= \ "$(INTDIR)\MemoryMonitor.obj" \ - "$(INTDIR)\SimpleHashPtr.obj" \ "$(OUTDIR)\xerces-c_3D.lib" "$(OUTDIR)\MemHandlerTest.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) @@ -159,7 +155,6 @@ CLEAN :"XercesLib - Win64 DebugCLEAN" CLEAN : !ENDIF -@erase "$(INTDIR)\MemoryMonitor.obj" - -@erase "$(INTDIR)\SimpleHashPtr.obj" -@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.pdb" -@erase "$(OUTDIR)\MemHandlerTest.exe" @@ -181,7 +176,6 @@ LINK32=link.exe LINK32_FLAGS=kernel32.lib user32.lib xerces-c_3D.lib /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\MemHandlerTest.pdb" /debug /machine:IX86 /out:"$(OUTDIR)\MemHandlerTest.exe" /pdbtype:sept /libpath:"..\..\..\..\..\Build\Win64\VC6\Debug" /machine:IA64 LINK32_OBJS= \ "$(INTDIR)\MemoryMonitor.obj" \ - "$(INTDIR)\SimpleHashPtr.obj" \ "$(OUTDIR)\xerces-c_3D.lib" "$(OUTDIR)\MemHandlerTest.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) @@ -213,7 +207,6 @@ CLEAN :"XercesLib - Win64 ReleaseCLEAN" CLEAN : !ENDIF -@erase "$(INTDIR)\MemoryMonitor.obj" - -@erase "$(INTDIR)\SimpleHashPtr.obj" -@erase "$(INTDIR)\vc60.idb" -@erase "$(OUTDIR)\MemHandlerTest.exe" -@erase "$(OUTDIR)\MemHandlerTest.ilk" @@ -233,7 +226,6 @@ LINK32=link.exe LINK32_FLAGS=kernel32.lib user32.lib xerces-c_3.lib /version:1.0 /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\MemHandlerTest.pdb" /machine:IX86 /out:"$(OUTDIR)\MemHandlerTest.exe" /libpath:"..\..\..\..\..\Build\Win64\VC6\Release" /machine:IA64 LINK32_OBJS= \ "$(INTDIR)\MemoryMonitor.obj" \ - "$(INTDIR)\SimpleHashPtr.obj" \ "$(OUTDIR)\xerces-c_3.lib" "$(OUTDIR)\MemHandlerTest.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) @@ -289,13 +281,6 @@ SOURCE=..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.cpp "$(INTDIR)\MemoryMonitor.obj" : $(SOURCE) "$(INTDIR)" $(CPP) $(CPP_PROJ) $(SOURCE) - -SOURCE=..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.cpp - -"$(INTDIR)\SimpleHashPtr.obj" : $(SOURCE) "$(INTDIR)" - $(CPP) $(CPP_PROJ) $(SOURCE) - - !IF "$(CFG)" == "MemHandlerTest - Win32 Release" "XercesLib - Win32 Release" : diff --git a/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp b/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp index a8dc14f5d..e46ada36d 100644 --- a/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp +++ b/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp @@ -545,27 +545,7 @@ SOURCE=..\..\..\..\..\src\xercesc\util\FlagJanitor.hpp # End Source File # Begin Source File -SOURCE=..\..\..\..\..\src\xercesc\util\HashBase.hpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\..\src\xercesc\util\HashCMStateSet.hpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\..\src\xercesc\util\HashPtr.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\..\src\xercesc\util\HashPtr.hpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\..\src\xercesc\util\HashXMLCh.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\..\src\xercesc\util\HashXMLCh.hpp +SOURCE=..\..\..\..\..\src\xercesc\util\Hashers.hpp # End Source File # Begin Source File diff --git a/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak b/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak index 87d0975ea..258a8874b 100644 --- a/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak +++ b/projects/Win32/VC6/xerces-all/XercesLib/XercesLib.mak @@ -150,8 +150,6 @@ CLEAN : -@erase "$(INTDIR)\GeneralAttributeCheck.obj" -@erase "$(INTDIR)\Grammar.obj" -@erase "$(INTDIR)\GrammarResolver.obj" - -@erase "$(INTDIR)\HashPtr.obj" - -@erase "$(INTDIR)\HashXMLCh.obj" -@erase "$(INTDIR)\HexBin.obj" -@erase "$(INTDIR)\HexBinaryDatatypeValidator.obj" -@erase "$(INTDIR)\IC_Field.obj" @@ -405,8 +403,6 @@ LINK32_OBJS= \ "$(INTDIR)\BitSet.obj" \ "$(INTDIR)\DefaultPanicHandler.obj" \ "$(INTDIR)\EncodingValidator.obj" \ - "$(INTDIR)\HashPtr.obj" \ - "$(INTDIR)\HashXMLCh.obj" \ "$(INTDIR)\HexBin.obj" \ "$(INTDIR)\KVStringPair.obj" \ "$(INTDIR)\Mutexes.obj" \ @@ -793,8 +789,6 @@ CLEAN : -@erase "$(INTDIR)\GeneralAttributeCheck.obj" -@erase "$(INTDIR)\Grammar.obj" -@erase "$(INTDIR)\GrammarResolver.obj" - -@erase "$(INTDIR)\HashPtr.obj" - -@erase "$(INTDIR)\HashXMLCh.obj" -@erase "$(INTDIR)\HexBin.obj" -@erase "$(INTDIR)\HexBinaryDatatypeValidator.obj" -@erase "$(INTDIR)\IC_Field.obj" @@ -1049,8 +1043,6 @@ LINK32_OBJS= \ "$(INTDIR)\BitSet.obj" \ "$(INTDIR)\DefaultPanicHandler.obj" \ "$(INTDIR)\EncodingValidator.obj" \ - "$(INTDIR)\HashPtr.obj" \ - "$(INTDIR)\HashXMLCh.obj" \ "$(INTDIR)\HexBin.obj" \ "$(INTDIR)\KVStringPair.obj" \ "$(INTDIR)\Mutexes.obj" \ @@ -1437,8 +1429,6 @@ CLEAN : -@erase "$(INTDIR)\GeneralAttributeCheck.obj" -@erase "$(INTDIR)\Grammar.obj" -@erase "$(INTDIR)\GrammarResolver.obj" - -@erase "$(INTDIR)\HashPtr.obj" - -@erase "$(INTDIR)\HashXMLCh.obj" -@erase "$(INTDIR)\HexBin.obj" -@erase "$(INTDIR)\HexBinaryDatatypeValidator.obj" -@erase "$(INTDIR)\IC_Field.obj" @@ -1694,8 +1684,6 @@ LINK32_OBJS= \ "$(INTDIR)\BitSet.obj" \ "$(INTDIR)\DefaultPanicHandler.obj" \ "$(INTDIR)\EncodingValidator.obj" \ - "$(INTDIR)\HashPtr.obj" \ - "$(INTDIR)\HashXMLCh.obj" \ "$(INTDIR)\HexBin.obj" \ "$(INTDIR)\KVStringPair.obj" \ "$(INTDIR)\Mutexes.obj" \ @@ -2082,8 +2070,6 @@ CLEAN : -@erase "$(INTDIR)\GeneralAttributeCheck.obj" -@erase "$(INTDIR)\Grammar.obj" -@erase "$(INTDIR)\GrammarResolver.obj" - -@erase "$(INTDIR)\HashPtr.obj" - -@erase "$(INTDIR)\HashXMLCh.obj" -@erase "$(INTDIR)\HexBin.obj" -@erase "$(INTDIR)\HexBinaryDatatypeValidator.obj" -@erase "$(INTDIR)\IC_Field.obj" @@ -2338,8 +2324,6 @@ LINK32_OBJS= \ "$(INTDIR)\BitSet.obj" \ "$(INTDIR)\DefaultPanicHandler.obj" \ "$(INTDIR)\EncodingValidator.obj" \ - "$(INTDIR)\HashPtr.obj" \ - "$(INTDIR)\HashXMLCh.obj" \ "$(INTDIR)\HexBin.obj" \ "$(INTDIR)\KVStringPair.obj" \ "$(INTDIR)\Mutexes.obj" \ @@ -2910,18 +2894,6 @@ SOURCE=..\..\..\..\..\src\xercesc\util\EncodingValidator.cpp SOURCE=..\..\..\..\..\src\xercesc\util\FlagJanitor.c -SOURCE=..\..\..\..\..\src\xercesc\util\HashPtr.cpp - -"$(INTDIR)\HashPtr.obj" : $(SOURCE) "$(INTDIR)" - $(CPP) $(CPP_PROJ) $(SOURCE) - - -SOURCE=..\..\..\..\..\src\xercesc\util\HashXMLCh.cpp - -"$(INTDIR)\HashXMLCh.obj" : $(SOURCE) "$(INTDIR)" - $(CPP) $(CPP_PROJ) $(SOURCE) - - SOURCE=..\..\..\..\..\src\xercesc\util\HexBin.cpp "$(INTDIR)\HexBin.obj" : $(SOURCE) "$(INTDIR)" diff --git a/projects/Win32/VC7.1/xerces-all/MemHandlerTest/MemHandlerTest.vcproj b/projects/Win32/VC7.1/xerces-all/MemHandlerTest/MemHandlerTest.vcproj index efe035f5b..937094175 100644 --- a/projects/Win32/VC7.1/xerces-all/MemHandlerTest/MemHandlerTest.vcproj +++ b/projects/Win32/VC7.1/xerces-all/MemHandlerTest/MemHandlerTest.vcproj @@ -380,9 +380,6 @@ <File RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.cpp"> </File> - <File - RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.cpp"> - </File> </Filter> <Filter Name="Header Files" @@ -390,9 +387,6 @@ <File RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.hpp"> </File> - <File - RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.hpp"> - </File> <File RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleValueHashTableOf.hpp"> </File> diff --git a/projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj b/projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj index f0a8ccf94..f72a49bf5 100644 --- a/projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj +++ b/projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj @@ -463,22 +463,7 @@ RelativePath="..\..\..\..\..\src\xercesc\util\FlagJanitor.hpp"> </File> <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashBase.hpp"> - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashCMStateSet.hpp"> - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashPtr.cpp"> - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashPtr.hpp"> - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashXMLCh.cpp"> - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashXMLCh.hpp"> + RelativePath="..\..\..\..\..\src\xercesc\util\Hashers.hpp"> </File> <File RelativePath="..\..\..\..\..\src\xercesc\util\HeaderDummy.cpp"> diff --git a/projects/Win32/VC8/xerces-all/MemHandlerTest/MemHandlerTest.vcproj b/projects/Win32/VC8/xerces-all/MemHandlerTest/MemHandlerTest.vcproj index c26b5e035..41f7a7fb3 100644 --- a/projects/Win32/VC8/xerces-all/MemHandlerTest/MemHandlerTest.vcproj +++ b/projects/Win32/VC8/xerces-all/MemHandlerTest/MemHandlerTest.vcproj @@ -1084,10 +1084,6 @@ RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.cpp" > </File> - <File - RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.cpp" - > - </File> </Filter> <Filter Name="Header Files" @@ -1097,10 +1093,6 @@ RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.hpp" > </File> - <File - RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.hpp" - > - </File> <File RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleValueHashTableOf.hpp" > diff --git a/projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj b/projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj index afce6489b..e411a2206 100644 --- a/projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj +++ b/projects/Win32/VC8/xerces-all/XercesLib/XercesLib.vcproj @@ -1182,27 +1182,7 @@ > </File> <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashBase.hpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashCMStateSet.hpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashPtr.cpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashPtr.hpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashXMLCh.cpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashXMLCh.hpp" + RelativePath="..\..\..\..\..\src\xercesc\util\Hashers.hpp" > </File> <File diff --git a/projects/Win32/VC9/xerces-all/MemHandlerTest/MemHandlerTest.vcproj b/projects/Win32/VC9/xerces-all/MemHandlerTest/MemHandlerTest.vcproj index bc79779bc..8a0e9aee2 100644 --- a/projects/Win32/VC9/xerces-all/MemHandlerTest/MemHandlerTest.vcproj +++ b/projects/Win32/VC9/xerces-all/MemHandlerTest/MemHandlerTest.vcproj @@ -1083,10 +1083,6 @@ RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.cpp" > </File> - <File - RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.cpp" - > - </File> </Filter> <Filter Name="Header Files" @@ -1096,10 +1092,6 @@ RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\MemoryMonitor.hpp" > </File> - <File - RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleHashPtr.hpp" - > - </File> <File RelativePath="..\..\..\..\..\tests\src\MemHandlerTest\SimpleValueHashTableOf.hpp" > diff --git a/projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj b/projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj index c77b9d3ba..490a8d57e 100644 --- a/projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj +++ b/projects/Win32/VC9/xerces-all/XercesLib/XercesLib.vcproj @@ -1181,27 +1181,7 @@ > </File> <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashBase.hpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashCMStateSet.hpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashPtr.cpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashPtr.hpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashXMLCh.cpp" - > - </File> - <File - RelativePath="..\..\..\..\..\src\xercesc\util\HashXMLCh.hpp" + RelativePath="..\..\..\..\..\src\xercesc\util\Hashers.hpp" > </File> <File diff --git a/src/Makefile.am b/src/Makefile.am index 8278866e8..e986f2044 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -577,10 +577,7 @@ util_headers = \ xercesc/util/EncodingValidator.hpp \ xercesc/util/FlagJanitor.hpp \ xercesc/util/FlagJanitor.c \ - xercesc/util/HashBase.hpp \ - xercesc/util/HashCMStateSet.hpp \ - xercesc/util/HashPtr.hpp \ - xercesc/util/HashXMLCh.hpp \ + xercesc/util/Hashers.hpp \ xercesc/util/HexBin.hpp \ xercesc/util/IllegalArgumentException.hpp \ xercesc/util/InvalidCastException.hpp \ @@ -715,8 +712,6 @@ util_sources = \ xercesc/util/BitSet.cpp \ xercesc/util/DefaultPanicHandler.cpp \ xercesc/util/EncodingValidator.cpp \ - xercesc/util/HashPtr.cpp \ - xercesc/util/HashXMLCh.cpp \ xercesc/util/HeaderDummy.cpp \ xercesc/util/HexBin.cpp \ xercesc/util/KVStringPair.cpp \ diff --git a/src/xercesc/dom/impl/DOMDeepNodeListPool.c b/src/xercesc/dom/impl/DOMDeepNodeListPool.c index 4e7038bce..6038ff2b0 100644 --- a/src/xercesc/dom/impl/DOMDeepNodeListPool.c +++ b/src/xercesc/dom/impl/DOMDeepNodeListPool.c @@ -37,14 +37,13 @@ XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // DOMDeepNodeListPool: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> -DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus +template <class TVal, class THasher> +DOMDeepNodeListPool<TVal, THasher>::DOMDeepNodeListPool( const XMLSize_t modulus , const bool adoptElems , const XMLSize_t initSize) : - fAdoptedElems(adoptElems) + fAdoptedElems(adoptElems) , fBucketList(0) , fHashModulus(modulus) - , fHash(0) , fIdPtrs(0) , fIdPtrsCount(initSize) , fIdCounter(0) @@ -52,12 +51,6 @@ DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus { initialize(modulus); - // create default hasher -#if defined (XML_GCC_VERSION) && (XML_GCC_VERSION < 29600) - fHash = new HashPtr(); -#else - fHash = new (fMemoryManager) HashPtr(); -#endif // // Allocate the initial id pointers array. We don't have to zero them // out since the fIdCounter value tells us which ones are valid. The @@ -70,23 +63,21 @@ DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus fIdPtrs[0] = 0; } -template <class TVal> -DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus +template <class TVal, class THasher> +DOMDeepNodeListPool<TVal, THasher>::DOMDeepNodeListPool( const XMLSize_t modulus , const bool adoptElems - , HashBase* hashBase + , const THasher& hasher , const XMLSize_t initSize) : - fAdoptedElems(adoptElems) + fAdoptedElems(adoptElems) , fBucketList(0) , fHashModulus(modulus) - , fHash(0) + , fHasher(hasher) , fIdPtrs(0) , fIdPtrsCount(initSize) , fIdCounter(0) , fMemoryManager(XMLPlatformUtils::fgMemoryManager) { initialize(modulus); - // set hasher - fHash = hashBase; // // Allocate the initial id pointers array. We don't have to zero them @@ -100,13 +91,12 @@ DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus fIdPtrs[0] = 0; } -template <class TVal> -DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus +template <class TVal, class THasher> +DOMDeepNodeListPool<TVal, THasher>::DOMDeepNodeListPool( const XMLSize_t modulus , const XMLSize_t initSize) : - fAdoptedElems(true) + fAdoptedElems(true) , fBucketList(0) , fHashModulus(modulus) - , fHash(0) , fIdPtrs(0) , fIdPtrsCount(initSize) , fIdCounter(0) @@ -114,13 +104,6 @@ DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus { initialize(modulus); - // create default hasher -#if defined (XML_GCC_VERSION) && (XML_GCC_VERSION < 29600) - fHash = new HashPtr(); -#else - fHash = new (fMemoryManager) HashPtr(); -#endif - // // Allocate the initial id pointers array. We don't have to zero them // out since the fIdCounter value tells us which ones are valid. The @@ -133,8 +116,8 @@ DOMDeepNodeListPool<TVal>::DOMDeepNodeListPool( const XMLSize_t modulus fIdPtrs[0] = 0; } -template <class TVal> -void DOMDeepNodeListPool<TVal>::initialize(const XMLSize_t modulus) +template <class TVal, class THasher> +void DOMDeepNodeListPool<TVal, THasher>::initialize(const XMLSize_t modulus) { if (modulus == 0) ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::HshTbl_ZeroModulus, fMemoryManager); @@ -149,22 +132,22 @@ void DOMDeepNodeListPool<TVal>::initialize(const XMLSize_t modulus) fBucketList[index] = 0; } -template <class TVal> DOMDeepNodeListPool<TVal>::~DOMDeepNodeListPool() +template <class TVal, class THasher> +DOMDeepNodeListPool<TVal, THasher>::~DOMDeepNodeListPool() { removeAll(); // Then delete the bucket list & hasher & id pointers list fMemoryManager->deallocate(fIdPtrs);//delete [] fIdPtrs; fMemoryManager->deallocate(fBucketList);//delete [] fBucketList; - delete fHash; } // --------------------------------------------------------------------------- // DOMDeepNodeListPool: Element management // --------------------------------------------------------------------------- -template <class TVal> -bool DOMDeepNodeListPool<TVal>::isEmpty() const +template <class TVal, class THasher> +bool DOMDeepNodeListPool<TVal, THasher>::isEmpty() const { // Just check the bucket list for non-empty elements for (XMLSize_t buckInd = 0; buckInd < fHashModulus; buckInd++) @@ -175,8 +158,8 @@ bool DOMDeepNodeListPool<TVal>::isEmpty() const return true; } -template <class TVal> -bool DOMDeepNodeListPool<TVal>::containsKey( const void* const key1 +template <class TVal, class THasher> +bool DOMDeepNodeListPool<TVal, THasher>::containsKey( const void* const key1 , const XMLCh* const key2 , const XMLCh* const key3) const { @@ -185,8 +168,8 @@ bool DOMDeepNodeListPool<TVal>::containsKey( const void* const key1 return (findIt != 0); } -template <class TVal> -void DOMDeepNodeListPool<TVal>::removeAll() +template <class TVal, class THasher> +void DOMDeepNodeListPool<TVal, THasher>::removeAll() { if (fIdCounter == 0) return; @@ -224,14 +207,14 @@ void DOMDeepNodeListPool<TVal>::removeAll() fIdCounter = 0; } -template <class TVal> void DOMDeepNodeListPool<TVal>::cleanup() +template <class TVal, class THasher> +void DOMDeepNodeListPool<TVal, THasher>::cleanup() { removeAll(); // Then delete the bucket list & hasher & id pointers list fMemoryManager->deallocate(fIdPtrs);//delete [] fIdPtrs; fMemoryManager->deallocate(fBucketList);//delete [] fBucketList; - delete fHash; } @@ -239,8 +222,9 @@ template <class TVal> void DOMDeepNodeListPool<TVal>::cleanup() // --------------------------------------------------------------------------- // DOMDeepNodeListPool: Getters // --------------------------------------------------------------------------- -template <class TVal> TVal* -DOMDeepNodeListPool<TVal>::getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) +template <class TVal, class THasher> +TVal* +DOMDeepNodeListPool<TVal, THasher>::getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) { XMLSize_t hashVal; DOMDeepNodeListPoolTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, key3, hashVal); @@ -249,8 +233,9 @@ DOMDeepNodeListPool<TVal>::getByKey(const void* const key1, const XMLCh* const k return findIt->fData; } -template <class TVal> const TVal* -DOMDeepNodeListPool<TVal>::getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const +template <class TVal, class THasher> +const TVal* +DOMDeepNodeListPool<TVal, THasher>::getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const { XMLSize_t hashVal; const DOMDeepNodeListPoolTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, key3, hashVal); @@ -259,8 +244,9 @@ DOMDeepNodeListPool<TVal>::getByKey(const void* const key1, const XMLCh* const k return findIt->fData; } -template <class TVal> TVal* -DOMDeepNodeListPool<TVal>::getById(const unsigned int elemId) +template <class TVal, class THasher> +TVal* +DOMDeepNodeListPool<TVal, THasher>::getById(const unsigned int elemId) { // If its either zero or beyond our current id, its an error if (!elemId || (elemId > fIdCounter)) @@ -269,8 +255,9 @@ DOMDeepNodeListPool<TVal>::getById(const unsigned int elemId) return fIdPtrs[elemId]; } -template <class TVal> const TVal* -DOMDeepNodeListPool<TVal>::getById(const unsigned int elemId) const +template <class TVal, class THasher> +const TVal* +DOMDeepNodeListPool<TVal, THasher>::getById(const unsigned int elemId) const { // If its either zero or beyond our current id, its an error if (!elemId || (elemId > fIdCounter)) @@ -282,8 +269,9 @@ DOMDeepNodeListPool<TVal>::getById(const unsigned int elemId) const // --------------------------------------------------------------------------- // DOMDeepNodeListPool: Putters // --------------------------------------------------------------------------- -template <class TVal> unsigned int -DOMDeepNodeListPool<TVal>::put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt) +template <class TVal, class THasher> +unsigned int +DOMDeepNodeListPool<TVal, THasher>::put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt) { // First see if the key exists already XMLSize_t hashVal; @@ -366,11 +354,12 @@ DOMDeepNodeListPool<TVal>::put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const // --------------------------------------------------------------------------- // DOMDeepNodeListPool: Private methods // --------------------------------------------------------------------------- -template <class TVal> DOMDeepNodeListPoolTableBucketElem<TVal>* DOMDeepNodeListPool<TVal>:: +template <class TVal, class THasher> +DOMDeepNodeListPoolTableBucketElem<TVal>* DOMDeepNodeListPool<TVal, THasher>:: findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal) { // Hash the key - hashVal = fHash->getHashVal(key1, fHashModulus); + hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key @@ -379,7 +368,7 @@ findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* con { //key2 and key3 are XMLCh*, compareString takes null pointer vs zero len string the same //but we need them to be treated as different keys in this case - if (fHash->equals(key1, curElem->fKey1) && (XMLString::equals(key2, curElem->fKey2)) && (XMLString::equals(key3, curElem->fKey3))) { + if (fHasher.equals(key1, curElem->fKey1) && (XMLString::equals(key2, curElem->fKey2)) && (XMLString::equals(key3, curElem->fKey3))) { if (!key2 || !curElem->fKey2) { if (key2 || curElem->fKey2) { curElem = curElem->fNext; @@ -401,11 +390,12 @@ findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* con return 0; } -template <class TVal> const DOMDeepNodeListPoolTableBucketElem<TVal>* DOMDeepNodeListPool<TVal>:: +template <class TVal, class THasher> +const DOMDeepNodeListPoolTableBucketElem<TVal>* DOMDeepNodeListPool<TVal, THasher>:: findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal) const { // Hash the key - hashVal = fHash->getHashVal(key1, fHashModulus); + hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key @@ -414,7 +404,7 @@ findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* con { //key2 and key3 are XMLCh*, compareString takes null pointer vs zero len string the same //but we need them to be treated as different keys in this case - if (fHash->equals(key1, curElem->fKey1) && (XMLString::equals(key2, curElem->fKey2)) && (XMLString::equals(key3, curElem->fKey3))) { + if (fHasher.equals(key1, curElem->fKey1) && (XMLString::equals(key2, curElem->fKey2)) && (XMLString::equals(key3, curElem->fKey3))) { if (!key2 || !curElem->fKey2) { if (key2 || curElem->fKey2) { curElem = curElem->fNext; diff --git a/src/xercesc/dom/impl/DOMDeepNodeListPool.hpp b/src/xercesc/dom/impl/DOMDeepNodeListPool.hpp index fcc6db8fd..760d58b50 100644 --- a/src/xercesc/dom/impl/DOMDeepNodeListPool.hpp +++ b/src/xercesc/dom/impl/DOMDeepNodeListPool.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,25 +32,15 @@ #define XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTPOOL_HPP -#include <xercesc/util/HashBase.hpp> +#include <xercesc/util/Hashers.hpp> #include <xercesc/util/IllegalArgumentException.hpp> #include <xercesc/util/NoSuchElementException.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/XMLExceptMsgs.hpp> #include <xercesc/util/XMLEnumerator.hpp> -#include <xercesc/util/XMLString.hpp> -#include <xercesc/util/HashXMLCh.hpp> -#include <xercesc/util/HashPtr.hpp> XERCES_CPP_NAMESPACE_BEGIN - -// This hash table is modified from RefHash3KeysIdPool with first key as object ptr (DOMNode), -// second and third keys are both XMLCh* string - -template <class TVal> struct DOMDeepNodeListPoolTableBucketElem; - - // // This should really be a nested class, but some of the compilers we // have to support cannot deal with that! @@ -90,20 +80,19 @@ struct DOMDeepNodeListPoolTableBucketElem : public XMemory }; -template <class TVal> class DOMDeepNodeListPool +template <class TVal, class THasher = PtrHasher> +class DOMDeepNodeListPool { public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - // backwards compatability - default hasher is HashXMLCh DOMDeepNodeListPool ( const XMLSize_t modulus , const XMLSize_t initSize = 128 ); - // backwards compatability - default hasher is HashXMLCh DOMDeepNodeListPool ( const XMLSize_t modulus @@ -111,14 +100,11 @@ public: , const XMLSize_t initSize = 128 ); - // if a hash function is passed in, it will be deleted when the hashtable is deleted. - // use a new instance of the hasher class for each hashtable, otherwise one hashtable - // may delete the hasher of a different hashtable if both use the same hasher. DOMDeepNodeListPool ( const XMLSize_t modulus , const bool adoptElems - , HashBase* hashBase + , const THasher& hasher , const XMLSize_t initSize = 128 ); @@ -145,7 +131,7 @@ public: // ----------------------------------------------------------------------- // Putters // ----------------------------------------------------------------------- - unsigned int put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt); + unsigned int put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt); private: @@ -159,8 +145,8 @@ private: // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- - DOMDeepNodeListPool(const DOMDeepNodeListPool<TVal> &); - DOMDeepNodeListPool<TVal> & operator = (const DOMDeepNodeListPool<TVal> &); + DOMDeepNodeListPool(const DOMDeepNodeListPool<TVal, THasher> &); + DOMDeepNodeListPool<TVal, THasher> & operator = (const DOMDeepNodeListPool<TVal, THasher> &); // ----------------------------------------------------------------------- // Data members @@ -198,7 +184,7 @@ private: bool fAdoptedElems; DOMDeepNodeListPoolTableBucketElem<TVal>** fBucketList; XMLSize_t fHashModulus; - HashBase* fHash; + THasher fHasher; TVal** fIdPtrs; XMLSize_t fIdPtrsCount; unsigned int fIdCounter; diff --git a/src/xercesc/dom/impl/DOMDocumentImpl.cpp b/src/xercesc/dom/impl/DOMDocumentImpl.cpp index 40f05a8f6..33f44b824 100644 --- a/src/xercesc/dom/impl/DOMDocumentImpl.cpp +++ b/src/xercesc/dom/impl/DOMDocumentImpl.cpp @@ -1266,11 +1266,10 @@ void* DOMDocumentImpl::setUserData(DOMNodeImpl* n, const XMLCh* key, void* data, if (!fUserDataTable) { // create the table on heap so that it can be cleaned in destructor - fUserDataTable = new (fMemoryManager) RefHash2KeysTableOf<DOMUserDataRecord> + fUserDataTable = new (fMemoryManager) RefHash2KeysTableOf<DOMUserDataRecord, PtrHasher> ( 109 , true - , new (fMemoryManager) HashPtr() , fMemoryManager ); } @@ -1290,7 +1289,7 @@ void* DOMDocumentImpl::setUserData(DOMNodeImpl* n, const XMLCh* key, void* data, fUserDataTable->put((void*)n, keyId, new (fMemoryManager) DOMUserDataRecord(data, handler)); } else { - RefHash2KeysTableOfEnumerator<DOMUserDataRecord> enumKeys(fUserDataTable, false, fMemoryManager); + RefHash2KeysTableOfEnumerator<DOMUserDataRecord, PtrHasher> enumKeys(fUserDataTable, false, fMemoryManager); enumKeys.setPrimaryKey(n); if (!enumKeys.hasMoreElements()) n->hasUserData(false); @@ -1316,7 +1315,7 @@ void* DOMDocumentImpl::getUserData(const DOMNodeImpl* n, const XMLCh* key) const void DOMDocumentImpl::callUserDataHandlers(const DOMNodeImpl* n, DOMUserDataHandler::DOMOperationType operation, const DOMNode* src, DOMNode* dst) const { if (fUserDataTable) { - RefHash2KeysTableOfEnumerator<DOMUserDataRecord> userDataEnum(fUserDataTable, false, fMemoryManager); + RefHash2KeysTableOfEnumerator<DOMUserDataRecord, PtrHasher> userDataEnum(fUserDataTable, false, fMemoryManager); userDataEnum.setPrimaryKey(n); // Create a snapshot of the handlers to be called, as the "handle" callback could be invalidating the enumerator by calling // setUserData on the dst node diff --git a/src/xercesc/dom/impl/DOMDocumentImpl.hpp b/src/xercesc/dom/impl/DOMDocumentImpl.hpp index d7fea2f4c..ed0d84d98 100644 --- a/src/xercesc/dom/impl/DOMDocumentImpl.hpp +++ b/src/xercesc/dom/impl/DOMDocumentImpl.hpp @@ -300,7 +300,7 @@ protected: DOMConfiguration* fDOMConfiguration; XMLStringPool fUserDataTableKeys; - RefHash2KeysTableOf<DOMUserDataRecord>* fUserDataTable; + RefHash2KeysTableOf<DOMUserDataRecord, PtrHasher>* fUserDataTable; // Per-Document heap Variables. diff --git a/src/xercesc/internal/DGXMLScanner.cpp b/src/xercesc/internal/DGXMLScanner.cpp index c91b898a2..d6bdd1cfd 100644 --- a/src/xercesc/internal/DGXMLScanner.cpp +++ b/src/xercesc/internal/DGXMLScanner.cpp @@ -42,7 +42,6 @@ #include <xercesc/validators/DTD/DTDValidator.hpp> #include <xercesc/util/OutOfMemoryException.hpp> #include <xercesc/util/XMLResourceIdentifier.hpp> -#include <xercesc/util/HashPtr.hpp> XERCES_CPP_NAMESPACE_BEGIN diff --git a/src/xercesc/internal/IGXMLScanner.cpp b/src/xercesc/internal/IGXMLScanner.cpp index f5788efba..261d152a4 100644 --- a/src/xercesc/internal/IGXMLScanner.cpp +++ b/src/xercesc/internal/IGXMLScanner.cpp @@ -25,7 +25,6 @@ // --------------------------------------------------------------------------- #include <xercesc/internal/IGXMLScanner.hpp> #include <xercesc/util/RuntimeException.hpp> -#include <xercesc/util/HashPtr.hpp> #include <xercesc/util/UnexpectedEOFException.hpp> #include <xercesc/sax/InputSource.hpp> #include <xercesc/framework/XMLDocumentHandler.hpp> diff --git a/src/xercesc/internal/SGXMLScanner.cpp b/src/xercesc/internal/SGXMLScanner.cpp index 62f7fbbb9..e03b56c52 100644 --- a/src/xercesc/internal/SGXMLScanner.cpp +++ b/src/xercesc/internal/SGXMLScanner.cpp @@ -49,7 +49,6 @@ #include <xercesc/validators/schema/identity/IC_Selector.hpp> #include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/util/OutOfMemoryException.hpp> -#include <xercesc/util/HashPtr.hpp> #include <xercesc/util/XMLStringTokenizer.hpp> XERCES_CPP_NAMESPACE_BEGIN diff --git a/src/xercesc/internal/XMLScanner.hpp b/src/xercesc/internal/XMLScanner.hpp index 6246b577e..b8313a5c5 100644 --- a/src/xercesc/internal/XMLScanner.hpp +++ b/src/xercesc/internal/XMLScanner.hpp @@ -1367,7 +1367,7 @@ inline void XMLScanner::setAttrDupChkRegistry(const XMLSize_t &attrNumber { fAttrDupChkRegistry = new (fMemoryManager) RefHash2KeysTableOf<XMLAttr> ( - 2*attrNumber+1, false, new (fMemoryManager)HashXMLCh(), fMemoryManager + 2*attrNumber+1, false, fMemoryManager ); } else diff --git a/src/xercesc/internal/XSObjectFactory.cpp b/src/xercesc/internal/XSObjectFactory.cpp index c7812b7af..dff7e7a69 100644 --- a/src/xercesc/internal/XSObjectFactory.cpp +++ b/src/xercesc/internal/XSObjectFactory.cpp @@ -50,7 +50,6 @@ #include <xercesc/validators/schema/identity/IdentityConstraint.hpp> #include <xercesc/validators/schema/identity/IC_KeyRef.hpp> #include <xercesc/validators/schema/identity/XercesXPath.hpp> -#include <xercesc/util/HashPtr.hpp> #include <xercesc/util/XMLStringTokenizer.hpp> XERCES_CPP_NAMESPACE_BEGIN diff --git a/src/xercesc/internal/XSerializeEngine.cpp b/src/xercesc/internal/XSerializeEngine.cpp index cb4ef89cf..506880fc3 100644 --- a/src/xercesc/internal/XSerializeEngine.cpp +++ b/src/xercesc/internal/XSerializeEngine.cpp @@ -27,8 +27,6 @@ #include <xercesc/internal/XSerializable.hpp> #include <xercesc/internal/XProtoType.hpp> -#include <xercesc/util/HashPtr.hpp> - #include <xercesc/framework/XMLGrammarPool.hpp> #include <xercesc/framework/BinOutputStream.hpp> #include <xercesc/util/BinInputStream.hpp> diff --git a/src/xercesc/internal/XTemplateSerializer.cpp b/src/xercesc/internal/XTemplateSerializer.cpp index 3e7031ba0..6efa277ed 100644 --- a/src/xercesc/internal/XTemplateSerializer.cpp +++ b/src/xercesc/internal/XTemplateSerializer.cpp @@ -23,7 +23,6 @@ #include <xercesc/internal/XTemplateSerializer.hpp> #include <xercesc/framework/XMLGrammarPool.hpp> #include <xercesc/validators/common/Grammar.hpp> -#include <xercesc/util/HashPtr.hpp> #include <stdio.h> #include <stdlib.h> diff --git a/src/xercesc/util/HashBase.hpp b/src/xercesc/util/HashBase.hpp deleted file mode 100644 index 59eab47f4..000000000 --- a/src/xercesc/util/HashBase.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * $Id$ - */ - -#if !defined(XERCESC_INCLUDE_GUARD_HASHBASE_HPP) -#define XERCESC_INCLUDE_GUARD_HASHBASE_HPP - -#include <xercesc/util/XMemory.hpp> -#include <xercesc/util/PlatformUtils.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -/** - * The <code>HashBase</code> interface is the general outline of a hasher. - * Hashers are used in <code>RefHashTableOf</code> hashtables to hash any - * type of key. An examples is the <code>HashXMLCh</code> class which is - * designed to produce hash values for XMLCh* strings. Any hasher inheriting - * from <code>HashBase</code> may be specified when the RefHashTableOf hashtable is constructed. - */ -class XMLUTIL_EXPORT HashBase : public XMemory -{ - -public: - - /** - * Returns a hash value based on the key - * - * @param key the key to be hashed - * @param mod the modulus the hasher should use - */ - virtual XMLSize_t getHashVal(const void *const key, XMLSize_t mod) = 0; - - /** - * Compares two keys and determines if they are semantically equal - * - * @param key1 the first key to be compared - * @param key2 the second key to be compared - * - * @return true if they are equal - */ - virtual bool equals(const void *const key1, const void *const key2) = 0; - - virtual ~HashBase() {}; - - HashBase() {}; - -private: - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - HashBase(const HashBase&); - HashBase& operator=(const HashBase&); -}; - -XERCES_CPP_NAMESPACE_END - -#endif diff --git a/src/xercesc/util/HashCMStateSet.hpp b/src/xercesc/util/HashCMStateSet.hpp deleted file mode 100644 index c98dba345..000000000 --- a/src/xercesc/util/HashCMStateSet.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * $Id$ - */ - -#if !defined(XERCESC_INCLUDE_GUARD_HASH_CMSTATESET_HPP) -#define XERCESC_INCLUDE_GUARD_HASH_CMSTATESET_HPP - -#include <xercesc/util/HashBase.hpp> -#include <xercesc/validators/common/CMStateSet.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -/** - * The <code>HashCMStateSet</code> class inherits from <code>HashBase</code>. - * This is a CMStateSet specific hasher class designed to hash the values - * of CMStateSet. - * - * See <code>HashBase</code> for more information. - */ - -class XMLUTIL_EXPORT HashCMStateSet : public HashBase -{ -public: - HashCMStateSet(); - virtual ~HashCMStateSet(); - virtual XMLSize_t getHashVal(const void *const key, XMLSize_t mod); - virtual bool equals(const void *const key1, const void *const key2); -private: - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - HashCMStateSet(const HashCMStateSet&); - HashCMStateSet& operator=(const HashCMStateSet&); -}; - -inline HashCMStateSet::HashCMStateSet() -{ -} - -inline HashCMStateSet::~HashCMStateSet() -{ -} - -inline XMLSize_t HashCMStateSet::getHashVal(const void *const key, XMLSize_t mod) -{ - const CMStateSet* const pkey = (const CMStateSet*) key; - return ((pkey->hashCode()) % mod); -} - -inline bool HashCMStateSet::equals(const void *const key1, const void *const key2) -{ - const CMStateSet* const pkey1 = (const CMStateSet*) key1; - const CMStateSet* const pkey2 = (const CMStateSet*) key2; - - return (*pkey1==*pkey2); -} - -XERCES_CPP_NAMESPACE_END - -#endif diff --git a/src/xercesc/util/HashPtr.cpp b/src/xercesc/util/HashPtr.cpp deleted file mode 100644 index f1e36f744..000000000 --- a/src/xercesc/util/HashPtr.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <xercesc/util/HashPtr.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -HashPtr::HashPtr() -{ -} - -HashPtr::~HashPtr() -{ -} - -XMLSize_t HashPtr::getHashVal(const void *const key, XMLSize_t mod) -{ - return (((XMLSize_t)key) % mod); -} - -bool HashPtr::equals(const void *const key1, const void *const key2) -{ - return (key1 == key2); -} - -XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/util/HashPtr.hpp b/src/xercesc/util/HashPtr.hpp deleted file mode 100644 index ebec05d4e..000000000 --- a/src/xercesc/util/HashPtr.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * $Id$ - */ - -#if !defined(XERCESC_INCLUDE_GUARD_HASHPTR_HPP) -#define XERCESC_INCLUDE_GUARD_HASHPTR_HPP - -#include <xercesc/util/HashBase.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -/** - * The <code>HashPtr</code> class inherits from <code>HashBase</code>. - * This is a generic hasher class designed to hash the pointers of the - * objects themselves. Useful if you want to hash objects instead of - * strings so long as the objects don't move to a different memory location. - * See <code>HashBase</code> for more information. - */ - -class XMLUTIL_EXPORT HashPtr : public HashBase -{ -public: - HashPtr(); - virtual ~HashPtr(); - virtual XMLSize_t getHashVal(const void *const key, XMLSize_t mod); - virtual bool equals(const void *const key1, const void *const key2); -private: - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - HashPtr(const HashPtr&); - HashPtr& operator=(const HashPtr&); -}; - -XERCES_CPP_NAMESPACE_END - -#endif diff --git a/src/xercesc/util/HashXMLCh.cpp b/src/xercesc/util/HashXMLCh.cpp deleted file mode 100644 index 8c9c1d3af..000000000 --- a/src/xercesc/util/HashXMLCh.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <xercesc/util/HashXMLCh.hpp> -#include <xercesc/util/XMLString.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -HashXMLCh::HashXMLCh() -{ -} - -HashXMLCh::~HashXMLCh() -{ -} - -XMLSize_t HashXMLCh::getHashVal(const void *const key, XMLSize_t mod) -{ - return XMLString::hash((XMLCh*)key, mod); -} - -bool HashXMLCh::equals(const void *const key1, const void *const key2) -{ - return XMLString::equals((const XMLCh*)key1, (const XMLCh*)key2); -} - -XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/util/HashXMLCh.hpp b/src/xercesc/util/HashXMLCh.hpp deleted file mode 100644 index f3fec94b3..000000000 --- a/src/xercesc/util/HashXMLCh.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * $Id$ - */ - -#if !defined(XERCESC_INCLUDE_GUARD_HASHXMLCH_HPP) -#define XERCESC_INCLUDE_GUARD_HASHXMLCH_HPP - -#include <xercesc/util/HashBase.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -/** - * The <code>HashXMLCh</code> class inherits from <code>HashBase</code>. - * This is a XMLCh* string specific hasher class designed to hash the values - * of XMLCh* strings with a given modulo. References the XMLString hash - * function. - * See <code>HashBase</code> for more information. - */ - -class XMLUTIL_EXPORT HashXMLCh : public HashBase -{ -public: - HashXMLCh(); - virtual ~HashXMLCh(); - virtual XMLSize_t getHashVal(const void *const key, XMLSize_t mod); - virtual bool equals(const void *const key1, const void *const key2); -private: - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - HashXMLCh(const HashXMLCh&); - HashXMLCh& operator=(const HashXMLCh&); -}; - -XERCES_CPP_NAMESPACE_END - -#endif diff --git a/src/xercesc/util/Hashers.hpp b/src/xercesc/util/Hashers.hpp new file mode 100644 index 000000000..97d8c3928 --- /dev/null +++ b/src/xercesc/util/Hashers.hpp @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * $Id: HashBase.hpp 678144 2008-07-19 12:08:55Z borisk $ + */ + +#if !defined(XERCESC_INCLUDE_GUARD_HASHERS_HPP) +#define XERCESC_INCLUDE_GUARD_HASHERS_HPP + +#include <xercesc/util/XMLString.hpp> + +XERCES_CPP_NAMESPACE_BEGIN + +// +// Common hashers. Only widely-used hashers should be placed here. +// + +/** + * Hasher for keys that are const XMLCh*. + */ +struct StringHasher +{ + /** + * Returns a hash value based on the key + * + * @param key the key to be hashed + * @param mod the modulus the hasher should use + */ + XMLSize_t getHashVal(const void* key, XMLSize_t mod) const + { + return XMLString::hash ((const XMLCh*)key, mod); + } + + /** + * Compares two keys and determines if they are semantically equal + * + * @param key1 the first key to be compared + * @param key2 the second key to be compared + * + * @return true if they are equal + */ + bool equals(const void *const key1, const void *const key2) const + { + return XMLString::equals ((const XMLCh*)key1, (const XMLCh*)key2); + } +}; + +/** + * Hasher for keys that are pointers. + */ +struct PtrHasher +{ + /** + * Returns a hash value based on the key + * + * @param key the key to be hashed + * @param mod the modulus the hasher should use + */ + XMLSize_t getHashVal(const void* key, XMLSize_t mod) const + { + return ((XMLSize_t)key) % mod; + } + + /** + * Compares two keys and determines if they are semantically equal + * + * @param key1 the first key to be compared + * @param key2 the second key to be compared + * + * @return true if they are equal + */ + bool equals(const void *const key1, const void *const key2) const + { + return key1 == key2; + } +}; + +XERCES_CPP_NAMESPACE_END + +#endif diff --git a/src/xercesc/util/RefHash2KeysTableOf.c b/src/xercesc/util/RefHash2KeysTableOf.c index f545fbff5..d37e00877 100644 --- a/src/xercesc/util/RefHash2KeysTableOf.c +++ b/src/xercesc/util/RefHash2KeysTableOf.c @@ -37,52 +37,72 @@ XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // RefHash2KeysTableOf: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> -RefHash2KeysTableOf<TVal>::RefHash2KeysTableOf( const XMLSize_t modulus - , const bool adoptElems - , MemoryManager* const manager) + +template <class TVal, class THasher> +RefHash2KeysTableOf<TVal, THasher>::RefHash2KeysTableOf( + const XMLSize_t modulus, + MemoryManager* const manager) + : fMemoryManager(manager) - , fAdoptedElems(adoptElems) + , fAdoptedElems(true) , fBucketList(0) , fHashModulus(modulus) , fCount(0) - , fHash(0) { initialize(modulus); } -template <class TVal> -RefHash2KeysTableOf<TVal>::RefHash2KeysTableOf( const XMLSize_t modulus - , const bool adoptElems - , HashBase* hashBase - , MemoryManager* const manager) +template <class TVal, class THasher> +RefHash2KeysTableOf<TVal, THasher>::RefHash2KeysTableOf( + const XMLSize_t modulus, + const THasher& hasher, + MemoryManager* const manager) + + : fMemoryManager(manager) + , fAdoptedElems(true) + , fBucketList(0) + , fHashModulus(modulus) + , fCount(0) + , fHasher (hasher) +{ + initialize(modulus); +} + +template <class TVal, class THasher> +RefHash2KeysTableOf<TVal, THasher>::RefHash2KeysTableOf( + const XMLSize_t modulus, + const bool adoptElems, + MemoryManager* const manager) + : fMemoryManager(manager) , fAdoptedElems(adoptElems) , fBucketList(0) , fHashModulus(modulus) , fCount(0) - , fHash(0) + { initialize(modulus); - // set hasher - fHash = hashBase; } -template <class TVal> -RefHash2KeysTableOf<TVal>::RefHash2KeysTableOf(const XMLSize_t modulus, - MemoryManager* const manager) +template <class TVal, class THasher> +RefHash2KeysTableOf<TVal, THasher>::RefHash2KeysTableOf( + const XMLSize_t modulus, + const bool adoptElems, + const THasher& hasher, + MemoryManager* const manager) + : fMemoryManager(manager) - , fAdoptedElems(true) + , fAdoptedElems(adoptElems) , fBucketList(0) , fHashModulus(modulus) , fCount(0) - , fHash(0) + , fHasher (hasher) { initialize(modulus); } -template <class TVal> -void RefHash2KeysTableOf<TVal>::initialize(const XMLSize_t modulus) +template <class TVal, class THasher> +void RefHash2KeysTableOf<TVal, THasher>::initialize(const XMLSize_t modulus) { if (modulus == 0) ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::HshTbl_ZeroModulus, fMemoryManager); @@ -95,27 +115,28 @@ void RefHash2KeysTableOf<TVal>::initialize(const XMLSize_t modulus) memset(fBucketList, 0, sizeof(fBucketList[0]) * fHashModulus); } -template <class TVal> RefHash2KeysTableOf<TVal>::~RefHash2KeysTableOf() +template <class TVal, class THasher> +RefHash2KeysTableOf<TVal, THasher>::~RefHash2KeysTableOf() { removeAll(); // Then delete the bucket list & hasher fMemoryManager->deallocate(fBucketList); //delete [] fBucketList; fBucketList = 0; - delete fHash; - fHash = 0; } // --------------------------------------------------------------------------- // RefHash2KeysTableOf: Element management // --------------------------------------------------------------------------- -template <class TVal> bool RefHash2KeysTableOf<TVal>::isEmpty() const +template <class TVal, class THasher> +bool RefHash2KeysTableOf<TVal, THasher>::isEmpty() const { return (fCount==0); } -template <class TVal> bool RefHash2KeysTableOf<TVal>:: +template <class TVal, class THasher> +bool RefHash2KeysTableOf<TVal, THasher>:: containsKey(const void* const key1, const int key2) const { XMLSize_t hashVal; @@ -123,11 +144,12 @@ containsKey(const void* const key1, const int key2) const return (findIt != 0); } -template <class TVal> void RefHash2KeysTableOf<TVal>:: +template <class TVal, class THasher> +void RefHash2KeysTableOf<TVal, THasher>:: removeKey(const void* const key1, const int key2) { // Hash the key - XMLSize_t hashVal = fHash==0?XMLString::hash((const XMLCh*)key1, fHashModulus) : fHash->getHashVal(key1, fHashModulus); + XMLSize_t hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // @@ -139,7 +161,7 @@ removeKey(const void* const key1, const int key2) while (curElem) { - if((key2==curElem->fKey2) && (fHash==0?XMLString::equals((const XMLCh*)key1, (const XMLCh*)curElem->fKey1) : fHash->equals(key1, curElem->fKey1))) + if((key2==curElem->fKey2) && (fHasher.equals(key1, curElem->fKey1))) { if (!lastElem) { @@ -174,11 +196,12 @@ removeKey(const void* const key1, const int key2) ThrowXMLwithMemMgr(NoSuchElementException, XMLExcepts::HshTbl_NoSuchKeyExists, fMemoryManager); } -template <class TVal> void RefHash2KeysTableOf<TVal>:: +template <class TVal, class THasher> +void RefHash2KeysTableOf<TVal, THasher>:: removeKey(const void* const key1) { // Hash the key - XMLSize_t hashVal = fHash==0?XMLString::hash((const XMLCh*)key1, fHashModulus) : fHash->getHashVal(key1, fHashModulus); + XMLSize_t hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // @@ -190,7 +213,7 @@ removeKey(const void* const key1) while (curElem) { - if(fHash==0?XMLString::equals((const XMLCh*)key1, (const XMLCh*)curElem->fKey1) : fHash->equals(key1, curElem->fKey1)) + if(fHasher.equals(key1, curElem->fKey1)) { if (!lastElem) { @@ -226,7 +249,8 @@ removeKey(const void* const key1) } } -template <class TVal> void RefHash2KeysTableOf<TVal>::removeAll() +template <class TVal, class THasher> +void RefHash2KeysTableOf<TVal, THasher>::removeAll() { if(isEmpty()) return; @@ -263,10 +287,11 @@ template <class TVal> void RefHash2KeysTableOf<TVal>::removeAll() } // this function transfer the data from key1 to key2 -template <class TVal> void RefHash2KeysTableOf<TVal>::transferElement(const void* const key1, void* key2) +template <class TVal, class THasher> +void RefHash2KeysTableOf<TVal, THasher>::transferElement(const void* const key1, void* key2) { // Hash the key - XMLSize_t hashVal = fHash==0?XMLString::hash((const XMLCh*)key1, fHashModulus) : fHash->getHashVal(key1, fHashModulus); + XMLSize_t hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // @@ -279,7 +304,7 @@ template <class TVal> void RefHash2KeysTableOf<TVal>::transferElement(const void while (curElem) { // if this element has the same primary key, remove it and add it using the new primary key - if(fHash==0?XMLString::equals((const XMLCh*)key1, (const XMLCh*)curElem->fKey1) : fHash->equals(key1, curElem->fKey1)) + if(fHasher.equals(key1, curElem->fKey1)) { if (!lastElem) { @@ -336,7 +361,8 @@ template <class TVal> void RefHash2KeysTableOf<TVal>::transferElement(const void // --------------------------------------------------------------------------- // RefHash2KeysTableOf: Getters // --------------------------------------------------------------------------- -template <class TVal> TVal* RefHash2KeysTableOf<TVal>::get(const void* const key1, const int key2) +template <class TVal, class THasher> +TVal* RefHash2KeysTableOf<TVal, THasher>::get(const void* const key1, const int key2) { XMLSize_t hashVal; RefHash2KeysTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, hashVal); @@ -345,7 +371,8 @@ template <class TVal> TVal* RefHash2KeysTableOf<TVal>::get(const void* const key return findIt->fData; } -template <class TVal> const TVal* RefHash2KeysTableOf<TVal>:: +template <class TVal, class THasher> +const TVal* RefHash2KeysTableOf<TVal, THasher>:: get(const void* const key1, const int key2) const { XMLSize_t hashVal; @@ -355,14 +382,14 @@ get(const void* const key1, const int key2) const return findIt->fData; } -template <class TVal> -MemoryManager* RefHash2KeysTableOf<TVal>::getMemoryManager() const +template <class TVal, class THasher> +MemoryManager* RefHash2KeysTableOf<TVal, THasher>::getMemoryManager() const { return fMemoryManager; } -template <class TVal> -XMLSize_t RefHash2KeysTableOf<TVal>::getHashModulus() const +template <class TVal, class THasher> +XMLSize_t RefHash2KeysTableOf<TVal, THasher>::getHashModulus() const { return fHashModulus; } @@ -370,7 +397,8 @@ XMLSize_t RefHash2KeysTableOf<TVal>::getHashModulus() const // --------------------------------------------------------------------------- // RefHash2KeysTableOf: Putters // --------------------------------------------------------------------------- -template <class TVal> void RefHash2KeysTableOf<TVal>::put(void* key1, int key2, TVal* const valueToAdopt) +template <class TVal, class THasher> +void RefHash2KeysTableOf<TVal, THasher>::put(void* key1, int key2, TVal* const valueToAdopt) { // Apply 4 load factor to find threshold. XMLSize_t threshold = fHashModulus * 4; @@ -410,18 +438,19 @@ template <class TVal> void RefHash2KeysTableOf<TVal>::put(void* key1, int key2, // --------------------------------------------------------------------------- // RefHash2KeysTableOf: Private methods // --------------------------------------------------------------------------- -template <class TVal> RefHash2KeysTableBucketElem<TVal>* RefHash2KeysTableOf<TVal>:: +template <class TVal, class THasher> +inline RefHash2KeysTableBucketElem<TVal>* RefHash2KeysTableOf<TVal, THasher>:: findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal) { // Hash the key - hashVal = fHash==0?XMLString::hash((const XMLCh*)key1, fHashModulus) : fHash->getHashVal(key1, fHashModulus); + hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key RefHash2KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if((key2==curElem->fKey2) && (fHash==0?XMLString::equals((const XMLCh*)key1, (const XMLCh*)curElem->fKey1) : fHash->equals(key1, curElem->fKey1))) + if((key2==curElem->fKey2) && (fHasher.equals(key1, curElem->fKey1))) return curElem; curElem = curElem->fNext; @@ -429,18 +458,19 @@ findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal) return 0; } -template <class TVal> const RefHash2KeysTableBucketElem<TVal>* RefHash2KeysTableOf<TVal>:: +template <class TVal, class THasher> +inline const RefHash2KeysTableBucketElem<TVal>* RefHash2KeysTableOf<TVal, THasher>:: findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal) const { // Hash the key - hashVal = fHash==0?XMLString::hash((const XMLCh*)key1, fHashModulus) : fHash->getHashVal(key1, fHashModulus); + hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key const RefHash2KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if((key2==curElem->fKey2) && (fHash==0?XMLString::equals((const XMLCh*)key1, (const XMLCh*)curElem->fKey1) : fHash->equals(key1, curElem->fKey1))) + if((key2==curElem->fKey2) && (fHasher.equals(key1, curElem->fKey1))) return curElem; curElem = curElem->fNext; @@ -449,7 +479,8 @@ findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal) const } -template <class TVal> void RefHash2KeysTableOf<TVal>:: +template <class TVal, class THasher> +void RefHash2KeysTableOf<TVal, THasher>:: rehash() { const XMLSize_t newMod = (fHashModulus * 8)+1; @@ -476,7 +507,7 @@ rehash() // Save the next element before we detach this one RefHash2KeysTableBucketElem<TVal>* nextElem = curElem->fNext; - const XMLSize_t hashVal = fHash==0?XMLString::hash((const XMLCh*)curElem->fKey1, newMod) : fHash->getHashVal(curElem->fKey1, newMod); + const XMLSize_t hashVal = fHasher.getHashVal(curElem->fKey1, newMod); assert(hashVal < newMod); RefHash2KeysTableBucketElem<TVal>* newHeadElem = newBucketList[hashVal]; @@ -506,8 +537,9 @@ rehash() // --------------------------------------------------------------------------- // RefHash2KeysTableOfEnumerator: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> RefHash2KeysTableOfEnumerator<TVal>:: -RefHash2KeysTableOfEnumerator(RefHash2KeysTableOf<TVal>* const toEnum +template <class TVal, class THasher> +RefHash2KeysTableOfEnumerator<TVal, THasher>:: +RefHash2KeysTableOfEnumerator(RefHash2KeysTableOf<TVal, THasher>* const toEnum , const bool adopt , MemoryManager* const manager) : fAdopted(adopt), fCurElem(0), fCurHash((XMLSize_t)-1), fToEnum(toEnum) @@ -527,7 +559,8 @@ RefHash2KeysTableOfEnumerator(RefHash2KeysTableOf<TVal>* const toEnum findNext(); } -template <class TVal> RefHash2KeysTableOfEnumerator<TVal>::~RefHash2KeysTableOfEnumerator() +template <class TVal, class THasher> +RefHash2KeysTableOfEnumerator<TVal, THasher>::~RefHash2KeysTableOfEnumerator() { if (fAdopted) delete fToEnum; @@ -537,7 +570,8 @@ template <class TVal> RefHash2KeysTableOfEnumerator<TVal>::~RefHash2KeysTableOfE // --------------------------------------------------------------------------- // RefHash2KeysTableOfEnumerator: Enum interface // --------------------------------------------------------------------------- -template <class TVal> bool RefHash2KeysTableOfEnumerator<TVal>::hasMoreElements() const +template <class TVal, class THasher> +bool RefHash2KeysTableOfEnumerator<TVal, THasher>::hasMoreElements() const { // // If our current has is at the max and there are no more elements @@ -548,7 +582,8 @@ template <class TVal> bool RefHash2KeysTableOfEnumerator<TVal>::hasMoreElements( return true; } -template <class TVal> TVal& RefHash2KeysTableOfEnumerator<TVal>::nextElement() +template <class TVal, class THasher> +TVal& RefHash2KeysTableOfEnumerator<TVal, THasher>::nextElement() { // Make sure we have an element to return if (!hasMoreElements()) @@ -564,7 +599,8 @@ template <class TVal> TVal& RefHash2KeysTableOfEnumerator<TVal>::nextElement() return *saveElem->fData; } -template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::nextElementKey(void*& retKey1, int& retKey2) +template <class TVal, class THasher> +void RefHash2KeysTableOfEnumerator<TVal, THasher>::nextElementKey(void*& retKey1, int& retKey2) { // Make sure we have an element to return if (!hasMoreElements()) @@ -583,10 +619,11 @@ template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::nextElementKey(v return; } -template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::Reset() +template <class TVal, class THasher> +void RefHash2KeysTableOfEnumerator<TVal, THasher>::Reset() { if(fLockPrimaryKey) - fCurHash=fToEnum->fHash==0?XMLString::hash((const XMLCh*)fLockPrimaryKey, fToEnum->fHashModulus) : fToEnum->fHash->getHashVal(fLockPrimaryKey, fToEnum->fHashModulus); + fCurHash=fToEnum->fHasher.getHashVal(fLockPrimaryKey, fToEnum->fHashModulus); else fCurHash = (XMLSize_t)-1; @@ -595,7 +632,8 @@ template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::Reset() } -template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::setPrimaryKey(const void* key) +template <class TVal, class THasher> +void RefHash2KeysTableOfEnumerator<TVal, THasher>::setPrimaryKey(const void* key) { fLockPrimaryKey=key; Reset(); @@ -604,7 +642,8 @@ template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::setPrimaryKey(co // --------------------------------------------------------------------------- // RefHash2KeysTableOfEnumerator: Private helper methods // --------------------------------------------------------------------------- -template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::findNext() +template <class TVal, class THasher> +void RefHash2KeysTableOfEnumerator<TVal, THasher>::findNext() { // Code to execute if we have to return only values with the primary key if(fLockPrimaryKey) @@ -613,8 +652,7 @@ template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::findNext() fCurElem = fToEnum->fBucketList[fCurHash]; else fCurElem = fCurElem->fNext; - while (fCurElem && - (fToEnum->fHash==0?!XMLString::equals((const XMLCh*)fLockPrimaryKey, (const XMLCh*)fCurElem->fKey1) : !fToEnum->fHash->equals(fLockPrimaryKey, fCurElem->fKey1))) + while (fCurElem && (!fToEnum->fHasher.equals(fLockPrimaryKey, fCurElem->fKey1))) fCurElem = fCurElem->fNext; // if we didn't found it, make so hasMoreElements() returns false if(!fCurElem) diff --git a/src/xercesc/util/RefHash2KeysTableOf.hpp b/src/xercesc/util/RefHash2KeysTableOf.hpp index 85d84cc04..d808abb8b 100644 --- a/src/xercesc/util/RefHash2KeysTableOf.hpp +++ b/src/xercesc/util/RefHash2KeysTableOf.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,31 +23,27 @@ #define XERCESC_INCLUDE_GUARD_REFHASH2KEYSTABLEOF_HPP -#include <xercesc/util/HashBase.hpp> +#include <xercesc/util/Hashers.hpp> #include <xercesc/util/IllegalArgumentException.hpp> #include <xercesc/util/NoSuchElementException.hpp> #include <xercesc/util/RuntimeException.hpp> -#include <xercesc/util/XMLString.hpp> -#include <xercesc/util/HashXMLCh.hpp> #include <xercesc/util/PlatformUtils.hpp> XERCES_CPP_NAMESPACE_BEGIN // This hash table is similar to RefHashTableOf with an additional integer as key2 +// Forward declare the enumerator so it can be our friend. // -// Forward declare the enumerator so he can be our friend. Can you say -// friend? Sure... -// -template <class TVal> class RefHash2KeysTableOfEnumerator; -template <class TVal> struct RefHash2KeysTableBucketElem; - +template <class TVal, class THasher = StringHasher> +class RefHash2KeysTableOfEnumerator; // // This should really be a nested class, but some of the compilers we // have to support cannot deal with that! // -template <class TVal> struct RefHash2KeysTableBucketElem +template <class TVal> +struct RefHash2KeysTableBucketElem { RefHash2KeysTableBucketElem(void* key1, int key2, TVal* const value, RefHash2KeysTableBucketElem<TVal>* next) : fData(value), fNext(next), fKey1(key1), fKey2(key2) @@ -55,10 +51,10 @@ template <class TVal> struct RefHash2KeysTableBucketElem } ~RefHash2KeysTableBucketElem() {}; - TVal* fData; + TVal* fData; RefHash2KeysTableBucketElem<TVal>* fNext; - void* fKey1; - int fKey2; + void* fKey1; + int fKey2; private: // ----------------------------------------------------------------------- @@ -69,35 +65,34 @@ private: }; -template <class TVal> class RefHash2KeysTableOf : public XMemory +template <class TVal, class THasher = StringHasher> +class RefHash2KeysTableOf : public XMemory { public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - // backwards compatability - default hasher is HashXMLCh - RefHash2KeysTableOf - ( - const XMLSize_t modulus - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - // backwards compatability - default hasher is HashXMLCh - RefHash2KeysTableOf - ( - const XMLSize_t modulus - , const bool adoptElems - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - // if a hash function is passed in, it will be deleted when the hashtable is deleted. - // use a new instance of the hasher class for each hashtable, otherwise one hashtable - // may delete the hasher of a different hashtable if both use the same hasher. - RefHash2KeysTableOf - ( - const XMLSize_t modulus - , const bool adoptElems - , HashBase* hashBase - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); + + RefHash2KeysTableOf( + const XMLSize_t modulus, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + + RefHash2KeysTableOf( + const XMLSize_t modulus, + const THasher& hasher, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + + RefHash2KeysTableOf( + const XMLSize_t modulus, + const bool adoptElems, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + + RefHash2KeysTableOf( + const XMLSize_t modulus, + const bool adoptElems, + const THasher& hasher, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + ~RefHash2KeysTableOf(); @@ -129,15 +124,15 @@ private : // ----------------------------------------------------------------------- // Declare our friends // ----------------------------------------------------------------------- - friend class RefHash2KeysTableOfEnumerator<TVal>; + friend class RefHash2KeysTableOfEnumerator<TVal, THasher>; + - private: // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- - RefHash2KeysTableOf(const RefHash2KeysTableOf<TVal>&); - RefHash2KeysTableOf<TVal>& operator=(const RefHash2KeysTableOf<TVal>&); + RefHash2KeysTableOf(const RefHash2KeysTableOf<TVal, THasher>&); + RefHash2KeysTableOf<TVal>& operator=(const RefHash2KeysTableOf<TVal, THasher>&); // ----------------------------------------------------------------------- // Private methods @@ -175,7 +170,7 @@ private: RefHash2KeysTableBucketElem<TVal>** fBucketList; XMLSize_t fHashModulus; XMLSize_t fCount; - HashBase* fHash; + THasher fHasher; }; @@ -184,15 +179,16 @@ private: // An enumerator for a value array. It derives from the basic enumerator // class, so that value vectors can be generically enumerated. // -template <class TVal> class RefHash2KeysTableOfEnumerator : public XMLEnumerator<TVal>, public XMemory +template <class TVal, class THasher> +class RefHash2KeysTableOfEnumerator : public XMLEnumerator<TVal>, public XMemory { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - RefHash2KeysTableOfEnumerator(RefHash2KeysTableOf<TVal>* const toEnum - , const bool adopt = false - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + RefHash2KeysTableOfEnumerator(RefHash2KeysTableOf<TVal, THasher>* const toEnum + , const bool adopt = false + , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); virtual ~RefHash2KeysTableOfEnumerator(); @@ -204,7 +200,7 @@ public : void Reset(); // ----------------------------------------------------------------------- - // New interface + // New interface // ----------------------------------------------------------------------- void nextElementKey(void*&, int&); void setPrimaryKey(const void* key); @@ -213,8 +209,8 @@ private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- - RefHash2KeysTableOfEnumerator(const RefHash2KeysTableOfEnumerator<TVal>&); - RefHash2KeysTableOfEnumerator<TVal>& operator=(const RefHash2KeysTableOfEnumerator<TVal>&); + RefHash2KeysTableOfEnumerator(const RefHash2KeysTableOfEnumerator<TVal, THasher>&); + RefHash2KeysTableOfEnumerator<TVal, THasher>& operator=(const RefHash2KeysTableOfEnumerator<TVal, THasher>&); // ----------------------------------------------------------------------- // Private methods @@ -248,7 +244,7 @@ private : bool fAdopted; RefHash2KeysTableBucketElem<TVal>* fCurElem; XMLSize_t fCurHash; - RefHash2KeysTableOf<TVal>* fToEnum; + RefHash2KeysTableOf<TVal, THasher>* fToEnum; MemoryManager* const fMemoryManager; const void* fLockPrimaryKey; }; diff --git a/src/xercesc/util/RefHash3KeysIdPool.c b/src/xercesc/util/RefHash3KeysIdPool.c index 69722d42f..ddcba863a 100644 --- a/src/xercesc/util/RefHash3KeysIdPool.c +++ b/src/xercesc/util/RefHash3KeysIdPool.c @@ -36,23 +36,50 @@ XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // RefHash3KeysIdPool: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> -RefHash3KeysIdPool<TVal>::RefHash3KeysIdPool( const XMLSize_t modulus - , const bool adoptElems - , const XMLSize_t initSize - , MemoryManager* const manager) : - fMemoryManager(manager) - , fAdoptedElems(adoptElems) +template <class TVal, class THasher> +RefHash3KeysIdPool<TVal, THasher>::RefHash3KeysIdPool( + const XMLSize_t modulus, + const XMLSize_t initSize, + MemoryManager* const manager) + + : fMemoryManager(manager) + , fAdoptedElems(true) , fBucketList(0) , fHashModulus(modulus) - , fHash(0) , fIdPtrs(0) , fIdPtrsCount(initSize) , fIdCounter(0) { initialize(modulus); + // Allocate the initial id pointers array. We don't have to zero them + // out since the fIdCounter value tells us which ones are valid. The + // zeroth element is never used (and represents an invalid pool id.) // + if (!fIdPtrsCount) + fIdPtrsCount = 256; + fIdPtrs = (TVal**) fMemoryManager->allocate(fIdPtrsCount * sizeof(TVal*)); //new TVal*[fIdPtrsCount]; + fIdPtrs[0] = 0; +} + +template <class TVal, class THasher> +RefHash3KeysIdPool<TVal, THasher>::RefHash3KeysIdPool( + const XMLSize_t modulus, + const THasher& hasher, + const XMLSize_t initSize, + MemoryManager* const manager) + + : fMemoryManager(manager) + , fAdoptedElems(true) + , fBucketList(0) + , fHashModulus(modulus) + , fHasher(hasher) + , fIdPtrs(0) + , fIdPtrsCount(initSize) + , fIdCounter(0) +{ + initialize(modulus); + // Allocate the initial id pointers array. We don't have to zero them // out since the fIdCounter value tells us which ones are valid. The // zeroth element is never used (and represents an invalid pool id.) @@ -63,26 +90,24 @@ RefHash3KeysIdPool<TVal>::RefHash3KeysIdPool( const XMLSize_t modulus fIdPtrs[0] = 0; } -template <class TVal> -RefHash3KeysIdPool<TVal>::RefHash3KeysIdPool( const XMLSize_t modulus - , const bool adoptElems - , HashBase* hashBase - , const XMLSize_t initSize - , MemoryManager* const manager) : - fMemoryManager(manager) +template <class TVal, class THasher> +RefHash3KeysIdPool<TVal, THasher>::RefHash3KeysIdPool( + const XMLSize_t modulus, + const bool adoptElems, + const XMLSize_t initSize, + MemoryManager* const manager) + + : fMemoryManager(manager) , fAdoptedElems(adoptElems) , fBucketList(0) , fHashModulus(modulus) - , fHash(0) , fIdPtrs(0) , fIdPtrsCount(initSize) , fIdCounter(0) + { initialize(modulus); - // set hasher - fHash = hashBase; - // // Allocate the initial id pointers array. We don't have to zero them // out since the fIdCounter value tells us which ones are valid. The // zeroth element is never used (and represents an invalid pool id.) @@ -93,22 +118,25 @@ RefHash3KeysIdPool<TVal>::RefHash3KeysIdPool( const XMLSize_t modulus fIdPtrs[0] = 0; } -template <class TVal> -RefHash3KeysIdPool<TVal>::RefHash3KeysIdPool( const XMLSize_t modulus - , const XMLSize_t initSize - , MemoryManager* const manager) : - fMemoryManager(manager) - , fAdoptedElems(true) +template <class TVal, class THasher> +RefHash3KeysIdPool<TVal, THasher>::RefHash3KeysIdPool( + const XMLSize_t modulus, + const bool adoptElems, + const THasher& hasher, + const XMLSize_t initSize, + MemoryManager* const manager) + + : fMemoryManager(manager) + , fAdoptedElems(adoptElems) , fBucketList(0) , fHashModulus(modulus) - , fHash(0) + , fHasher(hasher) , fIdPtrs(0) , fIdPtrsCount(initSize) , fIdCounter(0) { initialize(modulus); - // // Allocate the initial id pointers array. We don't have to zero them // out since the fIdCounter value tells us which ones are valid. The // zeroth element is never used (and represents an invalid pool id.) @@ -119,7 +147,8 @@ RefHash3KeysIdPool<TVal>::RefHash3KeysIdPool( const XMLSize_t modulus fIdPtrs[0] = 0; } -template <class TVal> void RefHash3KeysIdPool<TVal>::initialize(const XMLSize_t modulus) +template <class TVal, class THasher> +void RefHash3KeysIdPool<TVal, THasher>::initialize(const XMLSize_t modulus) { if (modulus == 0) ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::HshTbl_ZeroModulus, fMemoryManager); @@ -132,7 +161,8 @@ template <class TVal> void RefHash3KeysIdPool<TVal>::initialize(const XMLSize_t memset(fBucketList, 0, sizeof(fBucketList[0]) * fHashModulus); } -template <class TVal> RefHash3KeysIdPool<TVal>::~RefHash3KeysIdPool() +template <class TVal, class THasher> +RefHash3KeysIdPool<TVal, THasher>::~RefHash3KeysIdPool() { removeAll(); @@ -141,15 +171,14 @@ template <class TVal> RefHash3KeysIdPool<TVal>::~RefHash3KeysIdPool() fIdPtrs = 0; fMemoryManager->deallocate(fBucketList); //delete [] fBucketList; fBucketList = 0; - delete fHash; - fHash = 0; } // --------------------------------------------------------------------------- // RefHash3KeysIdPool: Element management // --------------------------------------------------------------------------- -template <class TVal> bool RefHash3KeysIdPool<TVal>::isEmpty() const +template <class TVal, class THasher> +bool RefHash3KeysIdPool<TVal, THasher>::isEmpty() const { // Just check the bucket list for non-empty elements for (XMLSize_t buckInd = 0; buckInd < fHashModulus; buckInd++) @@ -160,7 +189,8 @@ template <class TVal> bool RefHash3KeysIdPool<TVal>::isEmpty() const return true; } -template <class TVal> bool RefHash3KeysIdPool<TVal>:: +template <class TVal, class THasher> +bool RefHash3KeysIdPool<TVal, THasher>:: containsKey(const void* const key1, const int key2, const int key3) const { XMLSize_t hashVal; @@ -168,7 +198,8 @@ containsKey(const void* const key1, const int key2, const int key3) const return (findIt != 0); } -template <class TVal> void RefHash3KeysIdPool<TVal>::removeAll() +template <class TVal, class THasher> +void RefHash3KeysIdPool<TVal, THasher>::removeAll() { if (fIdCounter == 0) return; @@ -210,8 +241,9 @@ template <class TVal> void RefHash3KeysIdPool<TVal>::removeAll() // --------------------------------------------------------------------------- // RefHash3KeysIdPool: Getters // --------------------------------------------------------------------------- -template <class TVal> TVal* -RefHash3KeysIdPool<TVal>::getByKey(const void* const key1, const int key2, const int key3) +template <class TVal, class THasher> +TVal* +RefHash3KeysIdPool<TVal, THasher>::getByKey(const void* const key1, const int key2, const int key3) { XMLSize_t hashVal; RefHash3KeysTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, key3, hashVal); @@ -220,8 +252,9 @@ RefHash3KeysIdPool<TVal>::getByKey(const void* const key1, const int key2, const return findIt->fData; } -template <class TVal> const TVal* -RefHash3KeysIdPool<TVal>::getByKey(const void* const key1, const int key2, const int key3) const +template <class TVal, class THasher> +const TVal* +RefHash3KeysIdPool<TVal, THasher>::getByKey(const void* const key1, const int key2, const int key3) const { XMLSize_t hashVal; const RefHash3KeysTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, key3, hashVal); @@ -230,8 +263,9 @@ RefHash3KeysIdPool<TVal>::getByKey(const void* const key1, const int key2, const return findIt->fData; } -template <class TVal> TVal* -RefHash3KeysIdPool<TVal>::getById(const unsigned int elemId) +template <class TVal, class THasher> +TVal* +RefHash3KeysIdPool<TVal, THasher>::getById(const unsigned int elemId) { // If its either zero or beyond our current id, its an error if (!elemId || (elemId > fIdCounter)) @@ -240,8 +274,9 @@ RefHash3KeysIdPool<TVal>::getById(const unsigned int elemId) return fIdPtrs[elemId]; } -template <class TVal> const TVal* -RefHash3KeysIdPool<TVal>::getById(const unsigned int elemId) const +template <class TVal, class THasher> +const TVal* +RefHash3KeysIdPool<TVal, THasher>::getById(const unsigned int elemId) const { // If its either zero or beyond our current id, its an error if (!elemId || (elemId > fIdCounter)) @@ -250,14 +285,14 @@ RefHash3KeysIdPool<TVal>::getById(const unsigned int elemId) const return fIdPtrs[elemId]; } -template <class TVal> -MemoryManager* RefHash3KeysIdPool<TVal>::getMemoryManager() const +template <class TVal, class THasher> +MemoryManager* RefHash3KeysIdPool<TVal, THasher>::getMemoryManager() const { return fMemoryManager; } -template <class TVal> -XMLSize_t RefHash3KeysIdPool<TVal>::getHashModulus() const +template <class TVal, class THasher> +XMLSize_t RefHash3KeysIdPool<TVal, THasher>::getHashModulus() const { return fHashModulus; } @@ -265,8 +300,9 @@ XMLSize_t RefHash3KeysIdPool<TVal>::getHashModulus() const // --------------------------------------------------------------------------- // RefHash3KeysIdPool: Putters // --------------------------------------------------------------------------- -template <class TVal> XMLSize_t -RefHash3KeysIdPool<TVal>::put(void* key1, int key2, int key3, TVal* const valueToAdopt) +template <class TVal, class THasher> +XMLSize_t +RefHash3KeysIdPool<TVal, THasher>::put(void* key1, int key2, int key3, TVal* const valueToAdopt) { // First see if the key exists already XMLSize_t hashVal; @@ -337,18 +373,19 @@ RefHash3KeysIdPool<TVal>::put(void* key1, int key2, int key3, TVal* const valueT // --------------------------------------------------------------------------- // RefHash3KeysIdPool: Private methods // --------------------------------------------------------------------------- -template <class TVal> RefHash3KeysTableBucketElem<TVal>* RefHash3KeysIdPool<TVal>:: +template <class TVal, class THasher> +inline RefHash3KeysTableBucketElem<TVal>* RefHash3KeysIdPool<TVal, THasher>:: findBucketElem(const void* const key1, const int key2, const int key3, XMLSize_t& hashVal) { // Hash the key - hashVal = fHash==0?XMLString::hash((const XMLCh*)key1, fHashModulus) : fHash->getHashVal(key1, fHashModulus); + hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key RefHash3KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if((key2==curElem->fKey2) && (key3==curElem->fKey3) && (fHash==0?XMLString::equals((const XMLCh*)key1, (const XMLCh*)curElem->fKey1) : fHash->equals(key1, curElem->fKey1))) + if((key2==curElem->fKey2) && (key3==curElem->fKey3) && (fHasher.equals(key1, curElem->fKey1))) return curElem; curElem = curElem->fNext; @@ -356,18 +393,19 @@ findBucketElem(const void* const key1, const int key2, const int key3, XMLSize_t return 0; } -template <class TVal> const RefHash3KeysTableBucketElem<TVal>* RefHash3KeysIdPool<TVal>:: +template <class TVal, class THasher> +inline const RefHash3KeysTableBucketElem<TVal>* RefHash3KeysIdPool<TVal, THasher>:: findBucketElem(const void* const key1, const int key2, const int key3, XMLSize_t& hashVal) const { // Hash the key - hashVal = fHash==0?XMLString::hash((const XMLCh*)key1, fHashModulus) : fHash->getHashVal(key1, fHashModulus); + hashVal = fHasher.getHashVal(key1, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key const RefHash3KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if((key2==curElem->fKey2) && (key3==curElem->fKey3) && (fHash==0?XMLString::equals((const XMLCh*)key1, (const XMLCh*)curElem->fKey1) : fHash->equals(key1, curElem->fKey1))) + if((key2==curElem->fKey2) && (key3==curElem->fKey3) && (fHasher.equals(key1, curElem->fKey1))) return curElem; curElem = curElem->fNext; @@ -379,8 +417,9 @@ findBucketElem(const void* const key1, const int key2, const int key3, XMLSize_t // --------------------------------------------------------------------------- // RefHash3KeysIdPoolEnumerator: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> RefHash3KeysIdPoolEnumerator<TVal>:: -RefHash3KeysIdPoolEnumerator(RefHash3KeysIdPool<TVal>* const toEnum +template <class TVal, class THasher> +RefHash3KeysIdPoolEnumerator<TVal, THasher>:: +RefHash3KeysIdPoolEnumerator(RefHash3KeysIdPool<TVal, THasher>* const toEnum , const bool adopt , MemoryManager* const manager) : fAdoptedElems(adopt), fCurIndex(0), fToEnum(toEnum), fMemoryManager(manager) @@ -392,14 +431,16 @@ RefHash3KeysIdPoolEnumerator(RefHash3KeysIdPool<TVal>* const toEnum resetKey(); } -template <class TVal> RefHash3KeysIdPoolEnumerator<TVal>::~RefHash3KeysIdPoolEnumerator() +template <class TVal, class THasher> +RefHash3KeysIdPoolEnumerator<TVal, THasher>::~RefHash3KeysIdPoolEnumerator() { if (fAdoptedElems) delete fToEnum; } -template <class TVal> RefHash3KeysIdPoolEnumerator<TVal>:: -RefHash3KeysIdPoolEnumerator(const RefHash3KeysIdPoolEnumerator<TVal>& toCopy) : +template <class TVal, class THasher> +RefHash3KeysIdPoolEnumerator<TVal, THasher>:: +RefHash3KeysIdPoolEnumerator(const RefHash3KeysIdPoolEnumerator<TVal, THasher>& toCopy) : XMLEnumerator<TVal>(toCopy) , XMemory(toCopy) , fAdoptedElems(toCopy.fAdoptedElems) @@ -414,7 +455,8 @@ RefHash3KeysIdPoolEnumerator(const RefHash3KeysIdPoolEnumerator<TVal>& toCopy) : // --------------------------------------------------------------------------- // RefHash3KeysIdPoolEnumerator: Enum interface // --------------------------------------------------------------------------- -template <class TVal> bool RefHash3KeysIdPoolEnumerator<TVal>::hasMoreElements() const +template <class TVal, class THasher> +bool RefHash3KeysIdPoolEnumerator<TVal, THasher>::hasMoreElements() const { // If our index is zero or past the end, then we are done if (!fCurIndex || (fCurIndex > fToEnum->fIdCounter)) @@ -422,7 +464,8 @@ template <class TVal> bool RefHash3KeysIdPoolEnumerator<TVal>::hasMoreElements() return true; } -template <class TVal> TVal& RefHash3KeysIdPoolEnumerator<TVal>::nextElement() +template <class TVal, class THasher> +TVal& RefHash3KeysIdPoolEnumerator<TVal, THasher>::nextElement() { // If our index is zero or past the end, then we are done if (!fCurIndex || (fCurIndex > fToEnum->fIdCounter)) @@ -432,7 +475,8 @@ template <class TVal> TVal& RefHash3KeysIdPoolEnumerator<TVal>::nextElement() return *fToEnum->fIdPtrs[fCurIndex++]; } -template <class TVal> void RefHash3KeysIdPoolEnumerator<TVal>::Reset() +template <class TVal, class THasher> +void RefHash3KeysIdPoolEnumerator<TVal, THasher>::Reset() { // // Find the next available bucket element in the pool. We use the id @@ -444,19 +488,22 @@ template <class TVal> void RefHash3KeysIdPoolEnumerator<TVal>::Reset() } -template <class TVal> XMLSize_t RefHash3KeysIdPoolEnumerator<TVal>::size() const +template <class TVal, class THasher> +XMLSize_t RefHash3KeysIdPoolEnumerator<TVal, THasher>::size() const { return fToEnum->fIdCounter; } -template <class TVal> void RefHash3KeysIdPoolEnumerator<TVal>::resetKey() +template <class TVal, class THasher> +void RefHash3KeysIdPoolEnumerator<TVal, THasher>::resetKey() { fCurHash = (XMLSize_t)-1; fCurElem = 0; findNext(); } -template <class TVal> bool RefHash3KeysIdPoolEnumerator<TVal>::hasMoreKeys() const +template <class TVal, class THasher> +bool RefHash3KeysIdPoolEnumerator<TVal, THasher>::hasMoreKeys() const { // // If our current has is at the max and there are no more elements @@ -468,7 +515,8 @@ template <class TVal> bool RefHash3KeysIdPoolEnumerator<TVal>::hasMoreKeys() con return true; } -template <class TVal> void RefHash3KeysIdPoolEnumerator<TVal>::nextElementKey(void*& retKey1, int& retKey2, int& retKey3) +template <class TVal, class THasher> +void RefHash3KeysIdPoolEnumerator<TVal, THasher>::nextElementKey(void*& retKey1, int& retKey2, int& retKey3) { // Make sure we have an element to return if (!hasMoreKeys()) @@ -488,7 +536,8 @@ template <class TVal> void RefHash3KeysIdPoolEnumerator<TVal>::nextElementKey(vo return; } -template <class TVal> void RefHash3KeysIdPoolEnumerator<TVal>::findNext() +template <class TVal, class THasher> +void RefHash3KeysIdPoolEnumerator<TVal, THasher>::findNext() { // // If there is a current element, move to its next element. If this diff --git a/src/xercesc/util/RefHash3KeysIdPool.hpp b/src/xercesc/util/RefHash3KeysIdPool.hpp index 514d12ae7..e1dd5b82c 100644 --- a/src/xercesc/util/RefHash3KeysIdPool.hpp +++ b/src/xercesc/util/RefHash3KeysIdPool.hpp @@ -23,32 +23,29 @@ #define XERCESC_INCLUDE_GUARD_REFHASH3KEYSIDPOOL_HPP -#include <xercesc/util/HashBase.hpp> +#include <xercesc/util/Hashers.hpp> #include <xercesc/util/IllegalArgumentException.hpp> #include <xercesc/util/NoSuchElementException.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/PlatformUtils.hpp> -#include <xercesc/util/XMLString.hpp> -#include <xercesc/util/HashXMLCh.hpp> XERCES_CPP_NAMESPACE_BEGIN // This hash table is a combination of RefHash2KeyTableOf (with an additional integer as key3) // and NameIdPool with an id as index +// Forward declare the enumerator so it can be our friend. // -// Forward declare the enumerator so he can be our friend. Can you say -// friend? Sure... -// -template <class TVal> class RefHash3KeysIdPoolEnumerator; -template <class TVal> struct RefHash3KeysTableBucketElem; +template <class TVal, class THasher = StringHasher> +class RefHash3KeysIdPoolEnumerator; // // This should really be a nested class, but some of the compilers we // have to support cannot deal with that! // -template <class TVal> struct RefHash3KeysTableBucketElem +template <class TVal> +struct RefHash3KeysTableBucketElem { RefHash3KeysTableBucketElem( void* key1 @@ -82,40 +79,36 @@ private: }; -template <class TVal> class RefHash3KeysIdPool : public XMemory +template <class TVal, class THasher = StringHasher> +class RefHash3KeysIdPool : public XMemory { public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - // backwards compatability - default hasher is HashXMLCh - RefHash3KeysIdPool - ( - const XMLSize_t modulus - , const XMLSize_t initSize = 128 - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - - // backwards compatability - default hasher is HashXMLCh - RefHash3KeysIdPool - ( - const XMLSize_t modulus - , const bool adoptElems - , const XMLSize_t initSize = 128 - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - - // if a hash function is passed in, it will be deleted when the hashtable is deleted. - // use a new instance of the hasher class for each hashtable, otherwise one hashtable - // may delete the hasher of a different hashtable if both use the same hasher. - RefHash3KeysIdPool - ( - const XMLSize_t modulus - , const bool adoptElems - , HashBase* hashBase - , const XMLSize_t initSize = 128 - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); + RefHash3KeysIdPool( + const XMLSize_t modulus, + const XMLSize_t initSize = 128, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + + RefHash3KeysIdPool( + const XMLSize_t modulus, + const THasher& hasher, + const XMLSize_t initSize = 128, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + + RefHash3KeysIdPool( + const XMLSize_t modulus, + const bool adoptElems, + const XMLSize_t initSize = 128, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + + RefHash3KeysIdPool( + const XMLSize_t modulus, + const bool adoptElems, + const THasher& hasher, + const XMLSize_t initSize = 128, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); ~RefHash3KeysIdPool(); @@ -142,21 +135,21 @@ public: // ----------------------------------------------------------------------- // Putters // ----------------------------------------------------------------------- - XMLSize_t put(void* key1, int key2, int key3, TVal* const valueToAdopt); + XMLSize_t put(void* key1, int key2, int key3, TVal* const valueToAdopt); private : // ----------------------------------------------------------------------- // Declare our friends // ----------------------------------------------------------------------- - friend class RefHash3KeysIdPoolEnumerator<TVal>; + friend class RefHash3KeysIdPoolEnumerator<TVal, THasher>; private: // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- - RefHash3KeysIdPool(const RefHash3KeysIdPool<TVal>&); - RefHash3KeysIdPool<TVal>& operator=(const RefHash3KeysIdPool<TVal>&); + RefHash3KeysIdPool(const RefHash3KeysIdPool<TVal, THasher>&); + RefHash3KeysIdPool<TVal, THasher>& operator=(const RefHash3KeysIdPool<TVal, THasher>&); // ----------------------------------------------------------------------- // Private methods @@ -203,10 +196,10 @@ private: bool fAdoptedElems; RefHash3KeysTableBucketElem<TVal>** fBucketList; XMLSize_t fHashModulus; - HashBase* fHash; + THasher fHasher; TVal** fIdPtrs; XMLSize_t fIdPtrsCount; - XMLSize_t fIdCounter; + XMLSize_t fIdCounter; }; @@ -215,18 +208,19 @@ private: // An enumerator for a value array. It derives from the basic enumerator // class, so that value vectors can be generically enumerated. // -template <class TVal> class RefHash3KeysIdPoolEnumerator : public XMLEnumerator<TVal>, public XMemory +template <class TVal, class THasher> +class RefHash3KeysIdPoolEnumerator : public XMLEnumerator<TVal>, public XMemory { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - RefHash3KeysIdPoolEnumerator(RefHash3KeysIdPool<TVal>* const toEnum + RefHash3KeysIdPoolEnumerator(RefHash3KeysIdPool<TVal, THasher>* const toEnum , const bool adopt = false , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); virtual ~RefHash3KeysIdPoolEnumerator(); - RefHash3KeysIdPoolEnumerator(const RefHash3KeysIdPoolEnumerator<TVal>&); + RefHash3KeysIdPoolEnumerator(const RefHash3KeysIdPoolEnumerator<TVal, THasher>&); // ----------------------------------------------------------------------- // Enum interface // ----------------------------------------------------------------------- @@ -246,7 +240,8 @@ private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- - RefHash3KeysIdPoolEnumerator<TVal>& operator=(const RefHash3KeysIdPoolEnumerator<TVal>&); + RefHash3KeysIdPoolEnumerator<TVal, THasher>& + operator=(const RefHash3KeysIdPoolEnumerator<TVal, THasher>&); // ----------------------------------------------------------------------- // Private methods @@ -269,7 +264,7 @@ private : // ----------------------------------------------------------------------- bool fAdoptedElems; XMLSize_t fCurIndex; - RefHash3KeysIdPool<TVal>* fToEnum; + RefHash3KeysIdPool<TVal, THasher>* fToEnum; RefHash3KeysTableBucketElem<TVal>* fCurElem; XMLSize_t fCurHash; MemoryManager* const fMemoryManager; diff --git a/src/xercesc/util/RefHashTableOf.hpp b/src/xercesc/util/RefHashTableOf.hpp index 8d256c077..12572eb6d 100644 --- a/src/xercesc/util/RefHashTableOf.hpp +++ b/src/xercesc/util/RefHashTableOf.hpp @@ -22,49 +22,16 @@ #if !defined(XERCESC_INCLUDE_GUARD_REFHASHTABLEOF_HPP) #define XERCESC_INCLUDE_GUARD_REFHASHTABLEOF_HPP +#include <xercesc/util/Hashers.hpp> #include <xercesc/util/IllegalArgumentException.hpp> #include <xercesc/util/NoSuchElementException.hpp> #include <xercesc/util/RuntimeException.hpp> -#include <xercesc/util/XMLString.hpp> -#include <xercesc/util/HashXMLCh.hpp> #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/framework/MemoryManager.hpp> XERCES_CPP_NAMESPACE_BEGIN -// Default hasher for keys that are const XMLCh*. -// -struct StringHasher -{ - XMLSize_t getHashVal(const void* key, XMLSize_t mod) const - { - return XMLString::hash ((const XMLCh*)key, mod); - } - - bool equals(const void *const key1, const void *const key2) const - { - return XMLString::equals ((const XMLCh*)key1, (const XMLCh*)key2); - } -}; - -// Some common hashers. -// -struct PtrHasher -{ - XMLSize_t getHashVal(const void* key, XMLSize_t mod) const - { - return ((XMLSize_t)key) % mod; - } - - bool equals(const void *const key1, const void *const key2) const - { - return key1 == key2; - } -}; - -// -// Forward declare the enumerator so he can be our friend. Can you say -// friend? Sure... +// Forward declare the enumerator so it can be our friend. // template <class TVal, class THasher = StringHasher> class RefHashTableOfEnumerator; diff --git a/src/xercesc/util/ValueHashTableOf.c b/src/xercesc/util/ValueHashTableOf.c index 45519993c..b8925ac89 100644 --- a/src/xercesc/util/ValueHashTableOf.c +++ b/src/xercesc/util/ValueHashTableOf.c @@ -37,39 +37,35 @@ XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // ValueHashTableOf: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> -ValueHashTableOf<TVal>::ValueHashTableOf( const XMLSize_t modulus - , HashBase* hashBase - , MemoryManager* const manager) +template <class TVal, class THasher> +ValueHashTableOf<TVal, THasher>::ValueHashTableOf( const XMLSize_t modulus + , const THasher& hasher + , MemoryManager* const manager) : fMemoryManager(manager) , fBucketList(0) , fHashModulus(modulus) , fInitialModulus(modulus) , fCount(0) - , fHash(0) + , fHasher(hasher) { initialize(modulus); - // set hasher - fHash = hashBase; } -template <class TVal> -ValueHashTableOf<TVal>::ValueHashTableOf( const XMLSize_t modulus - , MemoryManager* const manager) +template <class TVal, class THasher> +ValueHashTableOf<TVal, THasher>::ValueHashTableOf( const XMLSize_t modulus + , MemoryManager* const manager) : fMemoryManager(manager) , fBucketList(0) , fHashModulus(modulus) , fInitialModulus(modulus) , fCount(0) - , fHash(0) + , fHasher() { initialize(modulus); - - // create default hasher - fHash = new (fMemoryManager) HashXMLCh(); } -template <class TVal> void ValueHashTableOf<TVal>::initialize(const XMLSize_t modulus) +template <class TVal, class THasher> +void ValueHashTableOf<TVal, THasher>::initialize(const XMLSize_t modulus) { if (modulus == 0) ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::HshTbl_ZeroModulus, fMemoryManager); @@ -82,25 +78,27 @@ template <class TVal> void ValueHashTableOf<TVal>::initialize(const XMLSize_t mo memset(fBucketList, 0, sizeof(fBucketList[0]) * fHashModulus); } -template <class TVal> ValueHashTableOf<TVal>::~ValueHashTableOf() +template <class TVal, class THasher> +ValueHashTableOf<TVal, THasher>::~ValueHashTableOf() { removeAll(); // Then delete the bucket list & hasher fMemoryManager->deallocate(fBucketList); //delete [] fBucketList; - delete fHash; } // --------------------------------------------------------------------------- // ValueHashTableOf: Element management // --------------------------------------------------------------------------- -template <class TVal> bool ValueHashTableOf<TVal>::isEmpty() const +template <class TVal, class THasher> +bool ValueHashTableOf<TVal, THasher>::isEmpty() const { return fCount==0; } -template <class TVal> bool ValueHashTableOf<TVal>:: +template <class TVal, class THasher> +bool ValueHashTableOf<TVal, THasher>:: containsKey(const void* const key) const { XMLSize_t hashVal; @@ -108,14 +106,16 @@ containsKey(const void* const key) const return (findIt != 0); } -template <class TVal> void ValueHashTableOf<TVal>:: +template <class TVal, class THasher> +void ValueHashTableOf<TVal, THasher>:: removeKey(const void* const key) { XMLSize_t hashVal; removeBucketElem(key, hashVal); } -template <class TVal> void ValueHashTableOf<TVal>::removeAll() +template <class TVal, class THasher> +void ValueHashTableOf<TVal, THasher>::removeAll() { if(isEmpty()) return; @@ -148,7 +148,8 @@ template <class TVal> void ValueHashTableOf<TVal>::removeAll() // --------------------------------------------------------------------------- // ValueHashTableOf: Getters // --------------------------------------------------------------------------- -template <class TVal> TVal& ValueHashTableOf<TVal>::get(const void* const key, MemoryManager* const manager) +template <class TVal, class THasher> +TVal& ValueHashTableOf<TVal, THasher>::get(const void* const key, MemoryManager* const manager) { XMLSize_t hashVal; ValueHashTableBucketElem<TVal>* findIt = findBucketElem(key, hashVal); @@ -158,7 +159,8 @@ template <class TVal> TVal& ValueHashTableOf<TVal>::get(const void* const key, M return findIt->fData; } -template <class TVal> const TVal& ValueHashTableOf<TVal>:: +template <class TVal, class THasher> +const TVal& ValueHashTableOf<TVal, THasher>:: get(const void* const key) const { XMLSize_t hashVal; @@ -173,7 +175,8 @@ get(const void* const key) const // --------------------------------------------------------------------------- // ValueHashTableOf: Putters // --------------------------------------------------------------------------- -template <class TVal> void ValueHashTableOf<TVal>::put(void* key, const TVal& valueToAdopt) +template <class TVal, class THasher> +void ValueHashTableOf<TVal, THasher>::put(void* key, const TVal& valueToAdopt) { // Apply 0.75 load factor to find threshold. XMLSize_t threshold = fHashModulus * 3 / 4; @@ -210,7 +213,8 @@ template <class TVal> void ValueHashTableOf<TVal>::put(void* key, const TVal& va // --------------------------------------------------------------------------- // ValueHashTableOf: Private methods // --------------------------------------------------------------------------- -template <class TVal> void ValueHashTableOf<TVal>::rehash() +template <class TVal, class THasher> +void ValueHashTableOf<TVal, THasher>::rehash() { const XMLSize_t newMod = (fHashModulus * 2) + 1; @@ -238,7 +242,7 @@ template <class TVal> void ValueHashTableOf<TVal>::rehash() // Save the next element before we detach this one ValueHashTableBucketElem<TVal>* const nextElem = curElem->fNext; - const XMLSize_t hashVal = fHash->getHashVal(curElem->fKey, newMod); + const XMLSize_t hashVal = fHasher.getHashVal(curElem->fKey, newMod); assert(hashVal < newMod); ValueHashTableBucketElem<TVal>* const newHeadElem = newBucketList[hashVal]; @@ -263,18 +267,19 @@ template <class TVal> void ValueHashTableOf<TVal>::rehash() } -template <class TVal> ValueHashTableBucketElem<TVal>* ValueHashTableOf<TVal>:: +template <class TVal, class THasher> +inline ValueHashTableBucketElem<TVal>* ValueHashTableOf<TVal, THasher>:: findBucketElem(const void* const key, XMLSize_t& hashVal) { // Hash the key - hashVal = fHash->getHashVal(key, fHashModulus); + hashVal = fHasher.getHashVal(key, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key ValueHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if (fHash->equals(key, curElem->fKey)) + if (fHasher.equals(key, curElem->fKey)) return curElem; curElem = curElem->fNext; @@ -282,18 +287,19 @@ findBucketElem(const void* const key, XMLSize_t& hashVal) return 0; } -template <class TVal> const ValueHashTableBucketElem<TVal>* ValueHashTableOf<TVal>:: +template <class TVal, class THasher> +inline const ValueHashTableBucketElem<TVal>* ValueHashTableOf<TVal, THasher>:: findBucketElem(const void* const key, XMLSize_t& hashVal) const { // Hash the key - hashVal = fHash->getHashVal(key, fHashModulus); + hashVal = fHasher.getHashVal(key, fHashModulus); assert(hashVal < fHashModulus); // Search that bucket for the key const ValueHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if (fHash->equals(key, curElem->fKey)) + if (fHasher.equals(key, curElem->fKey)) return curElem; curElem = curElem->fNext; @@ -302,11 +308,12 @@ findBucketElem(const void* const key, XMLSize_t& hashVal) const } -template <class TVal> void ValueHashTableOf<TVal>:: +template <class TVal, class THasher> +void ValueHashTableOf<TVal, THasher>:: removeBucketElem(const void* const key, XMLSize_t& hashVal) { // Hash the key - hashVal = fHash->getHashVal(key, fHashModulus); + hashVal = fHasher.getHashVal(key, fHashModulus); assert(hashVal < fHashModulus); // @@ -318,7 +325,7 @@ removeBucketElem(const void* const key, XMLSize_t& hashVal) while (curElem) { - if (fHash->equals(key, curElem->fKey)) + if (fHasher.equals(key, curElem->fKey)) { if (!lastElem) { @@ -357,8 +364,9 @@ removeBucketElem(const void* const key, XMLSize_t& hashVal) // --------------------------------------------------------------------------- // ValueHashTableOfEnumerator: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> ValueHashTableOfEnumerator<TVal>:: -ValueHashTableOfEnumerator(ValueHashTableOf<TVal>* const toEnum +template <class TVal, class THasher> +ValueHashTableOfEnumerator<TVal, THasher>:: +ValueHashTableOfEnumerator(ValueHashTableOf<TVal, THasher>* const toEnum , const bool adopt , MemoryManager* const manager) : fAdopted(adopt), fCurElem(0), fCurHash((XMLSize_t)-1), fToEnum(toEnum), fMemoryManager(manager) @@ -376,7 +384,8 @@ ValueHashTableOfEnumerator(ValueHashTableOf<TVal>* const toEnum findNext(); } -template <class TVal> ValueHashTableOfEnumerator<TVal>::~ValueHashTableOfEnumerator() +template <class TVal, class THasher> +ValueHashTableOfEnumerator<TVal, THasher>::~ValueHashTableOfEnumerator() { if (fAdopted) delete fToEnum; @@ -386,7 +395,8 @@ template <class TVal> ValueHashTableOfEnumerator<TVal>::~ValueHashTableOfEnumera // --------------------------------------------------------------------------- // ValueHashTableOfEnumerator: Enum interface // --------------------------------------------------------------------------- -template <class TVal> bool ValueHashTableOfEnumerator<TVal>::hasMoreElements() const +template <class TVal, class THasher> +bool ValueHashTableOfEnumerator<TVal, THasher>::hasMoreElements() const { // // If our current has is at the max and there are no more elements @@ -397,7 +407,8 @@ template <class TVal> bool ValueHashTableOfEnumerator<TVal>::hasMoreElements() c return true; } -template <class TVal> TVal& ValueHashTableOfEnumerator<TVal>::nextElement() +template <class TVal, class THasher> +TVal& ValueHashTableOfEnumerator<TVal, THasher>::nextElement() { // Make sure we have an element to return if (!hasMoreElements()) @@ -413,7 +424,8 @@ template <class TVal> TVal& ValueHashTableOfEnumerator<TVal>::nextElement() return saveElem->fData; } -template <class TVal> void* ValueHashTableOfEnumerator<TVal>::nextElementKey() +template <class TVal, class THasher> +void* ValueHashTableOfEnumerator<TVal, THasher>::nextElementKey() { // Make sure we have an element to return if (!hasMoreElements()) @@ -430,7 +442,8 @@ template <class TVal> void* ValueHashTableOfEnumerator<TVal>::nextElementKey() } -template <class TVal> void ValueHashTableOfEnumerator<TVal>::Reset() +template <class TVal, class THasher> +void ValueHashTableOfEnumerator<TVal, THasher>::Reset() { fCurHash = (XMLSize_t)-1; fCurElem = 0; @@ -442,7 +455,8 @@ template <class TVal> void ValueHashTableOfEnumerator<TVal>::Reset() // --------------------------------------------------------------------------- // ValueHashTableOfEnumerator: Private helper methods // --------------------------------------------------------------------------- -template <class TVal> void ValueHashTableOfEnumerator<TVal>::findNext() +template <class TVal, class THasher> +void ValueHashTableOfEnumerator<TVal, THasher>::findNext() { // // If there is a current element, move to its next element. If this diff --git a/src/xercesc/util/ValueHashTableOf.hpp b/src/xercesc/util/ValueHashTableOf.hpp index 0eff3b76a..a7cbe9dcf 100644 --- a/src/xercesc/util/ValueHashTableOf.hpp +++ b/src/xercesc/util/ValueHashTableOf.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,29 +23,26 @@ #define XERCESC_INCLUDE_GUARD_VALUEHASHTABLEOF_HPP -#include <xercesc/util/HashBase.hpp> +#include <xercesc/util/Hashers.hpp> #include <xercesc/util/IllegalArgumentException.hpp> #include <xercesc/util/NoSuchElementException.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/PlatformUtils.hpp> -#include <xercesc/util/XMLString.hpp> -#include <xercesc/util/HashXMLCh.hpp> XERCES_CPP_NAMESPACE_BEGIN +// Forward declare the enumerator so it can be our friend. // -// Forward declare the enumerator so he can be our friend. Can you say -// friend? Sure... -// -template <class TVal> class ValueHashTableOfEnumerator; -template <class TVal> struct ValueHashTableBucketElem; +template <class TVal, class THasher = StringHasher> +class ValueHashTableOfEnumerator; // // This should really be a nested class, but some of the compilers we // have to support cannot deal with that! // -template <class TVal> struct ValueHashTableBucketElem +template <class TVal> +struct ValueHashTableBucketElem { ValueHashTableBucketElem(void* key, const TVal& value, ValueHashTableBucketElem<TVal>* next) : fData(value), fNext(next), fKey(key) @@ -54,40 +51,35 @@ template <class TVal> struct ValueHashTableBucketElem ValueHashTableBucketElem(){}; ~ValueHashTableBucketElem(){}; - TVal fData; + TVal fData; ValueHashTableBucketElem<TVal>* fNext; - void* fKey; + void* fKey; private: // ----------------------------------------------------------------------- // Unimplemented constructors and operators - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- ValueHashTableBucketElem(const ValueHashTableBucketElem<TVal>&); ValueHashTableBucketElem<TVal>& operator=(const ValueHashTableBucketElem<TVal>&); }; -template <class TVal> class ValueHashTableOf : public XMemory +template <class TVal, class THasher = StringHasher> +class ValueHashTableOf : public XMemory { public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - // backwards compatability - default hasher is HashXMLCh - ValueHashTableOf - ( - const XMLSize_t modulus - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - // if a hash function is passed in, it will be deleted when the hashtable is deleted. - // use a new instance of the hasher class for each hashtable, otherwise one hashtable - // may delete the hasher of a different hashtable if both use the same hasher. - ValueHashTableOf - ( - const XMLSize_t modulus - , HashBase* hashBase - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); + ValueHashTableOf( + const XMLSize_t modulus, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + + ValueHashTableOf( + const XMLSize_t modulus, + const THasher& hasher, + MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + ~ValueHashTableOf(); @@ -110,21 +102,21 @@ public: // ----------------------------------------------------------------------- // Putters // ----------------------------------------------------------------------- - void put(void* key, const TVal& valueToAdopt); + void put(void* key, const TVal& valueToAdopt); private : // ----------------------------------------------------------------------- // Declare our friends // ----------------------------------------------------------------------- - friend class ValueHashTableOfEnumerator<TVal>; + friend class ValueHashTableOfEnumerator<TVal, THasher>; private: // ----------------------------------------------------------------------- // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - ValueHashTableOf(const ValueHashTableOf<TVal>&); - ValueHashTableOf<TVal>& operator=(const ValueHashTableOf<TVal>&); + // ----------------------------------------------------------------------- + ValueHashTableOf(const ValueHashTableOf<TVal, THasher>&); + ValueHashTableOf<TVal, THasher>& operator=(const ValueHashTableOf<TVal, THasher>&); // ----------------------------------------------------------------------- // Private methods @@ -132,8 +124,8 @@ private: ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal); const ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal) const; void removeBucketElem(const void* const key, XMLSize_t& hashVal); - void initialize(const XMLSize_t modulus); - void rehash(); + void initialize(const XMLSize_t modulus); + void rehash(); // ----------------------------------------------------------------------- @@ -146,16 +138,16 @@ private: // fHashModulus // The modulus used for this hash table, to hash the keys. This is // also the number of elements in the bucket list. - // - // fHash - // The hasher for the key data type. + // + // fHash + // The hasher for the key data type. // ----------------------------------------------------------------------- MemoryManager* fMemoryManager; ValueHashTableBucketElem<TVal>** fBucketList; XMLSize_t fHashModulus; XMLSize_t fInitialModulus; XMLSize_t fCount; - HashBase* fHash; + THasher fHasher; }; @@ -164,15 +156,16 @@ private: // An enumerator for a value array. It derives from the basic enumerator // class, so that value vectors can be generically enumerated. // -template <class TVal> class ValueHashTableOfEnumerator : public XMLEnumerator<TVal>, public XMemory +template <class TVal, class THasher> +class ValueHashTableOfEnumerator : public XMLEnumerator<TVal>, public XMemory { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - ValueHashTableOfEnumerator(ValueHashTableOf<TVal>* const toEnum - , const bool adopt = false - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + ValueHashTableOfEnumerator(ValueHashTableOf<TVal, THasher>* const toEnum + , const bool adopt = false + , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); virtual ~ValueHashTableOfEnumerator(); @@ -192,9 +185,9 @@ public : private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - ValueHashTableOfEnumerator(const ValueHashTableOfEnumerator<TVal>&); - ValueHashTableOfEnumerator<TVal>& operator=(const ValueHashTableOfEnumerator<TVal>&); + // ----------------------------------------------------------------------- + ValueHashTableOfEnumerator(const ValueHashTableOfEnumerator<TVal, THasher>&); + ValueHashTableOfEnumerator<TVal, THasher>& operator=(const ValueHashTableOfEnumerator<TVal, THasher>&); // ----------------------------------------------------------------------- // Private methods @@ -220,11 +213,11 @@ private : // fToEnum // The value array being enumerated. // ----------------------------------------------------------------------- - bool fAdopted; - ValueHashTableBucketElem<TVal>* fCurElem; - XMLSize_t fCurHash; - ValueHashTableOf<TVal>* fToEnum; - MemoryManager* const fMemoryManager; + bool fAdopted; + ValueHashTableBucketElem<TVal>* fCurElem; + XMLSize_t fCurHash; + ValueHashTableOf<TVal, THasher>* fToEnum; + MemoryManager* const fMemoryManager; }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/common/DFAContentModel.cpp b/src/xercesc/validators/common/DFAContentModel.cpp index c2274512b..6f776fe58 100644 --- a/src/xercesc/validators/common/DFAContentModel.cpp +++ b/src/xercesc/validators/common/DFAContentModel.cpp @@ -39,7 +39,6 @@ #include <xercesc/validators/schema/SubstitutionGroupComparator.hpp> #include <xercesc/validators/schema/XercesElementWildcard.hpp> #include <xercesc/util/RefHashTableOf.hpp> -#include <xercesc/util/HashCMStateSet.hpp> #include <xercesc/util/XMLInteger.hpp> XERCES_CPP_NAMESPACE_BEGIN diff --git a/src/xercesc/validators/schema/SchemaGrammar.cpp b/src/xercesc/validators/schema/SchemaGrammar.cpp index 64f0733d7..2a92cae79 100644 --- a/src/xercesc/validators/schema/SchemaGrammar.cpp +++ b/src/xercesc/validators/schema/SchemaGrammar.cpp @@ -29,7 +29,6 @@ #include <xercesc/validators/schema/XercesAttGroupInfo.hpp> #include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp> #include <xercesc/util/OutOfMemoryException.hpp> -#include <xercesc/util/HashPtr.hpp> #include <xercesc/framework/psvi/XSAnnotation.hpp> #include <xercesc/internal/XTemplateSerializer.hpp> diff --git a/src/xercesc/validators/schema/TraverseSchema.cpp b/src/xercesc/validators/schema/TraverseSchema.cpp index a5ee8cff9..1cefe1093 100644 --- a/src/xercesc/validators/schema/TraverseSchema.cpp +++ b/src/xercesc/validators/schema/TraverseSchema.cpp @@ -49,7 +49,6 @@ #include <xercesc/validators/schema/XercesAttGroupInfo.hpp> #include <xercesc/validators/schema/XSDLocator.hpp> #include <xercesc/validators/schema/XSDDOMParser.hpp> -#include <xercesc/util/HashPtr.hpp> #include <xercesc/dom/DOMNamedNodeMap.hpp> #include <xercesc/dom/DOMText.hpp> #include <xercesc/dom/impl/XSDElementNSImpl.hpp> diff --git a/src/xercesc/validators/schema/identity/FieldActivator.cpp b/src/xercesc/validators/schema/identity/FieldActivator.cpp index ad81da35b..8f93dd2ff 100644 --- a/src/xercesc/validators/schema/identity/FieldActivator.cpp +++ b/src/xercesc/validators/schema/identity/FieldActivator.cpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,7 +26,6 @@ #include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/validators/schema/identity/ValueStoreCache.hpp> #include <xercesc/validators/schema/identity/XPathMatcherStack.hpp> -#include <xercesc/util/HashPtr.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -41,7 +40,7 @@ FieldActivator::FieldActivator(ValueStoreCache* const valueStoreCache, , fMayMatch(0) , fMemoryManager(manager) { - fMayMatch = new (manager) ValueHashTableOf<bool>(29, new (manager) HashPtr(), manager); + fMayMatch = new (manager) ValueHashTableOf<bool, PtrHasher>(29, manager); } FieldActivator::FieldActivator(const FieldActivator& other) @@ -51,8 +50,8 @@ FieldActivator::FieldActivator(const FieldActivator& other) , fMayMatch(0) , fMemoryManager(other.fMemoryManager) { - fMayMatch = new (fMemoryManager) ValueHashTableOf<bool>(29, new (fMemoryManager) HashPtr(), fMemoryManager); - ValueHashTableOfEnumerator<bool> mayMatchEnum(other.fMayMatch, false, fMemoryManager); + fMayMatch = new (fMemoryManager) ValueHashTableOf<bool, PtrHasher>(29, fMemoryManager); + ValueHashTableOfEnumerator<bool, PtrHasher> mayMatchEnum(other.fMayMatch, false, fMemoryManager); // Build key set while (mayMatchEnum.hasMoreElements()) @@ -123,4 +122,3 @@ XERCES_CPP_NAMESPACE_END /** * End of file FieldActivator.cpp */ - diff --git a/src/xercesc/validators/schema/identity/FieldActivator.hpp b/src/xercesc/validators/schema/identity/FieldActivator.hpp index dd938af97..6e9dda3f9 100644 --- a/src/xercesc/validators/schema/identity/FieldActivator.hpp +++ b/src/xercesc/validators/schema/identity/FieldActivator.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -98,10 +98,10 @@ private: // ----------------------------------------------------------------------- // Data // ----------------------------------------------------------------------- - ValueStoreCache* fValueStoreCache; - XPathMatcherStack* fMatcherStack; - ValueHashTableOf<bool>* fMayMatch; - MemoryManager* fMemoryManager; + ValueStoreCache* fValueStoreCache; + XPathMatcherStack* fMatcherStack; + ValueHashTableOf<bool, PtrHasher>* fMayMatch; + MemoryManager* fMemoryManager; }; @@ -139,4 +139,3 @@ XERCES_CPP_NAMESPACE_END /** * End of file FieldActivator.hpp */ - diff --git a/src/xercesc/validators/schema/identity/ValueStoreCache.cpp b/src/xercesc/validators/schema/identity/ValueStoreCache.cpp index 202bce40e..bef10cea7 100644 --- a/src/xercesc/validators/schema/identity/ValueStoreCache.cpp +++ b/src/xercesc/validators/schema/identity/ValueStoreCache.cpp @@ -25,7 +25,6 @@ #include <xercesc/validators/schema/identity/ValueStoreCache.hpp> #include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/validators/schema/SchemaElementDecl.hpp> -#include <xercesc/util/HashPtr.hpp> #include <xercesc/util/OutOfMemoryException.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -132,11 +131,10 @@ void ValueStoreCache::init() { , false , fMemoryManager ); - fIC2ValueStoreMap = new (fMemoryManager) RefHash2KeysTableOf<ValueStore> + fIC2ValueStoreMap = new (fMemoryManager) RefHash2KeysTableOf<ValueStore, PtrHasher> ( 13 , false - , new (fMemoryManager) HashPtr() , fMemoryManager ); fGlobalMapStack = new (fMemoryManager) RefStackOf<RefHashTableOf<ValueStore, PtrHasher> >(8, true, fMemoryManager); diff --git a/src/xercesc/validators/schema/identity/ValueStoreCache.hpp b/src/xercesc/validators/schema/identity/ValueStoreCache.hpp index bcc20d480..bce984419 100644 --- a/src/xercesc/validators/schema/identity/ValueStoreCache.hpp +++ b/src/xercesc/validators/schema/identity/ValueStoreCache.hpp @@ -122,7 +122,7 @@ private: // ----------------------------------------------------------------------- RefVectorOf<ValueStore>* fValueStores; RefHashTableOf<ValueStore, PtrHasher>* fGlobalICMap; - RefHash2KeysTableOf<ValueStore>* fIC2ValueStoreMap; + RefHash2KeysTableOf<ValueStore, PtrHasher>* fIC2ValueStoreMap; RefStackOf<RefHashTableOf<ValueStore, PtrHasher> >* fGlobalMapStack; XMLScanner* fScanner; MemoryManager* fMemoryManager; diff --git a/tests/Makefile.am b/tests/Makefile.am index f462af61b..e9ec87ffe 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -71,8 +71,6 @@ InitTermTest_SOURCES = src/InitTermTest/InitTermTest.cp testprogs += MemHandlerTest MemHandlerTest_SOURCES = src/MemHandlerTest/MemoryMonitor.cpp \ src/MemHandlerTest/MemoryMonitor.hpp \ - src/MemHandlerTest/SimpleHashPtr.cpp \ - src/MemHandlerTest/SimpleHashPtr.hpp \ src/MemHandlerTest/SimpleValueHashTableOf.hpp testprogs += NetAccessorTest diff --git a/tests/src/MemHandlerTest/MemoryMonitor.hpp b/tests/src/MemHandlerTest/MemoryMonitor.hpp index 0e6a01b1e..9fd7243de 100755 --- a/tests/src/MemHandlerTest/MemoryMonitor.hpp +++ b/tests/src/MemHandlerTest/MemoryMonitor.hpp @@ -22,7 +22,6 @@ #include <xercesc/framework/MemoryManager.hpp> #include <xercesc/util/PlatformUtils.hpp> -#include "SimpleHashPtr.hpp" #include <xercesc/dom/DOMLSParser.hpp> #include <xercesc/dom/DOMErrorHandler.hpp> #include <xercesc/dom/DOMError.hpp> @@ -60,8 +59,7 @@ public: */ MemoryMonitor() { - fHashType = new SimpleHashPtr(); - fHashTable = new SimpleValueHashTableOf<unsigned int>(1013, fHashType); + fHashTable = new SimpleValueHashTableOf<unsigned int>(1013); } //@} @@ -74,7 +72,7 @@ public: */ virtual ~MemoryMonitor() { - delete fHashTable; + delete fHashTable; } //@} @@ -111,8 +109,5 @@ private: MemoryMonitor(const MemoryMonitor &); MemoryMonitor& operator=(const MemoryMonitor &); SimpleValueHashTableOf<unsigned int>* fHashTable; - SimpleHashPtr* fHashType; }; - - diff --git a/tests/src/MemHandlerTest/SimpleHashPtr.cpp b/tests/src/MemHandlerTest/SimpleHashPtr.cpp deleted file mode 100644 index 2efcf88c5..000000000 --- a/tests/src/MemHandlerTest/SimpleHashPtr.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SimpleHashPtr.hpp" -#include <xercesc/util/XercesDefs.hpp> - -// this is just a copy of HashPtr which is careful to rely on global new. - - -SimpleHashPtr::SimpleHashPtr() -{ -} - -SimpleHashPtr::~SimpleHashPtr() -{ -} - -XMLSize_t SimpleHashPtr::getHashVal(const void *const key, XMLSize_t mod) -{ - return ((XMLSize_t)key % mod); -} - -bool SimpleHashPtr::equals(const void *const key1, const void *const key2) -{ - return (key1 == key2); -} - diff --git a/tests/src/MemHandlerTest/SimpleHashPtr.hpp b/tests/src/MemHandlerTest/SimpleHashPtr.hpp deleted file mode 100644 index 1302d793d..000000000 --- a/tests/src/MemHandlerTest/SimpleHashPtr.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#if !defined(SIMPLEHASHPTR_HPP) -#define SIMPLEHASHPTR_HPP - -#include <xercesc/util/XercesDefs.hpp> - -/** - * this is just a copy of the HashPtr class that doesn't rely on the - * pluggable memory mechanism. - */ - -class SimpleHashPtr -{ -public: - SimpleHashPtr(); - virtual ~SimpleHashPtr(); - virtual XMLSize_t getHashVal(const void *const key, XMLSize_t mod); - virtual bool equals(const void *const key1, const void *const key2); - -}; - -#endif - diff --git a/tests/src/MemHandlerTest/SimpleValueHashTableOf.hpp b/tests/src/MemHandlerTest/SimpleValueHashTableOf.hpp index daa49d8e1..6291c6fdc 100644 --- a/tests/src/MemHandlerTest/SimpleValueHashTableOf.hpp +++ b/tests/src/MemHandlerTest/SimpleValueHashTableOf.hpp @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,57 +19,56 @@ * $Id$ */ - +// +// This is just a version of the ValueHashTableOf implementation from +// xercesc/util; we need a new one here because this cannot use the +// pluggable memory management facilities. +// #include <xercesc/util/XercesDefs.hpp> -#include "SimpleHashPtr.hpp" #include <xercesc/util/IllegalArgumentException.hpp> #include <xercesc/util/NoSuchElementException.hpp> #include <xercesc/util/NullPointerException.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/XMLExceptMsgs.hpp> #include <xercesc/util/XMLEnumerator.hpp> -#include <xercesc/util/XMLString.hpp> +#include <xercesc/util/Hashers.hpp> XERCES_CPP_NAMESPACE_USE +// Forward declare the enumerator so it can be our friend. // -// Forward declare the enumerator so he can be our friend. Can you say -// friend, neighbour? Of course you can... -// -template <class TVal> class ValueHashTableOfEnumerator; -template <class TVal> struct ValueHashTableBucketElem; +template <class TVal, class THasher = PtrHasher> +class ValueHashTableOfEnumerator; // // This should really be a nested class, but some of the compilers we // have to support cannot deal with that! // -template <class TVal> struct ValueHashTableBucketElem +template <class TVal> +struct ValueHashTableBucketElem { ValueHashTableBucketElem(void* key, const TVal& value, ValueHashTableBucketElem<TVal>* next) : fData(value), fNext(next), fKey(key) { } - TVal fData; + TVal fData; ValueHashTableBucketElem<TVal>* fNext; - void* fKey; + void* fKey; }; -template <class TVal> class SimpleValueHashTableOf +template <class TVal, class THasher = PtrHasher> +class SimpleValueHashTableOf { public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - // backwards compatability - default hasher is SimpleHasPtrh SimpleValueHashTableOf(const XMLSize_t modulus); - // if a hash function is passed in, it will be deleted when the hashtable is deleted. - // use a new instance of the hasher class for each hashtable, otherwise one hashtable - // may delete the hasher of a different hashtable if both use the same hasher. - SimpleValueHashTableOf(const XMLSize_t modulus, SimpleHashPtr* hashBase); + SimpleValueHashTableOf(const XMLSize_t modulus, const THasher& hasher); ~SimpleValueHashTableOf(); @@ -92,14 +91,14 @@ public: // ----------------------------------------------------------------------- // Putters // ----------------------------------------------------------------------- - void put(void* key, const TVal& valueToAdopt); + void put(void* key, const TVal& valueToAdopt); private : // ----------------------------------------------------------------------- // Declare our friends // ----------------------------------------------------------------------- - friend class ValueHashTableOfEnumerator<TVal>; + friend class ValueHashTableOfEnumerator<TVal, THasher>; private: @@ -109,7 +108,7 @@ private: ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal); const ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal) const; void removeBucketElem(const void* const key, XMLSize_t& hashVal); - void initialize(const XMLSize_t modulus); + void initialize(const XMLSize_t modulus); // ----------------------------------------------------------------------- @@ -128,7 +127,7 @@ private: // ----------------------------------------------------------------------- ValueHashTableBucketElem<TVal>** fBucketList; XMLSize_t fHashModulus; - SimpleHashPtr* fHash; + THasher fHasher; }; @@ -137,13 +136,14 @@ private: // An enumerator for a value array. It derives from the basic enumerator // class, so that value vectors can be generically enumerated. // -template <class TVal> class ValueHashTableOfEnumerator : public XMLEnumerator<TVal> +template <class TVal, class THasher> +class ValueHashTableOfEnumerator : public XMLEnumerator<TVal> { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - ValueHashTableOfEnumerator(SimpleValueHashTableOf<TVal>* const toEnum, const bool adopt = false); + ValueHashTableOfEnumerator(SimpleValueHashTableOf<TVal, THasher>* const toEnum, const bool adopt = false); virtual ~ValueHashTableOfEnumerator(); @@ -183,38 +183,30 @@ private : bool fAdopted; ValueHashTableBucketElem<TVal>* fCurElem; XMLSize_t fCurHash; - SimpleValueHashTableOf<TVal>* fToEnum; + SimpleValueHashTableOf<TVal, THasher>* fToEnum; }; -// This is just an old version of the ValueHashTableOf implementation -// from xercesc/util; we need a new one here because this -// cannot use the pluggable memory management facilities. - -// forward declarations - // --------------------------------------------------------------------------- // ValueHashTableOf: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> SimpleValueHashTableOf<TVal>::SimpleValueHashTableOf(const XMLSize_t modulus - , SimpleHashPtr* hashBase) - : fBucketList(0), fHashModulus(modulus) +template <class TVal, class THasher> +SimpleValueHashTableOf<TVal, THasher>::SimpleValueHashTableOf(const XMLSize_t modulus + , const THasher& hasher) + : fBucketList(0), fHashModulus(modulus), fHasher (hasher) { - initialize(modulus); - // set hasher - fHash = hashBase; + initialize(modulus); } -template <class TVal> SimpleValueHashTableOf<TVal>::SimpleValueHashTableOf(const XMLSize_t modulus) +template <class TVal, class THasher> +SimpleValueHashTableOf<TVal, THasher>::SimpleValueHashTableOf(const XMLSize_t modulus) : fBucketList(0), fHashModulus(modulus) { - initialize(modulus); - - // create default hasher - fHash = new HashXMLCh(); + initialize(modulus); } -template <class TVal> void SimpleValueHashTableOf<TVal>::initialize(const XMLSize_t modulus) +template <class TVal, class THasher> +void SimpleValueHashTableOf<TVal, THasher>::initialize(const XMLSize_t modulus) { if (modulus == 0) ThrowXML(IllegalArgumentException, XMLExcepts::HshTbl_ZeroModulus); @@ -225,20 +217,21 @@ template <class TVal> void SimpleValueHashTableOf<TVal>::initialize(const XMLSiz fBucketList[index] = 0; } -template <class TVal> SimpleValueHashTableOf<TVal>::~SimpleValueHashTableOf() +template <class TVal, class THasher> +SimpleValueHashTableOf<TVal, THasher>::~SimpleValueHashTableOf() { removeAll(); // Then delete the bucket list & hasher delete [] fBucketList; - delete fHash; } // --------------------------------------------------------------------------- // SimpleValueHashTableOf: Element management // --------------------------------------------------------------------------- -template <class TVal> bool SimpleValueHashTableOf<TVal>::isEmpty() const +template <class TVal, class THasher> +bool SimpleValueHashTableOf<TVal, THasher>::isEmpty() const { // Just check the bucket list for non-empty elements for (XMLSize_t buckInd = 0; buckInd < fHashModulus; buckInd++) @@ -249,7 +242,8 @@ template <class TVal> bool SimpleValueHashTableOf<TVal>::isEmpty() const return true; } -template <class TVal> bool SimpleValueHashTableOf<TVal>:: +template <class TVal, class THasher> +bool SimpleValueHashTableOf<TVal, THasher>:: containsKey(const void* const key) const { XMLSize_t hashVal; @@ -257,14 +251,16 @@ containsKey(const void* const key) const return (findIt != 0); } -template <class TVal> void SimpleValueHashTableOf<TVal>:: +template <class TVal, class THasher> +void SimpleValueHashTableOf<TVal, THasher>:: removeKey(const void* const key) { XMLSize_t hashVal; removeBucketElem(key, hashVal); } -template <class TVal> void SimpleValueHashTableOf<TVal>::removeAll() +template <class TVal, class THasher> +void SimpleValueHashTableOf<TVal, THasher>::removeAll() { // Clean up the buckets first for (XMLSize_t buckInd = 0; buckInd < fHashModulus; buckInd++) @@ -291,7 +287,8 @@ template <class TVal> void SimpleValueHashTableOf<TVal>::removeAll() // --------------------------------------------------------------------------- // SimpleValueHashTableOf: Getters // --------------------------------------------------------------------------- -template <class TVal> TVal& SimpleValueHashTableOf<TVal>::get(const void* const key) +template <class TVal, class THasher> +TVal& SimpleValueHashTableOf<TVal, THasher>::get(const void* const key) { XMLSize_t hashVal; ValueHashTableBucketElem<TVal>* findIt = findBucketElem(key, hashVal); @@ -301,7 +298,8 @@ template <class TVal> TVal& SimpleValueHashTableOf<TVal>::get(const void* const return findIt->fData; } -template <class TVal> const TVal& SimpleValueHashTableOf<TVal>:: +template <class TVal, class THasher> +const TVal& SimpleValueHashTableOf<TVal, THasher>:: get(const void* const key) const { XMLSize_t hashVal; @@ -316,7 +314,8 @@ get(const void* const key) const // --------------------------------------------------------------------------- // SimpleValueHashTableOf: Putters // --------------------------------------------------------------------------- -template <class TVal> void SimpleValueHashTableOf<TVal>::put(void* key, const TVal& valueToAdopt) +template <class TVal, class THasher> +void SimpleValueHashTableOf<TVal, THasher>::put(void* key, const TVal& valueToAdopt) { // First see if the key exists already XMLSize_t hashVal; @@ -343,11 +342,12 @@ template <class TVal> void SimpleValueHashTableOf<TVal>::put(void* key, const TV // --------------------------------------------------------------------------- // SimpleValueHashTableOf: Private methods // --------------------------------------------------------------------------- -template <class TVal> ValueHashTableBucketElem<TVal>* SimpleValueHashTableOf<TVal>:: +template <class TVal, class THasher> +ValueHashTableBucketElem<TVal>* SimpleValueHashTableOf<TVal, THasher>:: findBucketElem(const void* const key, XMLSize_t& hashVal) { // Hash the key - hashVal = fHash->getHashVal(key, fHashModulus); + hashVal = fHasher.getHashVal(key, fHashModulus); if (hashVal > fHashModulus) ThrowXML(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey); @@ -355,7 +355,7 @@ findBucketElem(const void* const key, XMLSize_t& hashVal) ValueHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if (fHash->equals(key, curElem->fKey)) + if (fHasher.equals(key, curElem->fKey)) return curElem; curElem = curElem->fNext; @@ -363,11 +363,12 @@ findBucketElem(const void* const key, XMLSize_t& hashVal) return 0; } -template <class TVal> const ValueHashTableBucketElem<TVal>* SimpleValueHashTableOf<TVal>:: +template <class TVal, class THasher> +const ValueHashTableBucketElem<TVal>* SimpleValueHashTableOf<TVal, THasher>:: findBucketElem(const void* const key, XMLSize_t& hashVal) const { // Hash the key - hashVal = fHash->getHashVal(key, fHashModulus); + hashVal = fHasher.getHashVal(key, fHashModulus); if (hashVal > fHashModulus) ThrowXML(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey); @@ -375,7 +376,7 @@ findBucketElem(const void* const key, XMLSize_t& hashVal) const const ValueHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; while (curElem) { - if (fHash->equals(key, curElem->fKey)) + if (fHasher.equals(key, curElem->fKey)) return curElem; curElem = curElem->fNext; @@ -384,11 +385,12 @@ findBucketElem(const void* const key, XMLSize_t& hashVal) const } -template <class TVal> void SimpleValueHashTableOf<TVal>:: +template <class TVal, class THasher> +void SimpleValueHashTableOf<TVal, THasher>:: removeBucketElem(const void* const key, XMLSize_t& hashVal) { // Hash the key - hashVal = fHash->getHashVal(key, fHashModulus); + hashVal = fHasher.getHashVal(key, fHashModulus); if (hashVal > fHashModulus) ThrowXML(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey); @@ -401,7 +403,7 @@ removeBucketElem(const void* const key, XMLSize_t& hashVal) while (curElem) { - if (fHash->equals(key, curElem->fKey)) + if (fHasher.equals(key, curElem->fKey)) { if (!lastElem) { @@ -430,13 +432,12 @@ removeBucketElem(const void* const key, XMLSize_t& hashVal) } - - // --------------------------------------------------------------------------- // ValueHashTableOfEnumerator: Constructors and Destructor // --------------------------------------------------------------------------- -template <class TVal> ValueHashTableOfEnumerator<TVal>:: -ValueHashTableOfEnumerator(SimpleValueHashTableOf<TVal>* const toEnum, const bool adopt) +template <class TVal, class THasher> +ValueHashTableOfEnumerator<TVal, THasher>:: +ValueHashTableOfEnumerator(SimpleValueHashTableOf<TVal, THasher>* const toEnum, const bool adopt) : fAdopted(adopt), fCurElem(0), fCurHash((XMLSize_t)-1), fToEnum(toEnum) { if (!toEnum) @@ -452,7 +453,8 @@ ValueHashTableOfEnumerator(SimpleValueHashTableOf<TVal>* const toEnum, const boo findNext(); } -template <class TVal> ValueHashTableOfEnumerator<TVal>::~ValueHashTableOfEnumerator() +template <class TVal, class THasher> +ValueHashTableOfEnumerator<TVal, THasher>::~ValueHashTableOfEnumerator() { if (fAdopted) delete fToEnum; @@ -462,7 +464,8 @@ template <class TVal> ValueHashTableOfEnumerator<TVal>::~ValueHashTableOfEnumera // --------------------------------------------------------------------------- // ValueHashTableOfEnumerator: Enum interface // --------------------------------------------------------------------------- -template <class TVal> bool ValueHashTableOfEnumerator<TVal>::hasMoreElements() const +template <class TVal, class THasher> +bool ValueHashTableOfEnumerator<TVal, THasher>::hasMoreElements() const { // // If our current has is at the max and there are no more elements @@ -473,7 +476,8 @@ template <class TVal> bool ValueHashTableOfEnumerator<TVal>::hasMoreElements() c return true; } -template <class TVal> TVal& ValueHashTableOfEnumerator<TVal>::nextElement() +template <class TVal, class THasher> +TVal& ValueHashTableOfEnumerator<TVal, THasher>::nextElement() { // Make sure we have an element to return if (!hasMoreElements()) @@ -490,7 +494,8 @@ template <class TVal> TVal& ValueHashTableOfEnumerator<TVal>::nextElement() } -template <class TVal> void ValueHashTableOfEnumerator<TVal>::Reset() +template <class TVal, class THasher> +void ValueHashTableOfEnumerator<TVal, THasher>::Reset() { fCurHash = (XMLSize_t)-1; fCurElem = 0; @@ -502,7 +507,8 @@ template <class TVal> void ValueHashTableOfEnumerator<TVal>::Reset() // --------------------------------------------------------------------------- // ValueHashTableOfEnumerator: Private helper methods // --------------------------------------------------------------------------- -template <class TVal> void ValueHashTableOfEnumerator<TVal>::findNext() +template <class TVal, class THasher> +void ValueHashTableOfEnumerator<TVal, THasher>::findNext() { // // If there is a current element, move to its next element. If this @@ -536,4 +542,3 @@ template <class TVal> void ValueHashTableOfEnumerator<TVal>::findNext() fCurElem = fToEnum->fBucketList[fCurHash]; } } - -- GitLab