C Collections

chashmap · Section 3

chmap_remove

chmap_remove - remove a key-value pair (type-inferred)

C Collections (libccollections, -lccollections)

#include <ccollections/chashmap.h>
 
ccol_retval chmap_remove(hm_name, key);

Type-inferred wrapper for chashmap_remove_elem() that returns the result
code, so a key_not_found does not stop the program.
 
The lookup key is converted through the DECLARED key type of the map,
the same way chmap_insert(3) converts it, so a key stored through that
conversion is only found again by a lookup that makes the same
conversion. A literal and a computed expression both work.

hm_name  Hash map to remove from
key      Key to remove

ccol_success when the key was removed
ccol_key_not_found when the map does not hold the key
ccol_invalid_args when key is a NULL character pointer, since that is
not a string

Does not stop the program for key_not_found
Frees the memory of the key and of the value

int key = 42;
ccol_retval r = chmap_remove(map, key);
if (r == ccol_key_not_found) {
  printf("Key not found\n");
}

chashmap_remove_elem(3), chmap_insert(3)