--- parser3/src/include/pa_hash.h 2005/07/27 06:15:34 1.64 +++ parser3/src/include/pa_hash.h 2005/07/27 10:39:40 1.64.2.2 @@ -17,7 +17,7 @@ #ifndef PA_HASH_H #define PA_HASH_H -static const char * const IDENT_HASH_H="$Date: 2005/07/27 06:15:34 $"; +static const char * const IDENT_HASH_H="$Date: 2005/07/27 10:39:40 $"; #include "pa_memory.h" #include "pa_types.h" @@ -133,6 +133,73 @@ public: return 0; } + /// put a [value] under the [key] @returns existed or not + template R maybe_append(K key, V value, F prevent, I info) { + assert(value); + + if(is_full()) + expand(); + + uint code=hash_code(key); + uint index=code%allocated; + Pair **ref=&refs[index]; + for(Pair *pair=*ref; pair; pair=pair->link) + if(pair->code==code && pair->key==key) { + // found a pair with the same key + pair->value=value; + return reinterpret_cast(1); + } + + // proper pair not found + // prevent-function intercepted put? + if(R result=prevent(value, info)) + return result; + + //create&link_in new pair + if(!*ref) // root cell were fused_refs? + fused_refs++; // not, we'll use it and record the fact + *ref=new Pair(code, key, value, *ref); + fpairs_count++; + return 0; + } + + /// put a [value] under the [key] @returns existed or not + template + R maybe_maybe_append(K key, V value, F1 prevent_replace, F2 prevent_append, I info) + { + assert(value); + + if(is_full()) + expand(); + + uint code=hash_code(key); + uint index=code%allocated; + Pair **ref=&refs[index]; + for(Pair *pair=*ref; pair; pair=pair->link) + if(pair->code==code && pair->key==key) { + // found a pair with the same key + + // prevent-function intercepted put? + if(R result=prevent_replace(pair->value, info)) + return result; + + pair->value=value; + return reinterpret_cast(1); + } + + // proper pair not found + // prevent-function intercepted put? + if(R result=prevent_append(value, info)) + return result; + + //create&link_in new pair + if(!*ref) // root cell were fused_refs? + fused_refs++; // not, we'll use it and record the fact + *ref=new Pair(code, key, value, *ref); + fpairs_count++; + return 0; + } + /// remove the [key] @returns existed or not bool remove(K key) { uint code=hash_code(key); @@ -189,7 +256,6 @@ public: for(Pair *pair=refs[index]; pair; pair=pair->link) if(pair->code==code && pair->key==key) { // found a pair with the same key, replacing - // prevent-function intercepted put? if(R result=prevent(pair->value)) return result;