summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-06-18 23:30:14 +0200
committerTyge Løvset <[email protected]>2021-06-18 23:30:14 +0200
commit3776efeb26088cde334eda8e8dcda66431a9a0cf (patch)
tree3cb3eaa544b05bc3cbbb006d76504970777570e9 /examples
parentde216de5b32da73ce835d2a3d03b4dd44bfeaf6d (diff)
downloadSTC-modified-3776efeb26088cde334eda8e8dcda66431a9a0cf.tar.gz
STC-modified-3776efeb26088cde334eda8e8dcda66431a9a0cf.zip
Simplified and removed unneeded stuff from csview.h
Diffstat (limited to 'examples')
-rw-r--r--examples/svmap.c38
1 files changed, 0 insertions, 38 deletions
diff --git a/examples/svmap.c b/examples/svmap.c
deleted file mode 100644
index d0f84ce4..00000000
--- a/examples/svmap.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <stc/csview.h>
-#include <stc/cmap.h>
-#include <stdio.h>
-
-// cmap<cstr, int> with csview as convertion key-type (raw):
-using_cmap_strvkey(si, int);
-
-int main() {
- csview fox = c_sv("The quick brown fox jumps over the lazy dog.");
- printf("\"%s\", length=%zu\n", fox.str, fox.size);
-
- c_forvar_initdel (cmap_si, frequencies)
- {
- // Non-emplace: cstr element API
- cmap_si_insert(&frequencies, cstr_lit("thousand"), 1000);
- cmap_si_insert_or_assign(&frequencies, cstr_lit("thousand"), 2000);
- cmap_si_insert(&frequencies, cstr_lit("thousand"), 3000); // ignored
-
- // Emplace: csview element API
- const char* key = "hundred";
- cmap_si_emplace(&frequencies, c_sv("hundred"), 300); // c_sv() shorthand for csview_lit()
- cmap_si_emplace(&frequencies, csview_from_n(key, 4), 400); // insert "hund"
- cmap_si_emplace_or_assign(&frequencies, csview_from(key), 500); // update
- cmap_si_emplace(&frequencies, c_sv("hundred"), 600); // ignored, already inserted
-
- // Lookup always uses "raw" type API, i.e. csview here.
- printf("at(\"hundred\"): %d\n", *cmap_si_at(&frequencies, c_sv("hundred")));
-
- c_foreach (i, cmap_si, frequencies)
- printf("%s: %d\n", i.ref->first.str, i.ref->second);
- }
- /* Output: */
- // "The quick brown fox jumps over the lazy dog.", length=44
- // at("hundred"): 500
- // hund: 400
- // hundred: 500
- // thousand: 2000
-} \ No newline at end of file