Skip to content

MapInsertL

Description

Insert a new (key, value) pair into the map. If a multi-valued map is supported, this adds another entry for an existing key rather than replacing. L-value form: takes ownership of both in_key and in_value on success when the corresponding copy_init handler is not configured (the sources are zeroed).

Parameters

Name Direction Description
m in,out Map handle.
in_key in Addressable key. Must match the map’s key type.
in_value in Addressable value. Must match the map’s value type.

Success

Returns true. A new (key, value) entry is stored in the map; length grows by one. When the map’s key_copy_init is absent the in_key source has been zeroed; same for value_copy_init and in_value. With a deep-copy handler, the corresponding source is unchanged. A rehash may have grown the underlying probe table.

Failure

Returns false on allocation failure (entry table grow or deep-copy callback) or policy violation. The map and both sources are unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
        int              value = 84;
    
        MapInsertL(&map, key, value);
    
        bool result = (key == 0) && (value == 0);
        int         value_count = 0;
    
        MapInsertL(&map, key, value);
        MapInsertL(&map, key, second_value);
    
        MapInsertL(&map, key, value);
        MapInsertL(&map, key, second_value);
    
        bool result         = (key == key_buf) && (value == value_buf) && (second_value == second_value_buf);
    /// TAGS: Map, Insert, API
    ///
    #define MapInsert(m, in_key, in_value) MapInsertL((m), (in_key), (in_value))
    
    ///
    #define MapMustInsertL(m, in_key, in_value)                                                                            \
        do {                                                                                                               \
            if (!MapInsertL((m), (in_key), (in_value))) {                                                                  \
                LOG_FATAL("MapMustInsertL failed");                                                                        \
            }                                                                                                              \
Last updated on