diff options
| author | Tyge Løvset <[email protected]> | 2021-04-29 19:33:15 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-04-29 22:06:12 +0200 |
| commit | 13f25229cfa7a3ec2215656c29783df7c63c7164 (patch) | |
| tree | 6451e448af5194a216d69dc2007ec2f173afceb7 /examples | |
| parent | 1faeef377e0298df3e6d765c08c2eeb02f45757a (diff) | |
| download | STC-modified-13f25229cfa7a3ec2215656c29783df7c63c7164.tar.gz STC-modified-13f25229cfa7a3ec2215656c29783df7c63c7164.zip | |
Added new constructors to carray.h. Made cmap and csmap keys immutable. Added get() method to cmap and csmap.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/complex.c | 2 | ||||
| -rw-r--r-- | examples/demos.c | 22 | ||||
| -rw-r--r-- | examples/ex_gauss1.c | 8 |
4 files changed, 18 insertions, 16 deletions
diff --git a/examples/advanced.c b/examples/advanced.c index 795f3f63..84e148ac 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -30,7 +30,7 @@ static inline int vikingraw_equals(const VikingRaw* rx, const VikingRaw* ry) { static inline Viking viking_fromRaw(VikingRaw raw) { // note: parameter is by value Viking vk = {cstr_from(raw.name), cstr_from(raw.country)}; return vk; } -static inline VikingRaw viking_toRaw(Viking* vk) { +static inline VikingRaw viking_toRaw(const Viking* vk) { VikingRaw raw = {vk->name.str, vk->country.str}; return raw; } diff --git a/examples/complex.c b/examples/complex.c index 32bbd057..eea92dbd 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -22,7 +22,7 @@ int main() { cmap_map myMap = cmap_map_init();
cmap_lst listMap = cmap_lst_init();
clist_arr tableList = clist_arr_init();
- carray2f arr2 = carray2f_init(xdim, ydim, 1.f);
+ carray2f arr2 = carray2f_with_value(xdim, ydim, 1.f);
printf("arr2 size: %zu x %zu\n", arr2.xdim, arr2.ydim);
diff --git a/examples/demos.c b/examples/demos.c index 286c2e79..3502f5f1 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -184,23 +184,23 @@ using_carray3(f, float); void arraydemo1()
{
printf("\nARRAYDEMO1\n");
- carray3f a3 = carray3f_init(30, 20, 10, 0.0f);
- a3.data[5][4][3] = 10.2f;
- float **a2 = a3.data[5];
- float *a1 = a3.data[5][4];
+ carray3f arr3 = carray3f_with_value(30, 20, 10, 0.0f);
+ arr3.data[5][4][3] = 10.2f;
+ float **arr2 = arr3.data[5];
+ float *arr1 = arr3.data[5][4];
- printf("a3: %zu: (%zu, %zu, %zu) = %zu\n", sizeof(a3), a3.xdim, a3.ydim, a3.zdim, carray3f_size(a3));
+ printf("arr3: %zu: (%zu, %zu, %zu) = %zu\n", sizeof(arr3), arr3.xdim, arr3.ydim, arr3.zdim, carray3f_size(arr3));
- printf("%g\n", a1[3]); // = 10.2
- printf("%g\n", a2[4][3]); // = 10.2
- printf("%g\n", a3.data[5][4][3]); // = 10.2
+ printf("%g\n", arr1[3]); // = 10.2
+ printf("%g\n", arr2[4][3]); // = 10.2
+ printf("%g\n", arr3.data[5][4][3]); // = 10.2
float x = 0.0;
- c_foreach (i, carray3f, a3)
+ c_foreach (i, carray3f, arr3)
*i.ref = ++x;
- printf("%g\n", a3.data[29][19][9]); // = 6000
+ printf("%g\n", arr3.data[29][19][9]); // = 6000
- carray3f_del(&a3);
+ carray3f_del(&arr3);
}
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c index 99d17b23..75b96482 100644 --- a/examples/ex_gauss1.c +++ b/examples/ex_gauss1.c @@ -10,10 +10,12 @@ using_cmap(i, int, size_t);
// Declare int vector with map entries that can be sorted by map keys.
-static int compare(cmap_i_value_t *a, cmap_i_value_t *b) {
+struct mapval {int first; size_t second;};
+static int compare(struct mapval *a, struct mapval *b) {
return c_default_compare(&a->first, &b->first);
}
-using_cvec(e, cmap_i_value_t, compare);
+
+using_cvec(e, struct mapval, compare);
int main()
{
@@ -37,7 +39,7 @@ int main() // Transfer map to vec and sort it by map keys.
cvec_e vhist = cvec_e_init();
c_foreach (i, cmap_i, mhist)
- cvec_e_push_back(&vhist, *i.ref);
+ cvec_e_push_back(&vhist, (struct mapval){i.ref->first, i.ref->second});
cvec_e_sort(&vhist);
// Print the gaussian bar chart
|
