diff options
| author | tylo <[email protected]> | 2020-08-11 11:29:23 +0200 |
|---|---|---|
| committer | tylo <[email protected]> | 2020-08-11 11:29:23 +0200 |
| commit | 28574b3bd60c5ef07f3c245095b56c8278a98459 (patch) | |
| tree | c3d813cc30b820c076694a1720eb95eba22d95d8 /examples | |
| parent | 8dcebff6e769b80346e452ad0be505fead57cd11 (diff) | |
| download | STC-modified-28574b3bd60c5ef07f3c245095b56c8278a98459.tar.gz STC-modified-28574b3bd60c5ef07f3c245095b56c8278a98459.zip | |
Fixed two bugs: 1) hash16 not to be used for string. 2) cstr_from(): va_copy missed
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/README.md | 3 | ||||
| -rw-r--r-- | examples/advanced.c | 10 | ||||
| -rw-r--r-- | examples/benchmark.c | 6 | ||||
| -rw-r--r-- | examples/demos.c | 1 |
4 files changed, 10 insertions, 10 deletions
diff --git a/examples/README.md b/examples/README.md index 27307372..661f7555 100644 --- a/examples/README.md +++ b/examples/README.md @@ -24,8 +24,7 @@ typedef struct VikingVw { uint32_t vikingvw_hash(const VikingVw* vw, size_t ignore) {
- uint32_t hash = c_default_hash(vw->name, strlen(vw->name))
- ^ c_default_hash(vw->country, strlen(vw->country));
+ uint32_t hash = c_string_hash(vw->name) ^ c_string_hash(w->country);
return hash;
}
static inline int vikingvw_equals(const VikingVw* x, const VikingVw* y) {
diff --git a/examples/advanced.c b/examples/advanced.c index 7162bdc9..03baf5fc 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -22,8 +22,7 @@ typedef struct VikingVw { } VikingVw; uint32_t vikingvw_hash(const VikingVw* vw, size_t ignore) { - uint32_t hash = c_default_hash(vw->name, strlen(vw->name)) - ^ c_default_hash(vw->country, strlen(vw->country)); + uint32_t hash = c_string_hash(vw->name) ^ c_string_hash(vw->country); return hash; } int vikingvw_equals(const VikingVw* x, const VikingVw* y) { @@ -69,10 +68,11 @@ int main() {{"Olaf", "Denmark"}, 24}, {{"Harald", "Iceland"}, 12}, )); - VikingVw look = {"Einar", "Norway"}; - cmap_vk_entry_t *e = cmap_vk_find(&vikings, look); + + VikingVw einar = {"Einar", "Norway"}; + cmap_vk_entry_t *e = cmap_vk_find(&vikings, einar); e->value += 5; // update - cmap_vk_insert(&vikings, look, 0)->value += 5; // again + cmap_vk_insert(&vikings, einar, 0)->value += 5; // again c_foreach (k, cmap_vk, vikings) { printf("%s of %s has %d hp\n", k.item->key.name.str, k.item->key.country.str, k.item->value); diff --git a/examples/benchmark.c b/examples/benchmark.c index 30fb48af..af696692 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) printf("\nRandom keys are in range [0, 2^%d), seed = %zu:\n", rr, seed);
printf("\nUnordered maps: %zu repeats of Insert random key + try to remove a random key:\n", N1);
MAP_TEST1(CMAP, ii)
- //MAP_TEST1(KMAP, ii)
+ MAP_TEST1(KMAP, ii)
#ifdef __cplusplus
MAP_TEST1(UMAP, ii)
MAP_TEST1(BMAP, ii)
@@ -152,7 +152,7 @@ int main(int argc, char* argv[]) printf("\nUnordered maps: Insert %zu index keys, then remove them in same order:\n", N2);
MAP_TEST2(CMAP, ii)
- //MAP_TEST2(KMAP, ii)
+ MAP_TEST2(KMAP, ii)
#ifdef __cplusplus
MAP_TEST2(UMAP, ii)
MAP_TEST2(BMAP, ii)
@@ -162,7 +162,7 @@ int main(int argc, char* argv[]) printf("\nUnordered maps: Insert %zu random keys, then remove them in same order:\n", N3);
MAP_TEST3(CMAP, ii)
- //MAP_TEST3(KMAP, ii)
+ MAP_TEST3(KMAP, ii)
#ifdef __cplusplus
MAP_TEST3(UMAP, ii)
MAP_TEST3(BMAP, ii)
diff --git a/examples/demos.c b/examples/demos.c index 47ba52aa..f8feb346 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -19,6 +19,7 @@ void stringdemo1() cstr_replace(&cs, cstr_find(cs, "seven", 0), 5, "four");
printf("%s.\n", cs.str);
+
cstr_take(&cs, cstr_from("%s *** %s", cs.str, cs.str));
printf("%s.\n", cs.str);
|
