diff options
Diffstat (limited to 'collections/map/map.adoc')
-rw-r--r-- | collections/map/map.adoc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/collections/map/map.adoc b/collections/map/map.adoc index c42a99a..740df3c 100644 --- a/collections/map/map.adoc +++ b/collections/map/map.adoc @@ -119,6 +119,32 @@ assert(strcmp(tmp, "FOUR") == 0); free(tmp); ---- +[[map_swap]] ++void map_swap(map *self, void *i, void *j)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Swaps values at keys +i+ and +j+, does nothing if +i+ or +j+ are invalid keys. + +Examples +^^^^^^^^ +[source,c] +---- +#include "map.h" +#include <string.h> + +char *str1 = "ONE"; +char *str2 = "TWO"; + +map *dict = map_new((cmp_func) strcmp); + +map_insert(dict, str1, strdup(str2)); +map_insert(dict, str2, strdup(str3)); + +map_swap(dict, str1, str2); + +assert(strcmp(str1, map_index(dict, str1)) == 0); +assert(strcmp(str2, map_index(dict, str2)) == 0); +---- + [[map_set_val]] +void* map_set_val(map *self, void *key, void *val)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |