diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/hashfunctionstring.cpp | 17 | ||||
| -rw-r--r-- | src/hashtable.cpp | 72 | ||||
| -rw-r--r-- | src/md5.cpp | 2 |
3 files changed, 58 insertions, 33 deletions
diff --git a/src/hashfunctionstring.cpp b/src/hashfunctionstring.cpp index 6ce7bb3..bd14643 100644 --- a/src/hashfunctionstring.cpp +++ b/src/hashfunctionstring.cpp | |||
| @@ -1,4 +1,7 @@ | |||
| 1 | #include "hashfunctionstring.h" | 1 | #include "hashfunctionstring.h" |
| 2 | #ifndef NULL | ||
| 3 | #define NULL ((void *) 0) | ||
| 4 | #endif | ||
| 2 | 5 | ||
| 3 | HashFunctionString::HashFunctionString() | 6 | HashFunctionString::HashFunctionString() |
| 4 | { | 7 | { |
| @@ -10,6 +13,11 @@ HashFunctionString::~HashFunctionString() | |||
| 10 | 13 | ||
| 11 | unsigned long int HashFunctionString::hash( const void *id ) | 14 | unsigned long int HashFunctionString::hash( const void *id ) |
| 12 | { | 15 | { |
| 16 | if (id == NULL) | ||
| 17 | { | ||
| 18 | return 0; | ||
| 19 | } | ||
| 20 | |||
| 13 | unsigned long int nPos = 0; | 21 | unsigned long int nPos = 0; |
| 14 | for( const char *s = (const char *)id; *s; s++ ) | 22 | for( const char *s = (const char *)id; *s; s++ ) |
| 15 | { | 23 | { |
| @@ -20,6 +28,15 @@ unsigned long int HashFunctionString::hash( const void *id ) | |||
| 20 | 28 | ||
| 21 | bool HashFunctionString::cmpIDs( const void *id1, const void *id2 ) | 29 | bool HashFunctionString::cmpIDs( const void *id1, const void *id2 ) |
| 22 | { | 30 | { |
| 31 | if (id1 == NULL || id2 == NULL) | ||
| 32 | { | ||
| 33 | return false; | ||
| 34 | } | ||
| 35 | if (id1 == id2) | ||
| 36 | { | ||
| 37 | return true; | ||
| 38 | } | ||
| 39 | |||
| 23 | const char *str1 = (const char *)id1; | 40 | const char *str1 = (const char *)id1; |
| 24 | const char *str2 = (const char *)id2; | 41 | const char *str2 = (const char *)id2; |
| 25 | 42 | ||
diff --git a/src/hashtable.cpp b/src/hashtable.cpp index ea13236..37c3149 100644 --- a/src/hashtable.cpp +++ b/src/hashtable.cpp | |||
| @@ -203,16 +203,18 @@ const void *HashTable::get( const void *id, unsigned long int nSkip ) | |||
| 203 | for( unsigned long int j=0; j < 32; nPos = (nPos+(1<<j))%nTableSize, j++ ) | 203 | for( unsigned long int j=0; j < 32; nPos = (nPos+(1<<j))%nTableSize, j++ ) |
| 204 | { | 204 | { |
| 205 | if( !isFilled( nPos ) ) return NULL; | 205 | if( !isFilled( nPos ) ) return NULL; |
| 206 | if( hFunc->cmpIDs( id, aTable[nPos].id ) && | 206 | if( aTable[nPos].bDeleted == false ) |
| 207 | aTable[nPos].bDeleted == false ) | ||
| 208 | { | 207 | { |
| 209 | if( nSkip == 0 ) | 208 | if( hFunc->cmpIDs( id, aTable[nPos].id ) ) |
| 210 | { | ||
| 211 | return aTable[nPos].data; | ||
| 212 | } | ||
| 213 | else | ||
| 214 | { | 209 | { |
| 215 | nSkip--; | 210 | if( nSkip == 0 ) |
| 211 | { | ||
| 212 | return aTable[nPos].data; | ||
| 213 | } | ||
| 214 | else | ||
| 215 | { | ||
| 216 | nSkip--; | ||
| 217 | } | ||
| 216 | } | 218 | } |
| 217 | } | 219 | } |
| 218 | } | 220 | } |
| @@ -223,16 +225,18 @@ const void *HashTable::get( const void *id, unsigned long int nSkip ) | |||
| 223 | for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize ) | 225 | for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize ) |
| 224 | { | 226 | { |
| 225 | if( !isFilled( nPos ) ) return NULL; | 227 | if( !isFilled( nPos ) ) return NULL; |
| 226 | if( hFunc->cmpIDs( id, aTable[nPos].id ) && | 228 | if( aTable[nPos].bDeleted == false ) |
| 227 | aTable[nPos].bDeleted == false ) | ||
| 228 | { | 229 | { |
| 229 | if( nSkip == 0 ) | 230 | if( hFunc->cmpIDs( id, aTable[nPos].id ) ) |
| 230 | { | 231 | { |
| 231 | return aTable[nPos].data; | 232 | if( nSkip == 0 ) |
| 232 | } | 233 | { |
| 233 | else | 234 | return aTable[nPos].data; |
| 234 | { | 235 | } |
| 235 | nSkip--; | 236 | else |
| 237 | { | ||
| 238 | nSkip--; | ||
| 239 | } | ||
| 236 | } | 240 | } |
| 237 | } | 241 | } |
| 238 | } | 242 | } |
| @@ -248,16 +252,18 @@ const void *HashTable::getKey( const void *id, unsigned long int nSkip ) | |||
| 248 | for( unsigned long int j=0; j < 32; nPos = (nPos+(1<<j))%nTableSize, j++ ) | 252 | for( unsigned long int j=0; j < 32; nPos = (nPos+(1<<j))%nTableSize, j++ ) |
| 249 | { | 253 | { |
| 250 | if( !isFilled( nPos ) ) return NULL; | 254 | if( !isFilled( nPos ) ) return NULL; |
| 251 | if( hFunc->cmpIDs( id, aTable[nPos].id ) && | 255 | if( aTable[nPos].bDeleted == false ) |
| 252 | aTable[nPos].bDeleted == false ) | ||
| 253 | { | 256 | { |
| 254 | if( nSkip == 0 ) | 257 | if( hFunc->cmpIDs( id, aTable[nPos].id ) ) |
| 255 | { | ||
| 256 | return aTable[nPos].id; | ||
| 257 | } | ||
| 258 | else | ||
| 259 | { | 258 | { |
| 260 | nSkip--; | 259 | if( nSkip == 0 ) |
| 260 | { | ||
| 261 | return aTable[nPos].id; | ||
| 262 | } | ||
| 263 | else | ||
| 264 | { | ||
| 265 | nSkip--; | ||
| 266 | } | ||
| 261 | } | 267 | } |
| 262 | } | 268 | } |
| 263 | } | 269 | } |
| @@ -268,16 +274,18 @@ const void *HashTable::getKey( const void *id, unsigned long int nSkip ) | |||
| 268 | for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize ) | 274 | for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize ) |
| 269 | { | 275 | { |
| 270 | if( !isFilled( nPos ) ) return NULL; | 276 | if( !isFilled( nPos ) ) return NULL; |
| 271 | if( hFunc->cmpIDs( id, aTable[nPos].id ) && | 277 | if( aTable[nPos].bDeleted == false ) |
| 272 | aTable[nPos].bDeleted == false ) | ||
| 273 | { | 278 | { |
| 274 | if( nSkip == 0 ) | 279 | if( hFunc->cmpIDs( id, aTable[nPos].id ) ) |
| 275 | { | 280 | { |
| 276 | return aTable[nPos].id; | 281 | if( nSkip == 0 ) |
| 277 | } | 282 | { |
| 278 | else | 283 | return aTable[nPos].id; |
| 279 | { | 284 | } |
| 280 | nSkip--; | 285 | else |
| 286 | { | ||
| 287 | nSkip--; | ||
| 288 | } | ||
| 281 | } | 289 | } |
| 282 | } | 290 | } |
| 283 | } | 291 | } |
diff --git a/src/md5.cpp b/src/md5.cpp index ed7e4ac..c0cacdd 100644 --- a/src/md5.cpp +++ b/src/md5.cpp | |||
| @@ -143,7 +143,7 @@ long *md5::c2l( const char *str, long len, long *nNewLen ) | |||
| 143 | long mlen = OBLOC( len8 ); | 143 | long mlen = OBLOC( len8 ); |
| 144 | long flen = (((mlen/16)+((mlen%16)?(1):(0))))*16; | 144 | long flen = (((mlen/16)+((mlen%16)?(1):(0))))*16; |
| 145 | long *aBin = new long[flen]; | 145 | long *aBin = new long[flen]; |
| 146 | memset( aBin, 0, flen ); | 146 | memset( aBin, 0, flen*4 ); |
| 147 | 147 | ||
| 148 | for( long i = 0; i < len8; i+=8 ) | 148 | for( long i = 0; i < len8; i+=8 ) |
| 149 | { | 149 | { |
