summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-10-05 09:00:28 +0200
committerTyge Løvset <[email protected]>2021-10-05 09:05:25 +0200
commitbf00ed0e7023cf49cf004dd4b4b39af2b824681e (patch)
treeadadcc1ac34fd5b614e566028d37d29db8fb7f80 /examples
parent88c67afa63e46551c67f573e0557323518c42f81 (diff)
downloadSTC-modified-bf00ed0e7023cf49cf004dd4b4b39af2b824681e.tar.gz
STC-modified-bf00ed0e7023cf49cf004dd4b4b39af2b824681e.zip
Changed recommended order of defining template parameters.
Diffstat (limited to 'examples')
-rw-r--r--examples/astar.c4
-rw-r--r--examples/birthday.c2
-rw-r--r--examples/complex.c8
-rw-r--r--examples/cpque.c2
-rw-r--r--examples/csmap_find.c4
-rw-r--r--examples/csmap_insert.c6
-rw-r--r--examples/demos.c12
-rw-r--r--examples/ex_gauss1.c4
-rw-r--r--examples/inits.c11
-rw-r--r--examples/list.c2
-rw-r--r--examples/list_erase.c2
-rw-r--r--examples/list_splice.c2
-rw-r--r--examples/mapmap.c2
-rw-r--r--examples/mmap.c4
-rw-r--r--examples/multimap.c6
-rw-r--r--examples/new_deq.c6
-rw-r--r--examples/new_list.c6
-rw-r--r--examples/new_map.c4
-rw-r--r--examples/new_pque.c4
-rw-r--r--examples/new_queue.c5
-rw-r--r--examples/new_smap.c4
-rw-r--r--examples/new_sptr.c4
-rw-r--r--examples/new_vec.c4
-rw-r--r--examples/priority.c2
-rw-r--r--examples/queue.c2
-rw-r--r--examples/replace.c2
-rw-r--r--examples/stack.c2
27 files changed, 59 insertions, 57 deletions
diff --git a/examples/astar.c b/examples/astar.c
index 5316b954..8c37d070 100644
--- a/examples/astar.c
+++ b/examples/astar.c
@@ -64,16 +64,16 @@ point_key_compare(const point* a, const point* b)
#define i_cmp c_no_compare
#include <stc/cdeq.h>
-#define i_tag pcost
#define i_key point
#define i_val int
#define i_cmp point_key_compare
+#define i_tag pcost
#include <stc/csmap.h>
-#define i_tag pstep
#define i_key point
#define i_val point
#define i_cmp point_key_compare
+#define i_tag pstep
#include <stc/csmap.h>
cdeq_point
diff --git a/examples/birthday.c b/examples/birthday.c
index 242ce78a..f9b777c0 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -29,9 +29,9 @@ static void test_repeats(void)
}
}
-#define i_tag x
#define i_key uint32_t
#define i_val uint64_t
+#define i_tag x
#include <stc/cmap.h>
void test_distribution(void)
diff --git a/examples/complex.c b/examples/complex.c
index e7789815..c910be80 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -2,27 +2,27 @@
void check_del(float* v) {printf("destroy %g\n", *v);}
-#define i_tag f
#define i_val float
#define i_valdel check_del
+#define i_tag f
#include <stc/cstack.h>
-#define i_tag arr
#define i_val cstack_f
#define i_cmp c_no_compare
#define i_valdel cstack_f_del
+#define i_tag arr
#include <stc/clist.h>
-#define i_tag lst
#define i_key int
#define i_val clist_arr
#define i_valdel clist_arr_del
+#define i_tag lst
#include <stc/cmap.h>
-#define i_tag map
#define i_key_str
#define i_val cmap_lst
#define i_valdel cmap_lst_del
+#define i_tag map
#include <stc/cmap.h>
// c++:
diff --git a/examples/cpque.c b/examples/cpque.c
index eabf11d0..541dcb6e 100644
--- a/examples/cpque.c
+++ b/examples/cpque.c
@@ -7,8 +7,8 @@
static int (*icmp_fn)(const int* x, const int* y);
#define i_val int
-#define i_cnt ipque
#define i_cmp icmp_fn
+#define i_cnt ipque
#include <stc/cpque.h>
#define imix_less(x, y) ((*(x) ^ 1) < (*(y) ^ 1))
diff --git a/examples/csmap_find.c b/examples/csmap_find.c
index eca14c52..39ffd975 100644
--- a/examples/csmap_find.c
+++ b/examples/csmap_find.c
@@ -2,14 +2,14 @@
// https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-160#example-17
#include <stc/cstr.h>
-#define i_tag istr
#define i_key int
#define i_val_str
+#define i_tag istr
#include <stc/csmap.h>
-#define i_tag istr
#define i_val csmap_istr_rawvalue_t
#define i_cmp c_no_compare
+#define i_tag istr
#include <stc/cvec.h>
void print_elem(csmap_istr_rawvalue_t p) {
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c
index ede1e5f0..939f2eca 100644
--- a/examples/csmap_insert.c
+++ b/examples/csmap_insert.c
@@ -4,19 +4,19 @@
// This implements the std::map insert c++ example at:
// https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-160#example-19
-#define i_tag ii // Map of int => int
#define i_key int
#define i_val int
+#define i_tag ii // Map of int => int
#include <stc/csmap.h>
-#define i_tag istr // Map of int => cstr
#define i_key int
#define i_val_str
+#define i_tag istr // Map of int => cstr
#include <stc/csmap.h>
-#define i_tag ii
#define i_val csmap_ii_rawvalue_t
#define i_cmp c_no_compare
+#define i_tag ii
#include <stc/cvec.h>
void print_ii(csmap_ii map) {
diff --git a/examples/demos.c b/examples/demos.c
index a874d38d..ab1a95ff 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -28,8 +28,8 @@ void stringdemo1()
}
}
-#define i_tag ix
#define i_val int64_t
+#define i_tag ix
#include <stc/cvec.h>
void vectordemo1()
@@ -72,8 +72,8 @@ void vectordemo2()
}
}
-#define i_tag ix
#define i_val int
+#define i_tag ix
#include <stc/clist.h>
void listdemo1()
@@ -106,8 +106,8 @@ void listdemo1()
}
}
-#define i_tag i
#define i_key int
+#define i_tag i
#include <stc/cset.h>
void setdemo1()
@@ -122,9 +122,9 @@ void setdemo1()
cset_i_del(&nums);
}
-#define i_tag ii
#define i_key int
#define i_val int
+#define i_tag ii
#include <stc/cmap.h>
void mapdemo1()
@@ -137,9 +137,9 @@ void mapdemo1()
cmap_ii_del(&nums);
}
-#define i_tag si
#define i_key_str
#define i_val int
+#define i_tag si
#include <stc/cmap.h>
void mapdemo2()
@@ -186,8 +186,8 @@ void mapdemo3()
}
//#define i_prefix carray3 // backward compatible.
-#define i_tag f
#define i_val float
+#define i_tag f
#include <stc/carr3.h>
void arraydemo1()
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c
index 42337d3b..c96562b6 100644
--- a/examples/ex_gauss1.c
+++ b/examples/ex_gauss1.c
@@ -5,9 +5,9 @@
#include <stc/cstr.h>
// Declare int -> int hashmap. Uses typetag 'ii' for ints.
-#define i_tag ii
#define i_key int32_t
#define i_val size_t
+#define i_tag ii
#include <stc/cmap.h>
// Declare int vector with map entries that can be sorted by map keys.
@@ -16,9 +16,9 @@ static int compare(mapval *a, mapval *b) {
return c_default_compare(&a->first, &b->first);
}
-#define i_tag pair
#define i_val mapval
#define i_cmp compare
+#define i_tag pair
#include <stc/cvec.h>
int main()
diff --git a/examples/inits.c b/examples/inits.c
index 47d01dac..be0914c2 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -1,14 +1,14 @@
#include <stdio.h>
#include <stc/cstr.h>
-#define i_tag id // Map of int => cstr
#define i_key int
#define i_val_str
+#define i_tag id // Map of int => cstr
#include <stc/cmap.h>
-#define i_tag cnt // Map of cstr => int
#define i_key_str
#define i_val int
+#define i_tag cnt // Map of cstr => int
#include <stc/cmap.h>
typedef struct {int x, y;} ipair_t;
@@ -17,18 +17,19 @@ inline static int ipair_compare(const ipair_t* a, const ipair_t* b) {
return cx == 0 ? c_default_compare(&a->y, &b->y) : cx;
}
-#define i_tag ip
+
#define i_val ipair_t
#define i_cmp ipair_compare
+#define i_tag ip
#include <stc/cvec.h>
-#define i_tag ip
#define i_val ipair_t
#define i_cmp ipair_compare
+#define i_tag ip
#include <stc/clist.h>
-#define i_tag f
#define i_val float
+#define i_tag f
#include <stc/cpque.h>
int main(void)
diff --git a/examples/list.c b/examples/list.c
index 94ee091f..30923e8b 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -2,8 +2,8 @@
#include <time.h>
#include <stc/crandom.h>
-#define i_tag fx
#define i_val double
+#define i_tag fx
#include <stc/clist.h>
int main() {
diff --git a/examples/list_erase.c b/examples/list_erase.c
index db05fb42..c1e5ab61 100644
--- a/examples/list_erase.c
+++ b/examples/list_erase.c
@@ -1,8 +1,8 @@
// erasing from clist
#include <stdio.h>
-#define i_tag i
#define i_val int
+#define i_tag i
#include <stc/clist.h>
int main ()
diff --git a/examples/list_splice.c b/examples/list_splice.c
index 425a344a..517cbcce 100644
--- a/examples/list_splice.c
+++ b/examples/list_splice.c
@@ -1,7 +1,7 @@
#include <stdio.h>
-#define i_tag i
#define i_val int
+#define i_tag i
#include <stc/clist.h>
void print_ilist(const char* s, clist_i list)
diff --git a/examples/mapmap.c b/examples/mapmap.c
index d24c4748..44cf7da5 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -8,10 +8,10 @@
#define i_val_str
#include <stc/cmap.h>
-#define i_tag cfg
#define i_key_str
#define i_val cmap_str
#define i_valdel cmap_str_del
+#define i_tag cfg
#include <stc/cmap.h>
int main(void)
diff --git a/examples/mmap.c b/examples/mmap.c
index ad2e28c8..2defbd96 100644
--- a/examples/mmap.c
+++ b/examples/mmap.c
@@ -6,11 +6,11 @@
#define i_val_str
#include <stc/clist.h>
-#define i_tag mult
#define i_key int
#define i_val clist_str
-#define i_valdel clist_str_del
#define i_cmp -c_default_compare
+#define i_valdel clist_str_del
+#define i_tag mult
#include <stc/csmap.h>
void print(const csmap_mult mmap)
diff --git a/examples/multimap.c b/examples/multimap.c
index 64e3493b..3dbe952d 100644
--- a/examples/multimap.c
+++ b/examples/multimap.c
@@ -43,17 +43,17 @@ void OlympicLocation_del(OlympicLocation* self) {
}
// Create a clist<OlympicLocation>, can be sorted by year.
-#define i_tag OL
#define i_val OlympicLocation
-#define i_valdel OlympicLocation_del
#define i_cmp OlympicLocation_compare
+#define i_del OlympicLocation_del
+#define i_tag OL
#include <stc/clist.h>
// Create a csmap<cstr, clist_OL> where key is country name
-#define i_tag OL
#define i_key_str
#define i_val clist_OL
#define i_valdel clist_OL_del
+#define i_tag OL
#include <stc/csmap.h>
int main()
diff --git a/examples/new_deq.c b/examples/new_deq.c
index 58ca7722..7d30343f 100644
--- a/examples/new_deq.c
+++ b/examples/new_deq.c
@@ -10,9 +10,9 @@ struct MyStruct {
} typedef MyStruct;
+#define i_val int
#define i_fwd
#define i_tag i32
-#define i_val int
#include <stc/cdeq.h>
struct Point { int x, y; } typedef Point;
@@ -21,10 +21,10 @@ int point_compare(const Point* a, const Point* b) {
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd
-#define i_tag pnt
#define i_val Point
#define i_cmp point_compare
+#define i_fwd
+#define i_tag pnt
#include <stc/cdeq.h>
#define i_val float
diff --git a/examples/new_list.c b/examples/new_list.c
index 879f26aa..4d2328be 100644
--- a/examples/new_list.c
+++ b/examples/new_list.c
@@ -9,9 +9,9 @@ struct MyStruct {
clist_pnt pntlst;
} typedef MyStruct;
+#define i_val int
#define i_fwd
#define i_tag i32
-#define i_val int
#include <stc/clist.h>
struct Point { int x, y; } typedef Point;
@@ -20,10 +20,10 @@ int point_compare(const Point* a, const Point* b) {
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd
-#define i_tag pnt
#define i_val Point
#define i_cmp point_compare
+#define i_fwd
+#define i_tag pnt
#include <stc/clist.h>
#define i_val float
diff --git a/examples/new_map.c b/examples/new_map.c
index 297e9be7..7ed192a3 100644
--- a/examples/new_map.c
+++ b/examples/new_map.c
@@ -20,11 +20,11 @@ int point_compare(const Point* a, const Point* b) {
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd // forward declared
-#define i_tag pnt
#define i_key Point
#define i_val int
#define i_cmp point_compare
+#define i_fwd // forward declared
+#define i_tag pnt
#include <stc/cmap.h>
// int => int map
diff --git a/examples/new_pque.c b/examples/new_pque.c
index 08962e1f..8335e46e 100644
--- a/examples/new_pque.c
+++ b/examples/new_pque.c
@@ -20,10 +20,10 @@ int Point_cmp(const Point* a, const Point* b) {
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd // forward declared.
-#define i_tag pnt
#define i_val Point
#define i_cmp Point_cmp
+#define i_fwd // forward declared.
+#define i_tag pnt
#include <stc/cpque.h>
#include <stdio.h>
diff --git a/examples/new_queue.c b/examples/new_queue.c
index 6e62abe6..53a5b341 100644
--- a/examples/new_queue.c
+++ b/examples/new_queue.c
@@ -1,6 +1,7 @@
#include <stc/crandom.h>
#include <stc/forward.h>
#include <stdio.h>
+#include <time.h>
forward_cqueue(cqueue_pnt, struct Point);
@@ -9,14 +10,14 @@ int point_compare(const Point* a, const Point* b) {
int c = c_default_compare(&a->x, &b->x);
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define F_tag pnt
#define i_val Point
#define i_cmp point_compare
+#define i_fwd
+#define i_tag pnt
#include <stc/cqueue.h>
#define i_val int
#include <stc/cqueue.h>
-#include <time.h>
int main() {
int n = 60000000;
diff --git a/examples/new_smap.c b/examples/new_smap.c
index bbaa3dd1..1c84a961 100644
--- a/examples/new_smap.c
+++ b/examples/new_smap.c
@@ -20,11 +20,11 @@ int point_compare(const Point* a, const Point* b) {
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd
-#define i_tag pnt
#define i_key Point
#define i_val int
#define i_cmp point_compare
+#define i_fwd
+#define i_tag pnt
#include <stc/csmap.h>
// int => int map
diff --git a/examples/new_sptr.c b/examples/new_sptr.c
index e4ed5e89..25eb6702 100644
--- a/examples/new_sptr.c
+++ b/examples/new_sptr.c
@@ -10,10 +10,10 @@ void Person_del(Person* p) {
c_del(cstr, &p->name, &p->last);
}
-#define i_tag person
#define i_val Person
#define i_del Person_del
#define i_cmp c_no_compare
+#define i_tag person
#include <stc/csptr.h>
// ...
@@ -21,8 +21,8 @@ void Person_del(Person* p) {
#define i_val int
#include <stc/csptr.h>
-#define i_tag iptr
#define i_key_csptr csptr_int
+#define i_tag iptr
#include <stc/csset.h>
int main(void) {
diff --git a/examples/new_vec.c b/examples/new_vec.c
index 34029168..5460789a 100644
--- a/examples/new_vec.c
+++ b/examples/new_vec.c
@@ -20,10 +20,10 @@ int point_compare(const Point* a, const Point* b) {
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd pnt
-#define i_tag pnt
#define i_val Point
#define i_cmp point_compare
+#define i_fwd pnt
+#define i_tag pnt
#include <stc/cvec.h>
#define i_val float
diff --git a/examples/priority.c b/examples/priority.c
index 03bd1a03..1068cb91 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -3,9 +3,9 @@
#include <time.h>
#include <stc/crandom.h>
-#define i_tag i
#define i_val int64_t
#define i_cmp -c_default_compare // min-heap (increasing values)
+#define i_tag i
#include <stc/cpque.h>
int main() {
diff --git a/examples/queue.c b/examples/queue.c
index 602e9f0f..2c2052e5 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -1,8 +1,8 @@
#include <stc/crandom.h>
#include <stdio.h>
-#define i_tag i
#define i_val int
+#define i_tag i
#include <stc/cqueue.h>
int main() {
diff --git a/examples/replace.c b/examples/replace.c
index 9e658922..ebb40cc5 100644
--- a/examples/replace.c
+++ b/examples/replace.c
@@ -13,7 +13,7 @@ int main ()
// Ustring positions: 0123456789*123456789*12345
cstr s = cstr_from(base); // "this is a test string."
cstr m = cstr_clone(s);
- c_autoscope (0, cstr_del(&s), cstr_del(&m)) {
+ c_autodefer (cstr_del(&s), cstr_del(&m)) {
cstr_append(&m, m.str);
cstr_append(&m, m.str);
printf("%s\n", m.str);
diff --git a/examples/stack.c b/examples/stack.c
index 7da3063a..54d5aeed 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -13,7 +13,7 @@
int main() {
cstack_i stack = cstack_i_init();
cstack_c chars = cstack_c_init();
- c_autoscope (0, cstack_i_del(&stack), cstack_c_del(&chars))
+ c_autodefer (cstack_i_del(&stack), cstack_c_del(&chars))
{
c_forrange (i, int, 101)
cstack_i_push(&stack, i*i);