summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-08-16 14:40:42 +0200
committerGitHub <[email protected]>2020-08-16 14:40:42 +0200
commit67d93d05586ffc8d2180c134a913434ca55e79d7 (patch)
treeda300fc8cbe2a850d0d05ba348409f963bfbc8d1
parentdad0f5157e729d60ef3ab0164284a095384610b7 (diff)
downloadSTC-modified-67d93d05586ffc8d2180c134a913434ca55e79d7.tar.gz
STC-modified-67d93d05586ffc8d2180c134a913434ca55e79d7.zip
Update README.md
-rw-r--r--README.md6
1 files changed, 6 insertions, 0 deletions
diff --git a/README.md b/README.md
index 8a471b18..8118684f 100644
--- a/README.md
+++ b/README.md
@@ -138,6 +138,12 @@ cmap_si_destroy(&map);
An alternative is to use *char* * as key type, but then you must manage allcoated memory of the hash char* keys yourself.
Note that this customization is also available for **cvec**, but only affects the *find()* function currently. See *declare_cvec_str()*.
+Finally, cmap mimics c++17 unordered_map::try_emplace() and avoids cstr memory leak if key already exists in this example:
+`
+declare_cmap_str(ss, cstr_t, cstr_destroy); // cstr_t -> cstr_t
+...
+cmap_try_emplace(&map, ss, "already here", cstr_make("won't be called then")); // special: tag 'ss' is a parameter here.
+`
You may want to look at **examples/advanced.c**, it demonstrates how to use a custom struct as a hash map key, using the optional parameters to declare_cmap().
Example usages