From f504699fb346eeb37b2ea2afe493566a26be7f4e Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sat, 9 Jan 2021 23:55:42 +0100 Subject: Added cmap benchmark and external picobenchmark.hpp Updated cstr.h --- docs/cmap_api.md | 3 +-- docs/cset_api.md | 47 ++++++++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 23 deletions(-) (limited to 'docs') diff --git a/docs/cmap_api.md b/docs/cmap_api.md index ee20793e..5e0a9fa3 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -134,8 +134,7 @@ using_cmap_str(); int main() { // Create an unordered_map of three strings (that map to strings) - cmap_str u = cmap_inits; - c_push_items(&u, cmap_str, { + c_init (cmap_str, u, { {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} diff --git a/docs/cset_api.md b/docs/cset_api.md index 831b5cdf..6ab0fb00 100644 --- a/docs/cset_api.md +++ b/docs/cset_api.md @@ -91,31 +91,36 @@ uint32_t c_default_hash32(const void* data, size_t len); ## Example ```c #include -#include "stc/cstr.h" -#include "stc/cset.h" +#include +#include + using_cset_str(); int main () { - cset_str first = cset_inits; // empty - cset_str second = cset_inits; c_push_items(&second, cset_str, {"red","green","blue"}); // init list - cset_str third = cset_inits; c_push_items(&third, cset_str, {"orange","pink","yellow"}); // init list - cset_str fourth = cset_inits; - cset_str_emplace(&fourth, "potatoes"); - cset_str_emplace(&fourth, "milk"); - cset_str_emplace(&fourth, "flour"); - - cset_str fifth = cset_inits; - c_foreach (x, cset_str, second) cset_str_emplace(&fifth, x.ref->str); - c_foreach (x, cset_str, third) cset_str_emplace(&fifth, x.ref->str); - c_foreach (x, cset_str, fourth) cset_str_emplace(&fifth, x.ref->str); - c_del(cset_str, &first, &second, &third, &fourth); - - printf("fifth contains:\n\n"); - c_foreach (x, cset_str, fifth) printf("%s\n", x.ref->str); - cset_str_del(&fifth); - - return 0; + cset_str first = cset_inits; // empty + c_init (cset_str, second, {"red", "green", "blue"}); + c_init (cset_str, third, {"orange", "pink", "yellow"}); + + cset_str fourth = cset_inits; + cset_str_emplace(&fourth, "potatoes"); + cset_str_emplace(&fourth, "milk"); + cset_str_emplace(&fourth, "flour"); + + cset_str fifth = cset_str_clone(second); + c_foreach (i, cset_str, third) + cset_str_insert(&fifth, cset_str_value_clone(*i.ref)); + c_foreach (i, cset_str, fourth) + cset_str_emplace(&fifth, i.ref->str); + + c_del(cset_str, &first, &second, &third, &fourth); + + printf("fifth contains:\n\n"); + c_foreach (i, cset_str, fifth) + printf("%s\n", i.ref->str); + + cset_str_del(&fifth); + return 0; } ``` Output: -- cgit v1.2.3