diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2020-07-24 15:56:43 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2020-07-24 15:56:43 -0400 |
commit | de41cfb61d4cbafdc3ffe8a2651630a53b3c8d11 (patch) | |
tree | 468869fa0550c2ce65ce1b1c02e66b7fd2701ec0 /collections/map/map.adoc | |
parent | bc540d32e8d2ff16ffe688b02f18d565651e4b10 (diff) |
Add first/last getters for maps.maps
Diffstat (limited to 'collections/map/map.adoc')
-rw-r--r-- | collections/map/map.adoc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/collections/map/map.adoc b/collections/map/map.adoc index 740df3c..690aa3d 100644 --- a/collections/map/map.adoc +++ b/collections/map/map.adoc @@ -119,6 +119,55 @@ assert(strcmp(tmp, "FOUR") == 0); free(tmp); ---- +[[map_first]] ++void* map_first(map *self)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Returns the value associated with the smallest key from +self+. + +Examples +^^^^^^^^ +[source,c] +---- +#include "map.h" +#include <string.h> + +char *str1 = "A"; +char *str2 = "Z"; + +map *dict = map_new((cmp_func) strcmp); + +map_insert(dict, str1, str1); +map_insert(dict, str2, str2); + + +assert(strcmp(str1, map_first(dict) == 0); +---- + +[[map_last]] ++void* map_last(map *self)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Returns the value associated with the largest key from +self+. + +Examples +^^^^^^^^ +[source,c] +---- +#include "map.h" +#include <string.h> + +char *str1 = "A"; +char *str2 = "Z"; + +map *dict = map_new((cmp_func) strcmp); + +map_insert(dict, str1, str1); +map_insert(dict, str2, str2); + + +assert(strcmp(str2, map_last(dict) == 0); +---- + + [[map_swap]] +void map_swap(map *self, void *i, void *j)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |