summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTylo <[email protected]>2020-06-25 11:15:54 +0200
committerTylo <[email protected]>2020-06-25 11:15:54 +0200
commit3e0e248a229d416a9c02fbb676ec86b5e72af99f (patch)
tree674bc19cbad6538516ca07ff20074710ae3715c9 /examples
parentb32ea825a1e79679c600d50d7530c6fdda96a87c (diff)
downloadSTC-modified-3e0e248a229d416a9c02fbb676ec86b5e72af99f.tar.gz
STC-modified-3e0e248a229d416a9c02fbb676ec86b5e72af99f.zip
Added carrayN_makeFrom(..., array, own) to create from a externally created C array. A few fixes.
Diffstat (limited to 'examples')
-rw-r--r--examples/complex.c21
-rw-r--r--examples/demos.c4
2 files changed, 13 insertions, 12 deletions
diff --git a/examples/complex.c b/examples/complex.c
index 3fb0f0a1..91a1d4c2 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -12,11 +12,12 @@ declare_CHash_string(sm, MAP, CHash_il, chash_il_destroy);
int main() {
int xdim = 4, ydim = 6;
- int x = 1, y = 5, entry = 42;
+ int x = 1, y = 5, tableKey = 42;
+ const char* strKey = "first";
CHash_sm theMap = chash_init;
- {
- // Construct.
- CArray2_f table = carray2_f_make(ydim, xdim, 0.f);
+
+ { // Construct.
+ CArray2_f table = carray2_f_make(ydim, xdim, -0.f);
printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table));
CList_t2 tableList = clist_init;
CHash_il listMap = chash_init;
@@ -24,13 +25,13 @@ int main() {
// Put in some data.
carray2_f_data(table, y)[x] = 3.1415927; // table[x][y]
clist_t2_pushBack(&tableList, table);
- chash_il_put(&listMap, entry, tableList);
- chash_sm_put(&theMap, "First", listMap);
+ chash_il_put(&listMap, tableKey, tableList);
+ chash_sm_put(&theMap, strKey, listMap);
+ }
+ { // Access the data entry
+ CArray2_f table = clist_back(chash_il_get(&chash_sm_get(&theMap, strKey)->value, tableKey)->value);
+ printf("value (%d, %d) is: %f\n", y, x, carray2_f_value(table, y, x));
}
-
- // Access the data entry
- CArray2_f table = clist_back(chash_il_get(&chash_sm_get(&theMap, "First")->value, entry)->value);
- printf("value (%d, %d) is: %f\n", y, x, carray2_f_value(table, y, x));
chash_sm_destroy(&theMap); // free up the whole shebang!
} \ No newline at end of file
diff --git a/examples/demos.c b/examples/demos.c
index e8530b90..ea8607db 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -179,8 +179,8 @@ void arraydemo1()
carray3_f_data(a3, 5, 4)[3] = 10.2f; // a3[5][4][3]
CArray2_f a2 = carray3_f_at(a3, 5); // sub-array reference (no data copy).
- printf("a3: %zu: (%zu, %zu, %zu) = %zu\n", sizeof(a3), carray_xdim(a3), carray_ydim(a3), carray_zdim(a3), carray3_size(a3));
- printf("a2: %zu: (%zu, %zu) = %zu\n", sizeof(a2), carray_xdim(a2), carray_ydim(a2), carray2_size(a2));
+ printf("a3: %zu: (%zu, %zu, %zu) = %zu\n", sizeof(a3), carray3_xdim(a3), carray3_ydim(a3), carray3_zdim(a3), carray3_size(a3));
+ printf("a2: %zu: (%zu, %zu) = %zu\n", sizeof(a2), carray2_xdim(a2), carray2_ydim(a2), carray2_size(a2));
printf("%f\n", carray2_f_value(a2, 4, 3)); // readonly lookup a2[4][3] (=10.2f)
printf("%f\n", carray2_f_data(a2, 4)[3]); // same, but this is writable.