aboutsummaryrefslogtreecommitdiff
path: root/collections/map/map.adoc
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2020-07-24 15:38:15 -0400
committerTucker Evans <tuckerevans24@gmail.com>2020-07-24 15:56:31 -0400
commitbc540d32e8d2ff16ffe688b02f18d565651e4b10 (patch)
treeaefaefaeb7451086eacfde86d5d523798bd1964e /collections/map/map.adoc
parent1cd08117d9506d72bf4bf87a12ad4720d0892407 (diff)
Add swap function for maps
Diffstat (limited to 'collections/map/map.adoc')
-rw-r--r--collections/map/map.adoc26
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)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~