diff options
| author | Tyge Løvset <[email protected]> | 2020-03-05 00:02:00 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-03-05 00:02:00 +0100 |
| commit | dbeb3f14de419d2e9565f719a6a03a88861feefc (patch) | |
| tree | 2a1eb02200e8af64a6c68a6266722eb42065aa8b | |
| parent | 1ea284cd25615cfa227ea91ee20bfee920086333 (diff) | |
| download | STC-modified-dbeb3f14de419d2e9565f719a6a03a88861feefc.tar.gz STC-modified-dbeb3f14de419d2e9565f719a6a03a88861feefc.zip | |
Update
| -rw-r--r-- | README.md | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -18,9 +18,10 @@ Simple CVector: declare_CVector(ix, int64_t); // ix is just an example tag name, use anything. CVector(ix) bignums = cvector_initializer; // use cvector_ix_init(); if initializing after declaration. -cvector_ix_reserve(&bignums, 1000); -for (int i = 0; i<1000; ++i) - cvector_ix_push(&bignums, i * i); +cvector_ix_reserve(&bignums, 100); +for (int i = 0; i<100; ++i) + cvector_ix_push(&bignums, i * i * i); +cvector_ix_pop(&bignums); // erase the last uint64_t value; for (int i = 0; i < cvector_size(bignums); ++i) @@ -47,21 +48,21 @@ declare_CMap(ii, int, int); CMap(ii) nums = cmap_initializer; cmap_ii_put(&nums, 8, 64); cmap_ii_put(&nums, 11, 121); -printf("%d\n", cmap_ii_get(&nums, 8)->value); +printf("%d\n", cmap_ii_get(nums, 8)->value); cmap_ii_destroy(&nums); ``` Simple CMap with CString keys -> int values ``` #include "cmap.h" declare_CMap_STR(si, int); // Just a shorthand macro for the general declare call. -// Keys strings are managed internally, although CMap is ignorant of CString. +// Keys strings are "magically" managed internally, although CMap is ignorant of CString. CMap(si) nums = cmap_initializer; cmap_si_put(&nums, "Hello", 64); cmap_si_put(&nums, "Groovy", 121); cmap_si_put(&nums, "Groovy", 200); // overwrite previous // iterate the map: -for (CMapIter(si) i = cmap_si_begin(&nums); i.item != cmap_si_end(&nums); i = cmap_si_next(i)) +for (CMapIter(si) i = cmap_si_begin(nums); i.item != cmap_si_end(nums); i = cmap_si_next(i)) printf("%s: %d\n", i.item->key.str, i.item->value); cmap_si_destroy(&nums); ``` @@ -73,6 +74,8 @@ declare_CMap_STR(ss, CString, cstring_destroy); CMap(ss) table = cmap_initializer; cmap_ss_put(&table, "Hello", cstring_make("Goodbye")); cmap_ss_put(&table, "Groovy", cstring_make("Shaky")); -printf("%s\n", cmap_ss_get(&table, "Groovy")->value.str); +printf("Groovy: %s\n", cmap_ss_get(table, "Groovy")->value.str); +cmap_ss_erase(&table, "Hello"); +printf("size %d\n", cmap_size(table)); cmap_ss_destroy(&table); // frees key and value CStrings, and hash table (CVector). ``` |
