From 67c15a839caa8d5abb6d8fa637c37c45dd0e69ff Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sat, 8 Aug 2020 18:57:21 +0200 Subject: Minor tweaks. --- examples/demos.c | 17 +++++++++-------- stc/cbitset.h | 32 ++++++++++---------------------- stc/cstr.h | 4 ++-- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/examples/demos.c b/examples/demos.c index a3a587ec..458806c3 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -54,22 +54,23 @@ void vectordemo1() -declare_cvec(cs, cstr_t, cstr_destroy, cstr_compare); // supply inline destructor of values +//declare_cvec(cs, cstr_t, cstr_destroy, cstr_compare); // supply inline destructor of values +declare_cvec_str(); // supply inline destructor of values void vectordemo2() { printf("\nVECTORDEMO2\n"); - cvec_cs names = cvec_init; - cvec_cs_push_back(&names, cstr_make("Mary")); - cvec_cs_push_back(&names, cstr_make("Joe")); - cvec_cs_push_back(&names, cstr_make("Chris")); + cvec_str names = cvec_init; + cvec_str_push_back(&names, cstr_make("Mary")); + cvec_str_push_back(&names, cstr_make("Joe")); + cvec_str_push_back(&names, cstr_make("Chris")); cstr_assign(&names.data[1], "Jane"); // replace Joe printf("names[1]: %s\n", names.data[1].str); - cvec_cs_sort(&names); // Sort the array - c_foreach (i, cvec_cs, names) + cvec_str_sort(&names); // Sort the array + c_foreach (i, cvec_str, names) printf("sorted: %s\n", i.item->str); - cvec_cs_destroy(&names); + cvec_str_destroy(&names); } declare_clist(ix, int); diff --git a/stc/cbitset.h b/stc/cbitset.h index 7e37ce3b..e021281c 100644 --- a/stc/cbitset.h +++ b/stc/cbitset.h @@ -171,12 +171,10 @@ STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value) { #else /* http://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation */ static inline uint64_t c_popcount64(uint64_t x) { - const uint64_t m1 = 0x5555555555555555, m2 = 0x3333333333333333, - m4 = 0x0f0f0f0f0f0f0f0f, h01 = 0x0101010101010101; - x -= (x >> 1) & m1; - x = (x & m2) + ((x >> 2) & m2); - x = (x + (x >> 4)) & m4; - return (x * h01) >> 56; + x -= (x >> 1) & 0x5555555555555555; + x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); + x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f; + return (x * 0x0101010101010101) >> 56; } #endif @@ -189,28 +187,18 @@ STC_API size_t cbitset_count(cbitset_t s) { return count; } -#define _cbitset_SETOP(op) \ +#define _cbitset_SETOP(OPR) \ if (s.size == 0) return false; /* ? */ \ size_t n = ((s.size + 63) >> 6) - 1; \ for (size_t i=0; istr, ((const cstr_t*)s2)->str); +cstr_compare(const cstr_t *s1, const cstr_t *s2) { + return strcmp(s1->str, s2->str); } STC_INLINE size_t cstr_find_n(cstr_t s, const char* needle, size_t pos, size_t n) { -- cgit v1.2.3