Name

dict_dec_or_remove — Decrement a counter in a dictionary of counters or deletes it if it becomes zero or negative.

Synopsis

dict_dec_or_remove ( inout dict dictionary ,
in key any ,
in value_decrement integer );

Description

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 and greater than value_decrement then value_decrement is subtracted from it and the result become the new value associated with key in dict . If the value is positive and less than or equal to value_decrement then key is removed from dict . If key is not in the dictionary then the dictionary remains unchanged.

Informally, the function reverts the effect of dict_inc_or_add .

Parameters

dict

Dictionary of counters. The NULL value is equivalent to an empty dictionary.

key

Key of a dictionary item to process.

value decrement

A nonnegative integer (typically 1) that is subtracted from the value associated with key .

Return Types

The function returns the changed value associated with the key , or zero in any other case.