summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authortylo <[email protected]>2020-08-28 10:14:56 +0200
committertylo <[email protected]>2020-08-28 10:14:56 +0200
commitdc1b74109029bc82efea290475431cafc0307674 (patch)
tree73f9e7ac75c6e6ee015417010034827bfbfa9265 /examples
parentc1131d5a5117a79f3fc0a1b693637be7a5298ab3 (diff)
downloadSTC-modified-dc1b74109029bc82efea290475431cafc0307674.tar.gz
STC-modified-dc1b74109029bc82efea290475431cafc0307674.zip
Finished adding RawValue API (convertable values) to containers.
Diffstat (limited to 'examples')
-rw-r--r--examples/benchmark.c2
-rw-r--r--examples/complex.c2
-rw-r--r--examples/demos.c10
-rw-r--r--examples/geek2.c43
-rw-r--r--examples/geek3.c4
-rw-r--r--examples/geek4.c10
-rw-r--r--examples/geek5.c2
-rw-r--r--examples/inits.c2
-rw-r--r--examples/mapmap.c4
-rw-r--r--examples/words.c4
10 files changed, 44 insertions, 39 deletions
diff --git a/examples/benchmark.c b/examples/benchmark.c
index 3ff193bc..0b9c4f10 100644
--- a/examples/benchmark.c
+++ b/examples/benchmark.c
@@ -124,7 +124,7 @@ crandom_eng64_t rng;
const size_t N1 = 10000000 * 5;
const size_t N2 = 10000000 * 5;
-const size_t N3 = 10000000 * 10;
+const size_t N3 = 10000000 * 5;
#define RR 20
int rr = RR;
diff --git a/examples/complex.c b/examples/complex.c
index cd8a6d78..08a3b505 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -8,7 +8,7 @@ void check_destroy(float* v) {printf("destroy %g\n", *v);}
declare_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
declare_clist(t2, carray2f, carray2f_destroy, c_no_compare);
declare_cmap(il, int, clist_t2, clist_t2_destroy);
-declare_cmap_str(sm, cmap_il, cmap_il_destroy);
+declare_cmap_strkey(sm, cmap_il, cmap_il_destroy);
int main() {
int xdim = 4, ydim = 6;
diff --git a/examples/demos.c b/examples/demos.c
index a3e512e5..4f5c2356 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -62,9 +62,9 @@ void vectordemo2()
{
printf("\nVECTORDEMO2\n");
cvec_str names = cvec_init;
- cvec_str_push_back(&names, cstr_make("Mary"));
- cvec_str_push_back(&names, cstr_make("Joe"));
- cvec_str_push_back(&names, cstr_make("Chris"));
+ cvec_str_push_back(&names, "Mary");
+ cvec_str_push_back(&names, "Joe");
+ cvec_str_push_back(&names, "Chris");
cstr_assign(&names.data[1], "Jane"); // replace Joe
printf("names[1]: %s\n", names.data[1].str);
@@ -130,7 +130,7 @@ void mapdemo1()
}
-declare_cmap_str(si, int); // Shorthand macro for the general declare_cmap expansion.
+declare_cmap_strkey(si, int); // Shorthand macro for the general declare_cmap expansion.
void mapdemo2()
{
@@ -152,7 +152,7 @@ void mapdemo2()
}
-declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cmap_strkey(ss, cstr_t, cstr_destroy);
void mapdemo3()
{
diff --git a/examples/geek2.c b/examples/geek2.c
index 9b2785f1..6141518f 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -1,16 +1,16 @@
-#ifndef CXX
+#ifndef RUST
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cmap_str();
declare_cset_str();
int main()
{
// Lets use an explicit type signature (which would
// be `cmap<String, String>` in this example).
- cmap_ss book_reviews = cmap_init;
+ cmap_str book_reviews = cmap_init;
cset_str set = cset_init;
cset_str_put(&set, "Hello");
cset_str_put(&set, "You");
@@ -19,50 +19,57 @@ int main()
printf("%s ", i.item->key.str); puts("");
// Review some books.
- cmap_ss_put(&book_reviews,
+ c_push(&book_reviews, cmap_str, c_items(
+ {"Adventures of Huckleberry Finn", "My favorite book."},
+ {"Grimms' Fairy Tales", "Masterpiece."},
+ {"Pride and Prejudice", "Very enjoyable."},
+ {"The Adventures of Sherlock Holmes", "Eye lyked it alot."},
+ ));
+/*
+ cmap_str_insert(&book_reviews,
"Adventures of Huckleberry Finn",
- cstr_make("My favorite book.")
+ "My favorite book."
);
- cmap_ss_put(&book_reviews,
+ cmap_str_insert(&book_reviews,
"Grimms' Fairy Tales",
- cstr_make("Masterpiece.")
+ "Masterpiece."
);
- cmap_ss_put(&book_reviews,
+ cmap_str_insert(&book_reviews,
"Pride and Prejudice",
- cstr_make("Very enjoyable.")
+ "Very enjoyable."
);
- cmap_ss_put(&book_reviews,
+ cmap_str_insert(&book_reviews,
"The Adventures of Sherlock Holmes",
- cstr_make("Eye lyked it alot.")
+ "Eye lyked it alot."
);
-
+*/
// Check for a specific one.
// When collections store owned values (String), they can still be
// queried using references (&str).
- if (! cmap_ss_find(&book_reviews, "Les Misérables")) {
+ if (! cmap_str_find(&book_reviews, "Les Misérables")) {
printf("We've got %zu reviews, but Les Misérables ain't one.\n",
cmap_size(book_reviews));
}
// oops, this review has a lot of spelling mistakes, let's delete it.
- cmap_ss_erase(&book_reviews, "The Adventures of Sherlock Holmes");
+ cmap_str_erase(&book_reviews, "The Adventures of Sherlock Holmes");
// Look up the values associated with some keys.
const char* to_find[] = {"Pride and Prejudice", "Alice's Adventure in Wonderland", NULL};
for (const char** book = to_find; *book; ++book) {
- cmap_ss_entry_t *review = cmap_ss_find(&book_reviews, *book);
+ cmap_str_entry_t *review = cmap_str_find(&book_reviews, *book);
if (review) printf("%s: %s\n", *book, review->value.str);
else printf("%s is unreviewed.\n", *book);
}
// Look up the value for a key (will panic if the key is not found).
- printf("Review for Jane: %s\n", cmap_ss_find(&book_reviews, "Pride and Prejudice")->value.str);
+ printf("Review for Jane: %s\n", cmap_str_find(&book_reviews, "Pride and Prejudice")->value.str);
// Iterate over everything.
- c_foreach (i, cmap_ss, book_reviews) {
+ c_foreach (i, cmap_str, book_reviews) {
printf("- %s: \"%s\"\n", i.item->key.str, i.item->value.str);
}
- cmap_ss_destroy(&book_reviews);
+ cmap_str_destroy(&book_reviews);
}
#else // ======================================================
diff --git a/examples/geek3.c b/examples/geek3.c
index b8de97c8..ad2bdfa1 100644
--- a/examples/geek3.c
+++ b/examples/geek3.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str(si, int);
-declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cmap_strkey(si, int);
+declare_cmap_strkey(ss, cstr_t, cstr_destroy);
int main ()
{
diff --git a/examples/geek4.c b/examples/geek4.c
index b0a57844..a62a6fd1 100644
--- a/examples/geek4.c
+++ b/examples/geek4.c
@@ -38,7 +38,7 @@ Efficient Approach: For all the words of the first sentence, we can check if it
#include <stc/cstr.h>
declare_cvec_str();
-declare_cmap_str(sb, bool);
+declare_cmap_strkey(sb, bool);
declare_cvec(sb, cmap_sb_entry_t, cmap_sb_entry_destroy, c_no_compare);
// Function to return the count of common words
@@ -137,10 +137,10 @@ int commonWords(cvec_str S)
int main()
{
cvec_str S = cvec_init;
- cvec_str_push_back(&S, cstr_make("there is a cow"));
- cvec_str_push_back(&S, cstr_make("cow is our mother"));
- cvec_str_push_back(&S, cstr_make("cow gives us milk and milk is sweet"));
- cvec_str_push_back(&S, cstr_make("there is a boy who loves cow"));
+ cvec_str_push_back(&S, "there is a cow");
+ cvec_str_push_back(&S, "cow is our mother");
+ cvec_str_push_back(&S, "cow gives us milk and milk is sweet");
+ cvec_str_push_back(&S, "there is a boy who loves cow");
printf("%d\n", commonWords(S));
cvec_str_destroy(&S);
diff --git a/examples/geek5.c b/examples/geek5.c
index 67f5d097..a0531ad3 100644
--- a/examples/geek5.c
+++ b/examples/geek5.c
@@ -22,7 +22,7 @@ Output: 0
#include <stc/cstr.h>
declare_cvec(i, int);
-declare_cmap_str(sv, cvec_i, cvec_i_destroy);
+declare_cmap_strkey(sv, cvec_i, cvec_i_destroy);
// Function to return the number of occurrences of
diff --git a/examples/inits.c b/examples/inits.c
index 92e67b84..c55bf83f 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -5,7 +5,7 @@
#include <stc/clist.h>
declare_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
-declare_cmap_str(cnt, int);
+declare_cmap_strkey(cnt, int);
typedef struct {int x, y;} ipair_t;
inline static int ipair_compare(const ipair_t* a, const ipair_t* b) {
diff --git a/examples/mapmap.c b/examples/mapmap.c
index 14ccd9a9..1f2bd4f5 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -8,8 +8,8 @@ static void my_str_destr(cstr_t* x) {
cstr_destroy(x);
}
-declare_cmap_str(ss, cstr_t, my_str_destr);
-declare_cmap_str(cfg, cmap_ss, cmap_ss_destroy);
+declare_cmap_strkey(ss, cstr_t, my_str_destr);
+declare_cmap_strkey(cfg, cmap_ss, cmap_ss_destroy);
int main(void) {
cmap_cfg config = cmap_init;
diff --git a/examples/words.c b/examples/words.c
index a10811c1..f8e86329 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -6,9 +6,7 @@
declare_cvec_str();
declare_clist_str();
-declare_cmap_str(si, int);
-
-typedef const char* input_t;
+declare_cmap_strkey(si, int);
int main1()
{