--- parser3/src/include/pa_hash.h 2009/08/08 13:30:21 1.79 +++ parser3/src/include/pa_hash.h 2010/08/04 15:08:44 1.82 @@ -17,7 +17,7 @@ #ifndef PA_HASH_H #define PA_HASH_H -static const char * const IDENT_HASH_H="$Date: 2009/08/08 13:30:21 $"; +static const char * const IDENT_HASH_H="$Date: 2010/08/04 15:08:44 $"; #include "pa_memory.h" #include "pa_types.h" @@ -136,21 +136,24 @@ public: fused_refs=source.fused_refs; fpairs_count=source.fpairs_count; refs=new(UseGC) Pair*[allocated]; + // clone & rehash #ifdef HASH_ORDER first=0; last=&first; -#endif - // clone & rehash - Pair **old_ref=source.refs; - for(int index=0; indexlink; - - Pair **ref=&refs[index]; + for(Pair *pair=source.first; pair; pair=pair->next) + { + uint index=pair->code%allocated; + Pair **ref=&refs[index]; + HASH_NEW_PAIR(pair->code, pair->key, pair->value); + } +#else + for(int i=0; ilink) + { + Pair **ref=&refs[i]; HASH_NEW_PAIR(pair->code, pair->key, pair->value); - - pair=next; } +#endif } #ifdef USE_DESTRUCTORS @@ -242,6 +245,16 @@ public: return V(0); } +#ifdef HASH_ORDER + V first_value() const { + return (first) ? first->value : V(0); + } + + V last_value() const { + return (fpairs_count) ? ((Pair *)((char *)last - offsetof(Pair, next)))->value : V(0); + } +#endif + /// put a [value] under the [key] if that [key] existed @returns existed or not bool put_replaced(K key, V value) { if(!value) { @@ -586,6 +599,32 @@ public: return pair->value; return V(0); } + + /// simple hash iterator + class Iterator { + const HASH_STRING& fhash; + Pair *fcurrent; + public: + Iterator(const HASH_STRING& ahash): fhash(ahash) { + fcurrent=fhash.first; + } + + operator bool () { + return fcurrent != 0; + } + + void next() { + fcurrent=fcurrent->next; + } + + String::Body key(){ + return String::Body(fcurrent->key, fcurrent->code); + } + + V value(){ + return fcurrent->value; + } + }; }; #else //HASH_CODE_CACHING