From 51d368c20e1d93970a94cb0d2aff10654922bb37 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 6 Jul 2020 19:47:22 -0400 Subject: Add insert function for maps --- collections/map/map.adoc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'collections/map/map.adoc') diff --git a/collections/map/map.adoc b/collections/map/map.adoc index 4668e0e..2b3e2cb 100644 --- a/collections/map/map.adoc +++ b/collections/map/map.adoc @@ -1,7 +1,7 @@ Map === Tucker Evans -v0.2, 2020-07-06 +v0.3, 2020-07-06 A basic map implemented in an AVL tree. @@ -70,6 +70,28 @@ map_insert(dict, "ONE", NULL); assert(map_size(dict) == 1); ---- +[[map_insert]] ++int map_insert(map *self, void *key, void *value)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Inserts item +value+ for +key+ into +self+ +This returns an int indicating a successful insertion; currently the only +two potential errors are caused by a NULL map or an equivalent key with a +different pointer, this is in order to prevent a memory leak. +<> can be used to fix this issue. + +Examples +^^^^^^^^ +[source,c] +---- +#include "map.h" +#include + +map *dict = map_new((cmp_func) strcmp); + +map_insert(dict, "ONE", NULL); +assert(map_size(dict) == 1); +---- + [[map_clear]] +void map_clear(map *self)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.1