from operator import add


def update_records_log_dict_classification(k_id_class, l_values, p_ip_prefix, d_prefixes_matchs):
    """
    Update log record entries for a given key, aggregating values when the key already exist.
    """

    if (k_id_class not in d_prefixes_matchs) and (p_ip_prefix is not None):
        d_prefixes_matchs[k_id_class] = l_values
    elif p_ip_prefix is not None:
        d_prefixes_matchs[k_id_class] = map(add, d_prefixes_matchs[k_id_class], l_values)

    return d_prefixes_matchs