The function checks whether dict contains key. If it isn't so then the function checks the datatype of the value associated with the key. An error 42000 is signalled in case of non-integer value or a negative integer value. If the value is positive then value_decrement is added to it and the result become the new value associated with key in dict. If key is not in the dictionary then a new item is added to the dict in order to associate the key with value_increment.
The function returns zero (for NULL dict) or the changed (or the added) value associated with the key.
The function is convenient to deal with multisets, i.e., sets with repeating elements. In this case the dictionary contains distinct items as keys and counts of duplicates as associated values. dict_inc_or_add is to add a member, dict_dec_or_remove is to remove. The following example gets an array of multisets and return the sum of them.
create function DB.DBA.SUM_MULTISETS (inout msets any) returns any { declare sum_of_msets any; sum_of_msets := dict_new (17); foreach (any mset in msets) do { declare iter any; declare memb any; declare dup_count integer; iter := mset; --- unlike dict_duplicate() this does not make copy of mset so it's fast. dict_iter_rewind (iter); while (dict_iter_next (iter, memb, dup_count)) dict_inc_or_put (sum_of_msets, memb, dup_count); } return sum_of_msets; };