diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-06 19:47:22 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-08 11:02:40 -0400 |
commit | 51d368c20e1d93970a94cb0d2aff10654922bb37 (patch) | |
tree | 2903118e96ca69a499e91e63c5ee6c217b47e44d /collections/map/map.adoc | |
parent | 0cca188d0ccbfe3d87805c74b63fef72a58a2b84 (diff) |
Add insert function for maps
Diffstat (limited to 'collections/map/map.adoc')
-rw-r--r-- | collections/map/map.adoc | 24 |
1 files changed, 23 insertions, 1 deletions
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. +<<reset_key,+map_reset_key()+>> can be used to fix this issue. + +Examples +^^^^^^^^ +[source,c] +---- +#include "map.h" +#include <string.h> + +map *dict = map_new((cmp_func) strcmp); + +map_insert(dict, "ONE", NULL); +assert(map_size(dict) == 1); +---- + [[map_clear]] +void map_clear(map *self)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |