summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-15 23:12:58 +0200
committerTyge Løvset <[email protected]>2020-09-15 23:12:58 +0200
commit0ce57669673a5a22d8207ec884bcebb97cb18448 (patch)
treed76c4b38431efee766d97ba572fa3127a3e05976 /examples
parentf4435af2fc9e9187f7be0149c2eb916db27cb257 (diff)
downloadSTC-modified-0ce57669673a5a22d8207ec884bcebb97cb18448.tar.gz
STC-modified-0ce57669673a5a22d8207ec884bcebb97cb18448.zip
Simplified declare_ statement e.g. c_cmap(...)
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/geek1.c2
-rw-r--r--examples/geek2.c4
-rw-r--r--examples/geek3.c4
-rw-r--r--examples/geek4.c6
-rw-r--r--examples/geek5.c4
-rw-r--r--examples/geek6.c2
-rw-r--r--examples/geek7.c6
-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
23 files changed, 59 insertions, 59 deletions
diff --git a/examples/README.md b/examples/README.md
index 5c9c990a..98e366df 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 cdef_cmap() macro to define {Viking -> int} hash map type:
+With this in place, we use the full c_cmap() macro to define {Viking -> int} hash map type:
```
-cdef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+c_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 ab2cec5f..1f4907c6 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 cdef_cmap() macro to define [Viking -> int] hash map type:
-cdef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+// Using the full c_cmap() macro to define [Viking -> int] hash map type:
+c_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 04995de0..55cae17f 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
-cdef_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
+c_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
KHASH_MAP_INIT_INT64(ii, int64_t)
diff --git a/examples/birthday.c b/examples/birthday.c
index c6a9e541..e2d2600a 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -7,7 +7,7 @@
#include <stc/cvec.h>
#include <stc/cstr.h>
-cdef_cmap(ic, uint64_t, uint8_t);
+c_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)
}
-cdef_cmap(x, uint32_t, uint64_t);
-cdef_cvec(x, uint64_t);
+c_cmap(x, uint32_t, uint64_t);
+c_cvec(x, uint64_t);
void distribution(void)
{
diff --git a/examples/complex.c b/examples/complex.c
index f129884a..d3f2cf4e 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -5,10 +5,10 @@
void check_destroy(float* v) {printf("destroy %g\n", *v);}
-cdef_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
-cdef_clist(y, carray2f, carray2f_destroy, c_no_compare);
-cdef_cmap(g, int, clist_y, clist_y_destroy);
-cdef_cmap_strkey(s, cmap_g, cmap_g_destroy);
+c_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
+c_clist(y, carray2f, carray2f_destroy, c_no_compare);
+c_cmap(g, int, clist_y, clist_y_destroy);
+c_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 b3ed91bb..78636864 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -34,7 +34,7 @@ void stringdemo1()
}
-cdef_cvec(ix, int64_t); // ix is just an example tag name.
+c_cvec(ix, int64_t); // ix is just an example tag name.
void vectordemo1()
{
@@ -55,7 +55,7 @@ void vectordemo1()
-cdef_cvec_str();
+c_cvec_str();
void vectordemo2()
{
@@ -73,7 +73,7 @@ void vectordemo2()
cvec_str_destroy(&names);
}
-cdef_clist(ix, int);
+c_clist(ix, int);
void listdemo1()
{
@@ -100,7 +100,7 @@ void listdemo1()
clist_ix_destroy(&nums);
}
-cdef_cset(i, int);
+c_cset(i, int);
void setdemo1()
{
@@ -115,7 +115,7 @@ void setdemo1()
}
-cdef_cmap(ii, int, int);
+c_cmap(ii, int, int);
void mapdemo1()
{
@@ -128,7 +128,7 @@ void mapdemo1()
}
-cdef_cmap_strkey(si, int); // Shorthand macro for the general cdef_cmap expansion.
+c_cmap_strkey(si, int); // Shorthand macro for the general c_cmap expansion.
void mapdemo2()
{
@@ -150,7 +150,7 @@ void mapdemo2()
}
-cdef_cmap_str();
+c_cmap_str();
void mapdemo3()
{
@@ -172,7 +172,7 @@ void mapdemo3()
}
-cdef_carray(f, float);
+c_carray(f, float);
void arraydemo1()
{
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c
index 402fba32..63e16f3c 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.
-cdef_cmap(i, int, size_t);
+c_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->key, &b->key);
}
// Vector: typetag 'e' for (map) entry
-cdef_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
+c_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
int main()
{
diff --git a/examples/geek1.c b/examples/geek1.c
index 50e23032..8da51f47 100644
--- a/examples/geek1.c
+++ b/examples/geek1.c
@@ -12,7 +12,7 @@ int a[] = { 1, 2, 2, 3, 2, 4, 10 };
#include <stdio.h>
#include <stc/cmap.h>
-cdef_cmap(ii, int, int);
+c_cmap(ii, int, int);
// Function to maximize the number of pairs
int findMaximumPairs(int a[], int n, int k)
diff --git a/examples/geek2.c b/examples/geek2.c
index 8b1ff2aa..778960f3 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-cdef_cmap_str();
-cdef_cset_str();
+c_cmap_str();
+c_cset_str();
int main()
{
diff --git a/examples/geek3.c b/examples/geek3.c
index 4e83a8ec..a3b41ee1 100644
--- a/examples/geek3.c
+++ b/examples/geek3.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-cdef_cmap_strkey(si, int);
-cdef_cmap_strkey(ss, cstr_t, cstr_destroy);
+c_cmap_strkey(si, int);
+c_cmap_strkey(ss, cstr_t, cstr_destroy);
int main ()
{
diff --git a/examples/geek4.c b/examples/geek4.c
index 3c4c085f..91fb122d 100644
--- a/examples/geek4.c
+++ b/examples/geek4.c
@@ -37,9 +37,9 @@ Efficient Approach: For all the words of the first sentence, we can check if it
#include <stc/cvec.h>
#include <stc/cstr.h>
-cdef_cvec_str();
-cdef_cmap_strkey(sb, bool);
-cdef_cvec(sb, cmap_sb_entry_t, cmap_sb_entry_destroy, c_no_compare);
+c_cvec_str();
+c_cmap_strkey(sb, bool);
+c_cvec(sb, cmap_sb_entry_t, cmap_sb_entry_destroy, c_no_compare);
// Function to return the count of common words
// in all the sentences
diff --git a/examples/geek5.c b/examples/geek5.c
index d8b520c6..f19edf8c 100644
--- a/examples/geek5.c
+++ b/examples/geek5.c
@@ -21,8 +21,8 @@ Output: 0
#include <stc/cvec.h>
#include <stc/cstr.h>
-cdef_cvec(i, int);
-cdef_cmap_strkey(sv, cvec_i, cvec_i_destroy);
+c_cvec(i, int);
+c_cmap_strkey(sv, cvec_i, cvec_i_destroy);
// Function to return the number of occurrences of
diff --git a/examples/geek6.c b/examples/geek6.c
index f03053ca..a973312c 100644
--- a/examples/geek6.c
+++ b/examples/geek6.c
@@ -30,7 +30,7 @@ operation in almost O(1) time complexity.
#include <stdio.h>
#include <stc/cmap.h>
-cdef_cset(i, int);
+c_cset(i, int);
// Function to find the smallest positive
// missing number
diff --git a/examples/geek7.c b/examples/geek7.c
index cb0b35a0..eb78b43b 100644
--- a/examples/geek7.c
+++ b/examples/geek7.c
@@ -27,9 +27,9 @@ After inserting all the elements excluding the ones which are to be deleted, Pop
#include <stc/cvec.h>
#include <stc/cpqueue.h>
-cdef_cmap(ii, int, int);
-cdef_cvec(i, int);
-cdef_cpqueue(i, cvec_i, >);
+c_cmap(ii, int, int);
+c_cvec(i, int);
+c_cpqueue(i, cvec_i, >);
// Find k minimum element from arr[0..m-1] after deleting
// elements from del[0..n-1]
diff --git a/examples/heap.c b/examples/heap.c
index fc067a41..99806c17 100644
--- a/examples/heap.c
+++ b/examples/heap.c
@@ -4,8 +4,8 @@
#include <stc/cvec.h>
#include <stc/cpqueue.h>
-cdef_cvec(f, float);
-cdef_cpqueue(f, cvec_f, >);
+c_cvec(f, float);
+c_cpqueue(f, cvec_f, >);
int main()
{
diff --git a/examples/inits.c b/examples/inits.c
index 37b08624..5fdb5c30 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -5,19 +5,19 @@
#include <stc/cpqueue.h>
#include <stc/clist.h>
-cdef_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
-cdef_cmap_strkey(cnt, int);
+c_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
+c_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);
}
-cdef_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
-cdef_clist(ip, ipair_t, c_default_destroy, ipair_compare);
+c_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
+c_clist(ip, ipair_t, c_default_destroy, ipair_compare);
-cdef_cvec(f, float);
-cdef_cpqueue(f, cvec_f, >);
+c_cvec(f, float);
+c_cpqueue(f, cvec_f, >);
int main(void) {
diff --git a/examples/list.c b/examples/list.c
index c77be371..cea8c7f6 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -2,7 +2,7 @@
#include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
-cdef_clist(fx, double);
+c_clist(fx, double);
int main() {
int k, n = 100000;
diff --git a/examples/mapmap.c b/examples/mapmap.c
index 4e71f6c0..94f4139e 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-cdef_cmap_str();
-cdef_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
+c_cmap_str();
+c_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 716d4e92..04ba2094 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -25,7 +25,7 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-cdef_cmap_str();
+c_cmap_str();
void print_phone_book(cmap_str phone_book)
{
diff --git a/examples/priority.c b/examples/priority.c
index ffc4f97b..6e39e63b 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -6,8 +6,8 @@
#include <stc/cmap.h>
#include <stc/crandom.h>
-cdef_cvec(i, int64_t);
-cdef_cpqueue(i, cvec_i, >); // min-heap (increasing values)
+c_cvec(i, int64_t);
+c_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 a912d8ea..addecaa6 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -2,8 +2,8 @@
#include <stc/cqueue.h>
#include <stdio.h>
-cdef_clist(i, int);
-cdef_cqueue(i, clist_i); // min-heap (increasing values)
+c_clist(i, int);
+c_cqueue(i, clist_i); // min-heap (increasing values)
int main() {
int n = 10000000;
diff --git a/examples/stack.c b/examples/stack.c
index a60e5564..ba7de082 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -3,10 +3,10 @@
#include <stc/cstr.h>
#include <stc/cstack.h>
-cdef_cvec(i, int);
-cdef_cvec(c, char);
-cdef_cstack(i, cvec_i);
-cdef_cstack(c, cvec_c);
+c_cvec(i, int);
+c_cvec(c, char);
+c_cstack(i, cvec_i);
+c_cstack(c, cvec_c);
int main() {
cstack_i stack = cstack_i_init();
diff --git a/examples/words.c b/examples/words.c
index ad37f72e..65e7e02d 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -4,9 +4,9 @@
#include <stc/clist.h>
#include <stc/cvec.h>
-cdef_cvec_str();
-cdef_clist_str();
-cdef_cmap_strkey(si, int);
+c_cvec_str();
+c_clist_str();
+c_cmap_strkey(si, int);
int main1()