diff options
| -rw-r--r-- | examples/demos.c | 17 | ||||
| -rw-r--r-- | stc/cbitset.h | 32 | ||||
| -rw-r--r-- | 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; i<n; ++i) \
- if ((s._arr[i] op other._arr[i]) != s._arr[i]) \
+ if ((s._arr[i] OPR other._arr[i]) != s._arr[i]) \
return false; \
uint64_t m = (1ull << (s.size & 63)) - 1, last = s._arr[n] & m; \
- return (last op (other._arr[n] & m)) == last
-
-STC_API bool cbitset_is_disjoint(cbitset_t s, cbitset_t other) {
- _cbitset_SETOP(^);
-}
-
-STC_API bool cbitset_is_subset(cbitset_t s, cbitset_t other) {
- _cbitset_SETOP(|);
-}
-
-STC_API bool cbitset_is_superset(cbitset_t s, cbitset_t other) {
- _cbitset_SETOP(&);
-}
+ return (last OPR (other._arr[n] & m)) == last
+STC_API bool cbitset_is_disjoint(cbitset_t s, cbitset_t other) { _cbitset_SETOP(^); }
+STC_API bool cbitset_is_subset(cbitset_t s, cbitset_t other) { _cbitset_SETOP(|); }
+STC_API bool cbitset_is_superset(cbitset_t s, cbitset_t other) { _cbitset_SETOP(&); }
#endif
-
#endif
\ No newline at end of file @@ -176,8 +176,8 @@ cstr_equals_s(cstr_t s1, cstr_t s2) { return strcmp(s1.str, s2.str) == 0;
}
STC_INLINE int
-cstr_compare(const void* s1, const void* s2) {
- return strcmp(((const cstr_t*)s1)->str, ((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) {
|
