--- parser3/src/include/pa_hash.h 2003/03/18 11:54:55 1.58.2.18 +++ parser3/src/include/pa_hash.h 2003/03/24 15:26:02 1.58.2.18.2.6 @@ -17,9 +17,9 @@ #ifndef PA_HASH_H #define PA_HASH_H -static const char* IDENT_HASH_H="$Date: 2003/03/18 11:54:55 $"; +static const char* IDENT_HASH_H="$Date: 2003/03/24 15:26:02 $"; -#include "pa_pool.h" +#include "pa_memory.h" #include "pa_types.h" /** @@ -63,10 +63,6 @@ public: pair=next; } } - ~Hash() { - destroy_pairs(); - delete refs; - } /// put a [value] under the [key] @returns existed or not bool put(K key, V value) { @@ -201,7 +197,7 @@ public: /// remove all elements void clear() { - destroy_pairs(); memset(refs, 0, sizeof(*refs)*allocated); + memset(refs, 0, sizeof(*refs)*allocated); fpairs_count=fused_refs=0; } @@ -259,7 +255,7 @@ private: // allocated bigger refs array allocated=allocates[allocates_index]; threshold=allocated*THRESHOLD_PERCENT/100; - refs=new(0) Pair*[allocated]; + refs=new(UseGC) Pair*[allocated]; // rehash Pair **old_ref=old_refs; @@ -275,19 +271,7 @@ private: pair=next; } - delete old_refs; - } - - void destroy_pairs() { - Pair **ref=refs; - for(int index=0; indexlink; - delete pair; - pair=next; - } - } + delete[] old_refs; } private: //disabled @@ -307,23 +291,41 @@ template int Hash::allocates_count=sizeof(allocates)/sizeof(uint); /// useful generic hash function -inline uint generic_hash_code(uint aresult, const char* start, size_t allocated) { - uint result=aresult, g; - const char* end=start+allocated; - - while (start>24); + result=result^g; + } +} +/// useful generic hash function +inline void generic_hash_code(uint& result, const char* s) { + while(char c=*s++) { + result=(result<<4)+c; + if(uint g=(result&0xF0000000)) { + result=result^(g>>24); + result=result^g; + } + } +} + +/// useful generic hash function +inline void generic_hash_code(uint& result, const char* buf, size_t size) { + const char* end=buf+size; + while(buf>24); result=result^g; } } - return result; } /// simple hash code of int. used by EXIF mapping inline uint hash_code(int self) { - return generic_hash_code(0, (const char*)&self, sizeof(self)); + uint result=0; + generic_hash_code(result, (const char*)&self, sizeof(self)); + return result; } /// Auto-object used to temporarily substituting/removing hash values