summaryrefslogtreecommitdiffhomepage
path: root/examples/complex.c
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/complex.c
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/complex.c')
-rw-r--r--examples/complex.c21
1 files changed, 11 insertions, 10 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