diff options
| author | Tyge Løvset <[email protected]> | 2020-07-16 17:17:24 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-07-16 17:17:24 +0200 |
| commit | 5f004f4f91b4a383005c763ea925cf655ba2d7c2 (patch) | |
| tree | 9a4d9162edc37f897f07a82ee15f9adf90a39827 /examples | |
| parent | 1d8b2adc084d684b90ec525e342b7a3a159a0474 (diff) | |
| download | STC-modified-5f004f4f91b4a383005c763ea925cf655ba2d7c2.tar.gz STC-modified-5f004f4f91b4a383005c763ea925cf655ba2d7c2.zip | |
CHanged API: Renamed CString to CStr and CVector to CVec. All function names are changed likewise.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/README.md | 12 | ||||
| -rw-r--r-- | examples/advanced.c | 10 | ||||
| -rw-r--r-- | examples/complex.c | 2 | ||||
| -rw-r--r-- | examples/demos.c | 62 |
4 files changed, 43 insertions, 43 deletions
diff --git a/examples/README.md b/examples/README.md index 3658076c..b77fb94e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -13,7 +13,7 @@ This demonstrates how to customize **CHash map** with a user-defined key-type. Y 2. A comparison function for equality;
When your key type consists of several members, you will usually have the hash function calculate hash values for the individual members, and then somehow combine them into one hash value for the entire object.
-If your key-type stores dynamic memory (e.g. CString as we will use), it is smart to define a plain-old-data "view" of the your key struct first:
+If your key-type stores dynamic memory (e.g. CStr as we will use), it is smart to define a plain-old-data "view" of the your key struct first:
```
#include <stdio.h>
#include <stc/chash.h>
@@ -40,21 +40,21 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) { And then the Viking data struct:
```
typedef struct Viking {
- CString name;
- CString country;
+ CStr name;
+ CStr country;
} Viking;
void viking_destroy(Viking* vk) {
- cstring_destroy(&vk->name);
- cstring_destroy(&vk->country);
+ cstr_destroy(&vk->name);
+ cstr_destroy(&vk->country);
}
VikingVw viking_getVw(Viking* vk) {
VikingVw vw = {vk->name.str, vk->country.str}; return vw;
}
Viking viking_fromVw(VikingVw vw) {
- Viking vk = {cstring_make(vw.name), cstring_make(vw.country)}; return vk;
+ Viking vk = {cstr_make(vw.name), cstr_make(vw.country)}; return vk;
}
```
diff --git a/examples/advanced.c b/examples/advanced.c index cd86b21d..e8b62fe2 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -34,21 +34,21 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) { // Viking data struct ----------------------- typedef struct Viking { - CString name; - CString country; + CStr name; + CStr country; } Viking; void viking_destroy(Viking* vk) { - cstring_destroy(&vk->name); - cstring_destroy(&vk->country); + cstr_destroy(&vk->name); + cstr_destroy(&vk->country); } VikingVw viking_getVw(Viking* vk) { VikingVw vw = {vk->name.str, vk->country.str}; return vw; } Viking viking_fromVw(VikingVw vw) { - Viking vk = {cstring_make(vw.name), cstring_make(vw.country)}; return vk; + Viking vk = {cstr_make(vw.name), cstr_make(vw.country)}; return vk; } diff --git a/examples/complex.c b/examples/complex.c index 8c44f6cc..3ecf6a1f 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -8,7 +8,7 @@ void check_destroy(float* v) {printf("destroy %g\n", *v);} declare_CArray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
declare_CList(t2, CArray2_f, carray2_f_destroy, c_noCompare);
declare_CHash(il, int, CList_t2, clist_t2_destroy);
-declare_CHash_string(sm, CHash_il, chash_il_destroy);
+declare_CHash_str(sm, CHash_il, chash_il_destroy);
int main() {
int xdim = 4, ydim = 6;
diff --git a/examples/demos.c b/examples/demos.c index 2705257b..20ecd3a0 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -8,68 +8,68 @@ void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- CString cs = cstring_make("one-nine-three-seven-five");
+ CStr cs = cstr_make("one-nine-three-seven-five");
printf("%s.\n", cs.str);
- cstring_insert(&cs, 3, "-two");
+ cstr_insert(&cs, 3, "-two");
printf("%s.\n", cs.str);
- cstring_erase(&cs, 7, 5); // -nine
+ cstr_erase(&cs, 7, 5); // -nine
printf("%s.\n", cs.str);
- cstring_replace(&cs, 0, "seven", "four");
+ cstr_replace(&cs, 0, "seven", "four");
printf("%s.\n", cs.str);
- cstring_take(&cs, cstring_makeFmt("%s *** %s", cs.str, cs.str));
+ cstr_take(&cs, cstr_makeFmt("%s *** %s", cs.str, cs.str));
printf("%s.\n", cs.str);
- printf("find: %s\n", cs.str + cstring_find(cs, 0, "four"));
+ printf("find: %s\n", cs.str + cstr_find(cs, 0, "four"));
// reassign:
- cstring_assign(&cs, "one two three four five six seven");
- cstring_append(&cs, " eight");
+ cstr_assign(&cs, "one two three four five six seven");
+ cstr_append(&cs, " eight");
printf("append: %s\n", cs.str);
- cstring_destroy(&cs);
+ cstr_destroy(&cs);
}
-declare_CVector(ix, int64_t); // ix is just an example tag name.
+declare_CVec(ix, int64_t); // ix is just an example tag name.
void vectordemo1()
{
printf("\nVECTORDEMO1\n");
- CVector_ix bignums = cvector_init; // = (CVector_ix) cvector_init; if initializing after declaration.
- cvector_ix_reserve(&bignums, 100);
+ CVec_ix bignums = cvec_init; // = (CVec_ix) cvec_init; if initializing after declaration.
+ cvec_ix_reserve(&bignums, 100);
for (size_t i = 0; i<=100; ++i)
- cvector_ix_pushBack(&bignums, i * i * i);
+ cvec_ix_pushBack(&bignums, i * i * i);
printf("erase - %d: %zu\n", 100, bignums.data[100]);
- cvector_ix_popBack(&bignums); // erase the last
+ cvec_ix_popBack(&bignums); // erase the last
- for (size_t i = 0; i < cvector_size(bignums); ++i) {
+ for (size_t i = 0; i < cvec_size(bignums); ++i) {
if (i >= 90) printf("%zu: %zu\n", i, bignums.data[i]);
}
- cvector_ix_destroy(&bignums);
+ cvec_ix_destroy(&bignums);
}
-declare_CVector(cs, CString, cstring_destroy, cstring_compare); // supply inline destructor of values
+declare_CVec(cs, CStr, cstr_destroy, cstr_compare); // supply inline destructor of values
void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- CVector_cs names = cvector_init;
- cvector_cs_pushBack(&names, cstring_make("Mary"));
- cvector_cs_pushBack(&names, cstring_make("Joe"));
- cvector_cs_pushBack(&names, cstring_make("Chris"));
- cstring_assign(&names.data[1], "Jane"); // replace Joe
+ CVec_cs names = cvec_init;
+ cvec_cs_pushBack(&names, cstr_make("Mary"));
+ cvec_cs_pushBack(&names, cstr_make("Joe"));
+ cvec_cs_pushBack(&names, cstr_make("Chris"));
+ cstr_assign(&names.data[1], "Jane"); // replace Joe
printf("names[1]: %s\n", names.data[1].str);
- cvector_cs_sort(&names); // Sort the array
- c_foreach (i, cvector_cs, names)
+ cvec_cs_sort(&names); // Sort the array
+ c_foreach (i, cvec_cs, names)
printf("sorted: %s\n", i.item->str);
- cvector_cs_destroy(&names);
+ cvec_cs_destroy(&names);
}
declare_CList(ix, int);
@@ -128,7 +128,7 @@ void mapdemo1() }
-declare_CHash_string(si, int); // Shorthand macro for the general declare_CHash expansion.
+declare_CHash_str(si, int); // Shorthand macro for the general declare_CHash expansion.
void mapdemo2()
{
@@ -150,15 +150,15 @@ void mapdemo2() }
-declare_CHash_string(ss, CString, cstring_destroy);
+declare_CHash_str(ss, CStr, cstr_destroy);
void mapdemo3()
{
printf("\nMAPDEMO3\n");
CHash_ss table = chash_init;
- chash_ss_put(&table, "Map", cstring_make("test"));
- chash_ss_put(&table, "Make", cstring_make("my"));
- chash_ss_put(&table, "Sunny", cstring_make("day"));
+ chash_ss_put(&table, "Map", cstr_make("test"));
+ chash_ss_put(&table, "Make", cstr_make("my"));
+ chash_ss_put(&table, "Sunny", cstr_make("day"));
CHashEntry_ss *e = chash_ss_get(&table, "Make");
printf("size %zu: remove: Make: %s\n", chash_size(table), e->value.str);
chash_ss_erase(&table, "Make");
@@ -167,7 +167,7 @@ void mapdemo3() printf("size %zu\n", chash_size(table));
c_foreach (i, chash_ss, table)
printf("entry: %s: %s\n", i.item->key.str, i.item->value.str);
- chash_ss_destroy(&table); // frees key and value CStrings, and hash table (CVector).
+ chash_ss_destroy(&table); // frees key and value CStrs, and hash table (CVec).
}
|
