summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-17 18:37:34 +0200
committerTyge Løvset <[email protected]>2020-09-17 18:37:34 +0200
commit692ab82818e2d65177e06d7717d9184b7bc27ff1 (patch)
tree0f59d93da6d579a68c7247434cab6e6e615e5b4a /examples
parent92edcbf8da88b1e59c7724f2875e9e9df3383cb1 (diff)
downloadSTC-modified-692ab82818e2d65177e06d7717d9184b7bc27ff1.tar.gz
STC-modified-692ab82818e2d65177e06d7717d9184b7bc27ff1.zip
Fixed range methods in cvec, and renamed typename_<container>(..) to using_<container>(..).
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md4
-rw-r--r--examples/advanced.c4
-rw-r--r--examples/benchmark.c2
-rw-r--r--examples/birthday.c6
-rw-r--r--examples/complex.c8
-rw-r--r--examples/demos.c16
-rw-r--r--examples/ex_gaussian.c4
-rw-r--r--examples/heap.c4
-rw-r--r--examples/inits.c12
-rw-r--r--examples/list.c2
-rw-r--r--examples/mapmap.c4
-rw-r--r--examples/phonebook.c2
-rw-r--r--examples/priority.c4
-rw-r--r--examples/queue.c4
-rw-r--r--examples/stack.c8
-rw-r--r--examples/words.c6
16 files changed, 45 insertions, 45 deletions
diff --git a/examples/README.md b/examples/README.md
index 8820f5cf..95880385 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -51,9 +51,9 @@ static inline Viking viking_fromVw(VikingVw vw) { // note: parameter is by value
Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk;
}
```
-With this in place, we use the full typedef_cmap() macro to define {Viking -> int} hash map type:
+With this in place, we use the full using_cmap() macro to define {Viking -> int} hash map type:
```
-typedef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+using_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, VikingVw, viking_toVw, viking_fromVw);
```
cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. cmap_vk_destroy() will free all memory allocated for Viking keys and the hash table values.
diff --git a/examples/advanced.c b/examples/advanced.c
index 2c736e2d..200ab5a3 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -50,8 +50,8 @@ Viking viking_fromVw(VikingVw vw) {
Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk;
}
-// Using the full typedef_cmap() macro to define [Viking -> int] hash map type:
-typedef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+// Using the full using_cmap() macro to define [Viking -> int] hash map type:
+using_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, VikingVw, viking_toVw, viking_fromVw);
// cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test.
diff --git a/examples/benchmark.c b/examples/benchmark.c
index 7b0e1fa5..a02e8be8 100644
--- a/examples/benchmark.c
+++ b/examples/benchmark.c
@@ -22,7 +22,7 @@ static inline uint32_t fibonacci_hash(const void* data, size_t len) {
}
// cmap and khash template expansion
-typedef_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash); // c_default_hash16);
+using_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash); // c_default_hash16);
KHASH_MAP_INIT_INT64(ii, int64_t)
diff --git a/examples/birthday.c b/examples/birthday.c
index e085e25c..7bee3658 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -7,7 +7,7 @@
#include <stc/cvec.h>
#include <stc/cstr.h>
-typedef_cmap(ic, uint64_t, uint8_t);
+using_cmap(ic, uint64_t, uint8_t);
const static uint64_t seed = 1234;
const static uint64_t N = 1ull << 27;
@@ -29,8 +29,8 @@ void repeats(void)
}
-typedef_cmap(x, uint32_t, uint64_t);
-typedef_cvec(x, uint64_t);
+using_cmap(x, uint32_t, uint64_t);
+using_cvec(x, uint64_t);
void distribution(void)
{
diff --git a/examples/complex.c b/examples/complex.c
index 0c3e5c38..12afc47c 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -5,10 +5,10 @@
void check_destroy(float* v) {printf("destroy %g\n", *v);}
-typedef_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
-typedef_clist(y, carray2f, carray2f_destroy, c_no_compare);
-typedef_cmap(g, int, clist_y, clist_y_destroy);
-typedef_cmap_strkey(s, cmap_g, cmap_g_destroy);
+using_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
+using_clist(y, carray2f, carray2f_destroy, c_no_compare);
+using_cmap(g, int, clist_y, clist_y_destroy);
+using_cmap_strkey(s, cmap_g, cmap_g_destroy);
int main() {
int xdim = 4, ydim = 6;
diff --git a/examples/demos.c b/examples/demos.c
index f39b439f..6f5c0207 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -34,7 +34,7 @@ void stringdemo1()
}
-typedef_cvec(ix, int64_t); // ix is just an example tag name.
+using_cvec(ix, int64_t); // ix is just an example tag name.
void vectordemo1()
{
@@ -55,7 +55,7 @@ void vectordemo1()
-typedef_cvec_str();
+using_cvec_str();
void vectordemo2()
{
@@ -73,7 +73,7 @@ void vectordemo2()
cvec_str_destroy(&names);
}
-typedef_clist(ix, int);
+using_clist(ix, int);
void listdemo1()
{
@@ -100,7 +100,7 @@ void listdemo1()
clist_ix_destroy(&nums);
}
-typedef_cset(i, int);
+using_cset(i, int);
void setdemo1()
{
@@ -115,7 +115,7 @@ void setdemo1()
}
-typedef_cmap(ii, int, int);
+using_cmap(ii, int, int);
void mapdemo1()
{
@@ -128,7 +128,7 @@ void mapdemo1()
}
-typedef_cmap_strkey(si, int); // Shorthand macro for the general typedef_cmap expansion.
+using_cmap_strkey(si, int); // Shorthand macro for the general using_cmap expansion.
void mapdemo2()
{
@@ -150,7 +150,7 @@ void mapdemo2()
}
-typedef_cmap_str();
+using_cmap_str();
void mapdemo3()
{
@@ -172,7 +172,7 @@ void mapdemo3()
}
-typedef_carray(f, float);
+using_carray(f, float);
void arraydemo1()
{
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c
index 3c3a05bf..033c0ebd 100644
--- a/examples/ex_gaussian.c
+++ b/examples/ex_gaussian.c
@@ -7,14 +7,14 @@
#include <stc/cvec.h>
// Declare int -> int hashmap. Uses typetag 'i' for ints.
-typedef_cmap(i, int, size_t);
+using_cmap(i, int, size_t);
// Declare int vector with map entries that can be sorted by map keys.
static int compare(cmap_i_entry_t *a, cmap_i_entry_t *b) {
return c_default_compare(&a->first, &b->first);
}
// Vector: typetag 'e' for (map) entry
-typedef_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
+using_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
int main()
{
diff --git a/examples/heap.c b/examples/heap.c
index 18ba247c..89f700d2 100644
--- a/examples/heap.c
+++ b/examples/heap.c
@@ -4,8 +4,8 @@
#include <stc/cvec.h>
#include <stc/cpqueue.h>
-typedef_cvec(f, float);
-typedef_cpqueue(f, cvec_f, >);
+using_cvec(f, float);
+using_cpqueue(f, cvec_f, >);
int main()
{
diff --git a/examples/inits.c b/examples/inits.c
index 7cad8f4e..c64ca574 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -5,19 +5,19 @@
#include <stc/cpqueue.h>
#include <stc/clist.h>
-typedef_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
-typedef_cmap_strkey(cnt, int);
+using_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
+using_cmap_strkey(cnt, int);
typedef struct {int x, y;} ipair_t;
inline static int ipair_compare(const ipair_t* a, const ipair_t* b) {
int c = c_default_compare(&a->x, &b->x);
return c != 0 ? c : c_default_compare(&a->y, &b->y);
}
-typedef_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
-typedef_clist(ip, ipair_t, c_default_destroy, ipair_compare);
+using_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
+using_clist(ip, ipair_t, c_default_destroy, ipair_compare);
-typedef_cvec(f, float);
-typedef_cpqueue(f, cvec_f, >);
+using_cvec(f, float);
+using_cpqueue(f, cvec_f, >);
int main(void) {
diff --git a/examples/list.c b/examples/list.c
index 9c393bcc..abc4d5b7 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -2,7 +2,7 @@
#include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
-typedef_clist(fx, double);
+using_clist(fx, double);
int main() {
int k;
diff --git a/examples/mapmap.c b/examples/mapmap.c
index f40d6be5..57bcf384 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-typedef_cmap_str();
-typedef_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
+using_cmap_str();
+using_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
int main(void) {
cmap_cfg config = cmap_ini;
diff --git a/examples/phonebook.c b/examples/phonebook.c
index 66b54e33..25d6ddb0 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -25,7 +25,7 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-typedef_cmap_str();
+using_cmap_str();
void print_phone_book(cmap_str phone_book)
{
diff --git a/examples/priority.c b/examples/priority.c
index d35ec4c7..12e4be25 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -6,8 +6,8 @@
#include <stc/cmap.h>
#include <stc/crandom.h>
-typedef_cvec(i, int64_t);
-typedef_cpqueue(i, cvec_i, >); // min-heap (increasing values)
+using_cvec(i, int64_t);
+using_cpqueue(i, cvec_i, >); // min-heap (increasing values)
int main() {
size_t N = 10000000;
diff --git a/examples/queue.c b/examples/queue.c
index 330e79fe..e1eaf5d4 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -2,8 +2,8 @@
#include <stc/cqueue.h>
#include <stdio.h>
-typedef_clist(i, int);
-typedef_cqueue(i, clist_i); // min-heap (increasing values)
+using_clist(i, int);
+using_cqueue(i, clist_i); // min-heap (increasing values)
int main() {
int n = 10000000;
diff --git a/examples/stack.c b/examples/stack.c
index c51c420c..e514808d 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -3,10 +3,10 @@
#include <stc/cstr.h>
#include <stc/cstack.h>
-typedef_cvec(i, int);
-typedef_cvec(c, char);
-typedef_cstack(i, cvec_i);
-typedef_cstack(c, cvec_c);
+using_cvec(i, int);
+using_cvec(c, char);
+using_cstack(i, cvec_i);
+using_cstack(c, cvec_c);
int main() {
cstack_i stack = cstack_i_init();
diff --git a/examples/words.c b/examples/words.c
index 0f799ea2..e22a2a9b 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -4,9 +4,9 @@
#include <stc/clist.h>
#include <stc/cvec.h>
-typedef_cvec_str();
-typedef_clist_str();
-typedef_cmap_strkey(si, int);
+using_cvec_str();
+using_clist_str();
+using_cmap_strkey(si, int);
int main1()