| Новости | FAQ | Авторы | Документация | В действии | Библиотека |
| Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
Александр Петросян (PAF) 28.07.2005 14:00
если не сложно вам:/// put a [value] under the [key] @returns existed or not
template<typename R, typename F1, typename F2, typename I>
R maybe_replace_maybe_append(K key, V value, F1 prevent_replace, F2 prevent_append, I info)
{
if(!value) {
// they can come here from Temp_value_element::dctor to restore some empty value
remove(key);
// this has nothing to do with properties, doing no special property handling here
return 0;
}
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<R>(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;
}какая-то мелочь не работает и потом всё грустит в хитрой ситуации.