summaryrefslogtreecommitdiffhomepage
path: root/docs/cset_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-12-01 21:45:19 +0100
committerTyge Løvset <[email protected]>2020-12-01 21:45:19 +0100
commitae032cb11e32f08258dd78c23e7624663cd25ef6 (patch)
tree7f9657c6c8dff0ab274cb713d35fbf3e96835daf /docs/cset_api.md
parent65033a7da71abb322b3dacf3e4a160961972c39e (diff)
downloadSTC-modified-ae032cb11e32f08258dd78c23e7624663cd25ef6.tar.gz
STC-modified-ae032cb11e32f08258dd78c23e7624663cd25ef6.zip
Added some examples.
Diffstat (limited to 'docs/cset_api.md')
-rw-r--r--docs/cset_api.md50
1 files changed, 35 insertions, 15 deletions
diff --git a/docs/cset_api.md b/docs/cset_api.md
index 92d6afe4..f0c62c8a 100644
--- a/docs/cset_api.md
+++ b/docs/cset_api.md
@@ -104,25 +104,45 @@ uint32_t c_default_hash16(const void *data, size_t len);
uint32_t c_default_hash32(const void* data, size_t len);
```
-Example:
+## Example
```c
+#include <stdio.h>
#include <stc/cstr.h>
-#include <stc/cmap.h>
+#include <stc/cset.h>
using_cset_str();
-int main() {
- cset_str words = cset_str_init();
- cset_str_emplace(&words, "Hello");
- cset_str_emplace(&words, "Crazy");
- cset_str_emplace(&words, "World");
- cset_str_erase(&words, "Crazy");
-
- // iterate the set of cstr_t values:
- c_foreach (i, cset_str, words)
- printf("%s ", i.val->str);
- cset_str_del(&words);
+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.val->str);
+ c_foreach (x, cset_str, third) cset_str_emplace(&fifth, x.val->str);
+ c_foreach (x, cset_str, fourth) cset_str_emplace(&fifth, x.val->str);
+
+ printf("fifth contains:\n-------------\n");
+ c_foreach (x, cset_str, fifth) printf("%s\n", x.val->str);
+
+ c_del(cset_str, &first, &second, &third, &fourth, &fifth);
+ return 0;
}
-// Output:
-Hello World
+```
+Output:
+```
+red
+green
+flour
+orange
+blue
+pink
+yellow
+milk
+potatoes
```