Browse Source

fix hashmap

Kolja Strohm 2 years ago
parent
commit
79e00dcf90
2 changed files with 16 additions and 14 deletions
  1. 13 12
      HashMap.h
  2. 3 2
      main.h

+ 13 - 12
HashMap.h

@@ -69,7 +69,7 @@ namespace Framework
             int index = abs( hash( key ) ) % bucketCount;
             if( !buckets[ index ] )
                 buckets[ index ] = new Array< MapEntry<K, V>>();
-            for( auto iterator = buckets[ index ]->getIterator(); iterator; iterator++ )
+            for( auto iterator = buckets[ index ]->begin(); iterator; iterator++ )
             {
                 if( iterator._.getKey() == key )
                 {
@@ -86,13 +86,14 @@ namespace Framework
             if( !buckets[ index ] )
                 return;
             int listIndex = 0;
-            for( auto iterator = buckets[ index ]->getIterator(); iterator; iterator++, listIndex++ )
+            for( auto bucket : *buckets[ index ] )
             {
-                if( iterator._.getKey() == key )
+                if( bucket.getKey() == key )
                 {
-                    buckets[ index ]->remove( listIndex );
+                    bucket.remove( listIndex );
                     return;
                 }
+                listIndex++;
             }
         }
 
@@ -101,10 +102,10 @@ namespace Framework
             int index = abs( hash( key ) ) % bucketCount;
             if( !buckets[ index ] )
                 throw "element not found";
-            for( auto iterator = buckets[ index ]->getIterator(); iterator; iterator++ )
+            for( auto iterator : *buckets[ index ] )
             {
-                if( iterator._.getKey() == key )
-                    return iterator._.getValue();
+                if( iterator.getKey() == key )
+                    return iterator.getValue();
             }
             throw "element not found";
         }
@@ -114,10 +115,10 @@ namespace Framework
             int index = abs( hash( key ) ) % bucketCount;
             if( !buckets[ index ] )
                 return fallback;
-            for( auto iterator = buckets[ index ]->getIterator(); iterator; iterator++ )
+            for( auto bucket : *buckets[ index ] )
             {
-                if( iterator._.getKey() == key )
-                    return iterator._.getValue();
+                if( bucket.getKey() == key )
+                    return bucket.getValue();
             }
             return fallback;
         }
@@ -127,9 +128,9 @@ namespace Framework
             int index = abs( hash( key ) ) % bucketCount;
             if( !buckets[ index ] )
                 return 0;
-            for( auto iterator = buckets[ index ]->getIterator(); iterator; iterator++ )
+            for( auto bucket : buckets[ index ] )
             {
-                if( iterator._.getKey() == key )
+                if( bucket.getKey() == key )
                     return 1;
             }
             return 0;

+ 3 - 2
main.h

@@ -44,7 +44,7 @@ typedef BOOL( __stdcall *MINIDUMPWRITEDUMP )( HANDLE hProcess, DWORD dwPid, HAND
 void createMinidump( struct _EXCEPTION_POINTERS *apExceptionInfo )
 {
     HMODULE mhLib = ::LoadLibrary( "dbghelp.dll" );
-    MINIDUMPWRITEDUMP pDump = ( MINIDUMPWRITEDUMP )::GetProcAddress( mhLib, "MiniDumpWriteDump" );
+    MINIDUMPWRITEDUMP pDump = mhLib ? ( MINIDUMPWRITEDUMP )::GetProcAddress( mhLib, "MiniDumpWriteDump" ) : 0;
 
     HANDLE  hFile = ::CreateFile( "error_core_memory_dump.dmp", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
                                   FILE_ATTRIBUTE_NORMAL, NULL );
@@ -54,7 +54,8 @@ void createMinidump( struct _EXCEPTION_POINTERS *apExceptionInfo )
     ExInfo.ExceptionPointers = apExceptionInfo;
     ExInfo.ClientPointers = FALSE;
 
-    pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
+    if( pDump )
+        pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
     ::CloseHandle( hFile );
 }