aboutsummaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.h')
-rw-r--r--src/hash.h38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/hash.h b/src/hash.h
index b5bf8d6..71abff5 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -5,10 +5,18 @@
5#include <string.h> 5#include <string.h>
6#include <memory> 6#include <memory>
7#include <iostream> 7#include <iostream>
8#include "exceptionbase.h"
8#include "hashable.h" 9#include "hashable.h"
9 10
10#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) 11#define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0))
11 12
13subExceptionDecl( HashException )
14
15enum eHashException
16{
17 excodeNotFilled
18};
19
12template<typename T> 20template<typename T>
13uint32_t __calcHashCode( T k ); 21uint32_t __calcHashCode( T k );
14 22
@@ -59,14 +67,20 @@ public:
59 operator _value() 67 operator _value()
60 { 68 {
61 if( bFilled == false ) 69 if( bFilled == false )
62 throw "Nope, no data there"; 70 throw HashException(
71 excodeNotFilled,
72 "No data assosiated with that key."
73 );
63 return *pValue; 74 return *pValue;
64 } 75 }
65 76
66 _value value() 77 _value value()
67 { 78 {
68 if( bFilled == false ) 79 if( bFilled == false )
69 throw "Nope, no data there"; 80 throw HashException(
81 excodeNotFilled,
82 "No data assosiated with that key."
83 );
70 return *pValue; 84 return *pValue;
71 } 85 }
72 86
@@ -199,6 +213,21 @@ public:
199 } 213 }
200 } 214 }
201 215
216 void clear()
217 {
218 for( uint32_t j = 0; j < nCapacity; j++ )
219 {
220 if( isFilled( j ) )
221 if( !isDeleted( j ) )
222 {
223 va.destroy( &aValues[j] );
224 ka.destroy( &aKeys[j] );
225 }
226 }
227
228 clearBits();
229 }
230
202 value get( key k ) 231 value get( key k )
203 { 232 {
204 uint32_t hash = __calcHashCode( k ); 233 uint32_t hash = __calcHashCode( k );
@@ -211,7 +240,10 @@ public:
211 } 240 }
212 else 241 else
213 { 242 {
214 throw "Hey, no such thing..."; 243 throw HashException(
244 excodeNotFilled,
245 "No data assosiated with that key."
246 );
215 } 247 }
216 } 248 }
217 249