chsvlib
chsv helper source code

◆ MapInsert()

EXTERN_C bool Chusov::MapInsert ( HCHSVMAP  hMap,
const void *  pKey,
std::size_t  cbKey,
const void *  pValue,
std::size_t  cbValue 
)
noexcept

Inserts a new element by value to the specified map. The data in the parameter is copied into the internal buffers bound to elements.

Parameters
[in]hMapis a handle to a map or a multimap instance.
[in]pKeyis a pointer to memory containing key data. If hMap is an instance of a map, and not multimap, the key value must be unique among the map elements or the function will fail with the CHSVERROR_ALREADY_EXISTS code. The key is copied into the element internal buffers, therefore the memory is not owned by the map.
[in]cbKeyis a length of the key data pointed by the pKey parameter, in bytes.
[in]pValueis a pointer to a value of the new element to be created in the map. The value is copied into the element internal buffers, therefore the memory is not owned by the map. As opposed to the MapInsertByPtr the pointer is mandatory and should not be NULL. To store a NULL pointer use the MapInsertByPtr function.
[in]cbValueis a byte size of the memory pointed by the pValue.
Returns
The function returns true on successful insertion and false on failure. Use GetLastChsvError function to get the extended error information.
Remarks
The key and value data in the parameters list are copied into internal buffers of the element.
The complexity is \(O(\log n)=O_{find}(\log n)+O_{create}(1)\).
Declared in chsvmap.h.
See also
MapInsertByPtr;
MapErase.