diff options
Diffstat (limited to 'examples/complex.c')
| -rw-r--r-- | examples/complex.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/examples/complex.c b/examples/complex.c index 3dbf683d..6f665208 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -5,33 +5,33 @@ void check_del(float* v) {printf("destroy %g\n", *v);}
-using_carray(f, float, check_del); // normally omit the last argument - float type need no destroy.
-using_clist(y, carray2f, c_no_compare, carray2f_del);
-using_cmap(g, int, clist_y, clist_y_del);
-using_cmap_strkey(s, cmap_g, cmap_g_del);
+using_carray(f, float, check_del, c_default_clone); // normally omit the last argument - float type need no destroy.
+using_clist(a, carray2f, c_no_compare, carray2f_del);
+using_cmap(l, int, clist_a, clist_a_del, clist_a_clone);
+using_cmap_strkey(s, cmap_l, cmap_l_del, cmap_l_clone);
int main() {
int xdim = 4, ydim = 6;
int x = 1, y = 5, tableKey = 42;
const char* strKey = "first";
+ cmap_l listMap = cmap_inits;
+
cmap_s myMap = cmap_inits;
- { // Construct.
- carray2f table = carray2f_init(ydim, xdim, 0.f);
- printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table));
- clist_y tableList = clist_inits;
- // Put in some data.
- cmap_g listMap = cmap_inits;
-
- *carray2f_at(&table, y, x) = 3.1415927f; // table[y][x]
- clist_y_push_back(&tableList, table);
- cmap_g_put(&listMap, tableKey, tableList);
- cmap_s_put(&myMap, strKey, listMap);
- }
- { // Access the data entry
- carray2f table = *clist_y_back(&cmap_g_find(&cmap_s_find(&myMap, strKey)->second, tableKey)->second);
- printf("value (%d, %d) is: %f\n", y, x, *carray2f_at(&table, y, x));
- }
+ // Construct.
+ carray2f arr_a = carray2f_init(ydim, xdim, 0.f);
+ printf("arr_a: (%zu, %zu)\n", carray2f_ydim(arr_a), carray2f_xdim(arr_a));
+
+ clist_a tableList = clist_inits;
+ // Put in some data.
+ *carray2f_at(&arr_a, y, x) = 3.1415927f; // aa[y][x]
+ clist_a_push_back(&tableList, arr_a);
+ cmap_l_put(&listMap, tableKey, tableList);
+ cmap_s_put(&myMap, strKey, listMap);
+
+ // Access the data entry
+ carray2f arr_b = *clist_a_back(&cmap_l_find(&cmap_s_find(&myMap, strKey)->second, tableKey)->second);
+ printf("value (%d, %d) is: %f\n", y, x, *carray2f_at(&arr_b, y, x));
cmap_s_del(&myMap); // free up everything!
-}
\ No newline at end of file +}
|
