diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | examples/bits.c | 12 | ||||
| -rw-r--r-- | examples/csmap_insert.c | 14 | ||||
| -rw-r--r-- | examples/sso_map.c | 4 | ||||
| -rw-r--r-- | examples/sso_substr.c | 22 | ||||
| -rw-r--r-- | include/stc/alt/cstr.h | 162 | ||||
| -rw-r--r-- | include/stc/cbits.h | 30 | ||||
| -rw-r--r-- | include/stc/forward.h | 2 |
8 files changed, 124 insertions, 126 deletions
@@ -316,11 +316,11 @@ container. `i_valfrom/i_valfrom` are defined, the **emplace** functions are *not* available (or needed), as it can easier lead to mistakes. -| non-emplace: Move | emplace: Clone | Container | +| non-emplace: Move | emplace: Embedded copy | Container | |:--------------------------|:-----------------------------|:--------------------------------------------| | insert() | emplace() | cmap, csmap, cset, csset, cdeq, clist, cvec | | insert_or_assign(), put() | emplace_or_assign() | cmap, csmap | -| push() | emplace() | cqueue, cpque, cstack | +| push() | emplace() | cqueue, cpque, cstack, cdeq, cvec | | push_back() | emplace_back() | cdeq, clist, cvec | | push_front() | emplace_front() | cdeq, clist | diff --git a/examples/bits.c b/examples/bits.c index 9fdf1d5d..680b3501 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -17,7 +17,7 @@ int main() printf(" str: %s\n", cbits_to_str(set, str, 0, -1));
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
@@ -27,12 +27,12 @@ int main() cbits_resize(&set, 102, true);
cbits_set_value(&set, 99, false);
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("\nIterate:");
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
@@ -42,19 +42,19 @@ int main() cbits_set(&s2, 17);
cbits_set(&s2, 18);
printf(" new: ");
- c_forrange (i, int, s2.size)
+ c_forrange (i, s2.size)
printf("%d", cbits_test(s2, i));
puts("");
printf(" xor: ");
cbits_xor(&set, s2);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
cbits_set_all(&set, false);
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
}
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index 2a69a8f7..11217de5 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -71,13 +71,16 @@ int main() cvec_ii_push_back(&v, (ipair){44, 311});
puts("Inserting the following vector data into m2:");
- c_foreach (e, cvec_ii, v) printf("(%d, %d) ", e.ref->first, e.ref->second);
+ c_foreach (e, cvec_ii, v)
+ printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("");
- c_foreach (e, cvec_ii, v) csmap_ii_put(&m2, e.ref->first, e.ref->second);
+ c_foreach (e, cvec_ii, v)
+ csmap_ii_insert_or_assign(&m2, e.ref->first, e.ref->second);
puts("The modified key and mapped values of m2 are:");
- c_foreach (e, csmap_ii, m2) printf("(%d, %d) ", e.ref->first, e.ref->second);
+ c_foreach (e, csmap_ii, m2)
+ printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("\n");
}
@@ -99,8 +102,9 @@ int main() c_auto (csmap_ii, m4) {
// Insert the elements from an initializer_list
- c_apply(v, csmap_ii_insert(&m4, c_pair(v)), csmap_ii_raw,
- { { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 } });
+ c_apply(v, csmap_ii_insert(&m4, c_pair(v)), csmap_ii_raw, {
+ { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 }
+ });
puts("After initializer_list insertion, m4 contains:");
print_ii(m4);
puts("");
diff --git a/examples/sso_map.c b/examples/sso_map.c index 6022572f..a70722f7 100644 --- a/examples/sso_map.c +++ b/examples/sso_map.c @@ -1,5 +1,5 @@ -#include <stc/alt/cstr.h>
-
+#define STC_USE_SSO 1
+#include <stc/cstr.h>
#define i_key_str
#define i_val_str
#include <stc/cmap.h>
diff --git a/examples/sso_substr.c b/examples/sso_substr.c new file mode 100644 index 00000000..60fb9997 --- /dev/null +++ b/examples/sso_substr.c @@ -0,0 +1,22 @@ +#define STC_USE_SSO 1 +#include <stc/cstr.h> +#include <stc/csview.h> + +int main () +{ + cstr str = cstr_new("We think in generalities, but we live in details."); + csview sv1 = cstr_substr(&str, 3, 5); // "think" + size_t pos = cstr_find(str, "live"); // position of "live" + csview sv2 = cstr_substr(&str, pos, 4); // "live" + csview sv3 = cstr_slice(&str, -8, -1); // "details" + printf(c_PRIsv ", " c_PRIsv ", " c_PRIsv "\n", + c_ARGsv(sv1), c_ARGsv(sv2), c_ARGsv(sv3)); + + cstr_assign(&str, "apples are green or red"); + cstr s2 = cstr_from_sv(cstr_substr(&str, -3, 3)); // "red" + cstr s3 = cstr_from_sv(cstr_substr(&str, 0, 6)); // "apples" + printf("%s %s: %d, %d\n", cstr_str(&s2), cstr_str(&s3), + cstr_is_long(&str), cstr_is_long(&s2)); + + c_drop (cstr, &str, &s2, &s3); +} diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index 5d84f538..37d6fcb5 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -37,15 +37,11 @@ /**************************** PRIVATE API **********************************/
-enum { SSO_CAP = sizeof(cstr_rep_t) - 1 };
-#define SSO_CALL(s, call) (cstr_is_long(s) ? cstr_l_##call : cstr_s_##call)
-
-#define cstr_is_long(s) ((s)->sso.last > 127)
-#define cstr_s_cap(s) SSO_CAP
-#define cstr_s_size(s) ((size_t)(SSO_CAP - (s)->sso.last))
-#define cstr_s_set_size(s, len) ((s)->sso.last = SSO_CAP - (len), (s)->sso.data[len] = 0)
-#define cstr_s_data(s) (s)->sso.data
-#define cstr_s_end(s) ((s)->sso.data + cstr_s_size(s))
+enum { cstr_s_cap = sizeof(cstr_rep_t) - 1 };
+#define cstr_s_size(s) ((size_t)(cstr_s_cap - (s)->sml.last))
+#define cstr_s_set_size(s, len) ((s)->sml.last = cstr_s_cap - (len), (s)->sml.data[len] = 0)
+#define cstr_s_data(s) (s)->sml.data
+#define cstr_s_end(s) ((s)->sml.data + cstr_s_size(s))
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define byte_rotl_(x, b) ((x) << (b)*8 | (x) >> (sizeof(x) - (b))*8)
@@ -61,18 +57,15 @@ enum { SSO_CAP = sizeof(cstr_rep_t) - 1 }; #define cstr_l_end(s) ((s)->lon.data + cstr_l_size(s))
#define cstr_l_drop(s) c_free((s)->lon.data)
+#define cstr_is_long(s) ((s)->sml.last > 127)
STC_API char* _cstr_init(cstr* self, size_t len, size_t cap);
STC_API char* _cstr_internal_move(cstr* self, size_t pos1, size_t pos2);
-STC_INLINE void _cstr_set_size(cstr* s, size_t len) {
- SSO_CALL(s, set_size(s, len));
-}
-
/**************************** PUBLIC API **********************************/
#define cstr_new(literal) cstr_from_n(literal, c_strlen_lit(literal))
#define cstr_npos (SIZE_MAX >> 1)
-#define cstr_null (c_make(cstr){.sso = {.last = SSO_CAP}})
+#define cstr_null (c_make(cstr){.sml = {.last = cstr_s_cap}})
#define cstr_toraw(self) cstr_str(self)
STC_API char* cstr_reserve(cstr* self, size_t cap);
@@ -89,12 +82,11 @@ STC_API int cstr_printf(cstr* self, const char* fmt, ...); STC_INLINE cstr_rep_t cstr_rep(cstr* s) {
return cstr_is_long(s)
? c_make(cstr_rep_t){s->lon.data, cstr_l_size(s), cstr_l_cap(s)}
- : c_make(cstr_rep_t){s->sso.data, cstr_s_size(s), cstr_s_cap(s)};
+ : c_make(cstr_rep_t){s->sml.data, cstr_s_size(s), cstr_s_cap};
}
-STC_INLINE cstr cstr_init(void) {
- return cstr_null;
-}
+STC_INLINE cstr cstr_init(void)
+ { return cstr_null; }
STC_INLINE cstr cstr_from_n(const char* str, const size_t n) {
cstr s;
@@ -102,9 +94,8 @@ STC_INLINE cstr cstr_from_n(const char* str, const size_t n) { return s;
}
-STC_INLINE cstr cstr_from(const char* str) {
- return cstr_from_n(str, strlen(str));
-}
+STC_INLINE cstr cstr_from(const char* str)
+ { return cstr_from_n(str, strlen(str)); }
STC_INLINE cstr cstr_with_size(const size_t size, const char value) {
cstr s;
@@ -137,7 +128,8 @@ STC_INLINE cstr cstr_clone(cstr s) { }
STC_INLINE void cstr_drop(cstr* self) {
- if (cstr_is_long(self)) cstr_l_drop(self);
+ if (cstr_is_long(self))
+ cstr_l_drop(self);
}
STC_INLINE void cstr_clear(cstr* self) {
@@ -145,62 +137,54 @@ STC_INLINE void cstr_clear(cstr* self) { cstr_s_set_size(self, 0);
}
-STC_INLINE char* cstr_data(cstr* self) {
- return SSO_CALL(self, data(self));
-}
+#define SSO_CALL(s, call) (cstr_is_long(s) ? cstr_l_##call : cstr_s_##call)
-STC_INLINE const char* cstr_str(const cstr* self) {
- return SSO_CALL(self, data(self));
-}
+STC_INLINE void _cstr_set_size(cstr* self, size_t len)
+ { SSO_CALL(self, set_size(self, len)); }
-STC_INLINE bool cstr_empty(cstr s) {
- return SSO_CALL(&s, size(&s)) == 0;
-}
+STC_INLINE char* cstr_data(cstr* self)
+ { return SSO_CALL(self, data(self)); }
-STC_INLINE size_t cstr_size(cstr s) {
- return SSO_CALL(&s, size(&s));
-}
+STC_INLINE const char* cstr_str(const cstr* self)
+ { return SSO_CALL(self, data(self)); }
-STC_INLINE size_t cstr_length(cstr s) {
- return SSO_CALL(&s, size(&s));
-}
+STC_INLINE bool cstr_empty(cstr s)
+ { return s.sml.last == cstr_s_cap; }
-STC_INLINE size_t cstr_capacity(cstr s) {
- return SSO_CALL(&s, cap(&s));
-}
+STC_INLINE size_t cstr_size(cstr s)
+ { return SSO_CALL(&s, size(&s)); }
-STC_INLINE bool cstr_equals(cstr s1, const char* str) {
- return strcmp(cstr_str(&s1), str) == 0;
-}
+STC_INLINE size_t cstr_length(cstr s)
+ { return SSO_CALL(&s, size(&s)); }
-STC_INLINE bool cstr_equals_s(cstr s1, cstr s2) {
- return strcmp(cstr_str(&s1), cstr_str(&s2)) == 0;
-}
+STC_INLINE size_t cstr_capacity(cstr s)
+ { return cstr_is_long(&s) ? cstr_l_cap(&s) : cstr_s_cap; }
-STC_INLINE bool cstr_eq(const cstr* s1, const cstr* s2) {
- return strcmp(cstr_str(s1), cstr_str(s2)) == 0;
-}
+STC_INLINE bool cstr_equals(cstr s1, const char* str)
+ { return strcmp(cstr_str(&s1), str) == 0; }
-STC_INLINE int cstr_cmp(const cstr* s1, const cstr* s2) {
- return strcmp(cstr_str(s1), cstr_str(s2));
-}
+STC_INLINE bool cstr_equals_s(cstr s1, cstr s2)
+ { return strcmp(cstr_str(&s1), cstr_str(&s2)) == 0; }
+
+STC_INLINE bool cstr_eq(const cstr* s1, const cstr* s2)
+ { return strcmp(cstr_str(s1), cstr_str(s2)) == 0; }
+
+STC_INLINE int cstr_cmp(const cstr* s1, const cstr* s2)
+ { return strcmp(cstr_str(s1), cstr_str(s2)); }
STC_INLINE size_t cstr_find(cstr s, const char* needle) {
const char *str = cstr_str(&s), *res = strstr(str, needle);
return res ? res - str : cstr_npos;
}
-STC_INLINE bool cstr_find_s(cstr s, cstr needle) {
- return cstr_find(s, cstr_str(&needle));
-}
+STC_INLINE bool cstr_find_s(cstr s, cstr needle)
+ { return cstr_find(s, cstr_str(&needle)); }
-STC_INLINE bool cstr_contains(cstr s, const char* needle) {
- return strstr(cstr_str(&s), needle) != NULL;
-}
+STC_INLINE bool cstr_contains(cstr s, const char* needle)
+ { return strstr(cstr_str(&s), needle) != NULL; }
-STC_INLINE bool cstr_contains_s(cstr s, cstr needle) {
- return strstr(cstr_str(&s), cstr_str(&needle)) != NULL;
-}
+STC_INLINE bool cstr_contains_s(cstr s, cstr needle)
+ { return strstr(cstr_str(&s), cstr_str(&needle)) != NULL; }
STC_INLINE bool cstr_starts_with(cstr s, const char* sub) {
const char* str = cstr_str(&s);
@@ -208,31 +192,27 @@ STC_INLINE bool cstr_starts_with(cstr s, const char* sub) { return *sub == 0;
}
-STC_INLINE bool cstr_starts_with_s(cstr s, cstr sub) {
- return cstr_starts_with(s, cstr_str(&sub));
-}
+STC_INLINE bool cstr_starts_with_s(cstr s, cstr sub)
+ { return cstr_starts_with(s, cstr_str(&sub)); }
STC_INLINE bool cstr_ends_with(cstr s, const char* sub) {
cstr_rep_t r = cstr_rep(&s); size_t n = strlen(sub);
return n <= r.size && memcmp(r.data + r.size - n, sub, n) == 0;
}
-STC_INLINE bool cstr_ends_with_s(cstr s, cstr sub) {
- return cstr_ends_with(s, cstr_str(&sub));
-}
+STC_INLINE bool cstr_ends_with_s(cstr s, cstr sub)
+ { return cstr_ends_with(s, cstr_str(&sub)); }
-STC_INLINE void cstr_assign(cstr* self, const char* str) {
- cstr_assign_n(self, str, strlen(str));
-}
+STC_INLINE void cstr_assign(cstr* self, const char* str)
+ { cstr_assign_n(self, str, strlen(str)); }
STC_INLINE void cstr_copy(cstr* self, cstr s) {
cstr_rep_t r = cstr_rep(&s);
cstr_assign_n(self, r.data, r.size);
}
-STC_INLINE void cstr_append(cstr* self, const char* str) {
- cstr_append_n(self, str, strlen(str));
-}
+STC_INLINE void cstr_append(cstr* self, const char* str)
+ { cstr_append_n(self, str, strlen(str)); }
STC_INLINE void cstr_append_s(cstr* self, cstr s) {
cstr_rep_t r = cstr_rep(&s);
@@ -244,31 +224,27 @@ STC_INLINE void cstr_replace_n(cstr* self, size_t pos, size_t len, const char* s memcpy(d + pos, str, n);
}
-STC_INLINE void cstr_replace(cstr* self, size_t pos, size_t len, const char* str) {
- cstr_replace_n(self, pos, len, str, strlen(str));
-}
+STC_INLINE void cstr_replace(cstr* self, size_t pos, size_t len, const char* str)
+ { cstr_replace_n(self, pos, len, str, strlen(str)); }
STC_INLINE void cstr_replace_s(cstr* self, size_t pos, size_t len, cstr s) {
cstr_rep_t r = cstr_rep(&s);
cstr_replace_n(self, pos, len, r.data, r.size);
}
-STC_INLINE void cstr_insert_n(cstr* self, size_t pos, const char* str, size_t n) {
- cstr_replace_n(self, pos, 0, str, n);
-}
+STC_INLINE void cstr_insert_n(cstr* self, size_t pos, const char* str, size_t n)
+ { cstr_replace_n(self, pos, 0, str, n); }
-STC_INLINE void cstr_insert(cstr* self, size_t pos, const char* str) {
- cstr_replace_n(self, pos, 0, str, strlen(str));
-}
+STC_INLINE void cstr_insert(cstr* self, size_t pos, const char* str)
+ { cstr_replace_n(self, pos, 0, str, strlen(str)); }
STC_INLINE void cstr_insert_s(cstr* self, size_t pos, cstr s) {
cstr_rep_t r = cstr_rep(&s);
cstr_replace_n(self, pos, 0, r.data, r.size);
}
-STC_INLINE bool cstr_getline(cstr *self, FILE *fp) {
- return cstr_getdelim(self, '\n', fp);
-}
+STC_INLINE bool cstr_getline(cstr *self, FILE *fp)
+ { return cstr_getdelim(self, '\n', fp); }
/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(_i_implement)
@@ -286,25 +262,25 @@ STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t po }
STC_DEF char* _cstr_init(cstr* self, const size_t len, const size_t cap) {
- if (cap > SSO_CAP) {
+ if (cap > cstr_s_cap) {
self->lon.data = (char *)c_malloc(cap + 1);
cstr_l_set_size(self, len);
cstr_l_set_cap(self, cap);
return self->lon.data;
}
cstr_s_set_size(self, len);
- return self->sso.data;
+ return self->sml.data;
}
STC_DEF void cstr_shrink_to_fit(cstr* self) {
cstr_rep_t r = cstr_rep(self);
if (r.size == r.cap)
return;
- if (r.size > SSO_CAP) {
+ if (r.size > cstr_s_cap) {
self->lon.data = (char *)c_realloc(self->lon.data, r.size + 1);
cstr_l_set_cap(self, r.size);
- } else if (r.cap > SSO_CAP) {
- memcpy(self->sso.data, r.data, r.size + 1);
+ } else if (r.cap > cstr_s_cap) {
+ memcpy(self->sml.data, r.data, r.size + 1);
cstr_s_set_size(self, r.size);
c_free(r.data);
}
@@ -319,16 +295,16 @@ STC_DEF char* cstr_reserve(cstr* self, const size_t cap) { return self->lon.data;
}
/* from short to long: */
- if (cap > cstr_s_cap(self)) {
+ if (cap > cstr_s_cap) {
char* data = (char *)c_malloc(cap + 1);
const size_t len = cstr_s_size(self);
- memcpy(data, self->sso.data, len);
+ memcpy(data, self->sml.data, len);
self->lon.data = data;
cstr_l_set_size(self, len);
cstr_l_set_cap(self, cap);
return data;
}
- return self->sso.data;
+ return self->sml.data;
}
STC_DEF void cstr_resize(cstr* self, const size_t size, const char value) {
diff --git a/include/stc/cbits.h b/include/stc/cbits.h index af9336c1..347261d8 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -77,6 +77,8 @@ STC_INLINE void cbits_clear(cbits* self) { self->size = 0; } STC_INLINE void cbits_drop(cbits* self) { c_free(self->data64); }
STC_INLINE size_t cbits_size(cbits set) { return set.size; }
+#define _cbits_bit(i) ((uint64_t)1 << ((i) & 63))
+
#define cbits_new(literal) \
cbits_from_n(literal, c_strlen_lit(literal))
@@ -91,33 +93,27 @@ STC_INLINE cbits cbits_move(cbits* self) { }
STC_INLINE bool cbits_test(cbits set, size_t i) {
- return (set.data64[i >> 6] & (1ull << (i & 63))) != 0;
+ return (set.data64[i >> 6] & _cbits_bit(i)) != 0;
}
STC_INLINE bool cbits_at(cbits set, size_t i) {
- return (set.data64[i >> 6] & (1ull << (i & 63))) != 0;
+ return (set.data64[i >> 6] & _cbits_bit(i)) != 0;
}
STC_INLINE void cbits_set(cbits *self, size_t i) {
- self->data64[i >> 6] |= 1ull << (i & 63);
+ self->data64[i >> 6] |= _cbits_bit(i);
}
STC_INLINE void cbits_reset(cbits *self, size_t i) {
- self->data64[i >> 6] &= ~(1ull << (i & 63));
+ self->data64[i >> 6] &= ~_cbits_bit(i);
}
-#ifdef _MSC_VER
-#pragma warning(disable: 4146) // unary minus operator applied to unsigned type
-#endif
STC_INLINE void cbits_set_value(cbits *self, size_t i, bool value) {
- self->data64[i >> 6] ^= (-(uint64_t)value ^ self->data64[i >> 6]) & 1ull << (i & 63);
+ self->data64[i >> 6] ^= ((uint64_t)-(int)value ^ self->data64[i >> 6]) & _cbits_bit(i);
}
-#ifdef _MSC_VER
-#pragma warning(default: 4146)
-#endif
STC_INLINE void cbits_flip(cbits *self, size_t i) {
- self->data64[i >> 6] ^= 1ull << (i & 63);
+ self->data64[i >> 6] ^= _cbits_bit(i);
}
STC_INLINE void cbits_set_all(cbits *self, bool value) {
@@ -131,7 +127,7 @@ STC_INLINE void cbits_set_values(cbits *self, uint64_t pattern) { STC_INLINE void cbits_flip_all(cbits *self) {
size_t n = (self->size + 63) >> 6;
- for (size_t i=0; i<n; ++i) self->data64[i] ^= ~0ull;
+ for (size_t i=0; i<n; ++i) self->data64[i] ^= ~(uint64_t)0;
}
/* Intersection */
@@ -172,7 +168,7 @@ STC_INLINE void cbits_xor(cbits *self, cbits other) { STC_DEF cbits* cbits_copy(cbits* self, cbits other) {
if (self->data64 == other.data64) return self;
if (self->size != other.size) return cbits_take(self, cbits_clone(other));
- memcpy(self->data64, other.data64, ((other.size + 63) >> 6)*8);
+ memcpy(self->data64, other.data64, ((other.size + 63) >> 6) * 8);
return self;
}
@@ -183,7 +179,7 @@ STC_DEF void cbits_resize(cbits* self, size_t size, bool value) { if (new_n >= old_n) {
memset(self->data64 + old_n, -(int)value, (new_n - old_n) * 8);
if (old_n > 0) {
- uint64_t m = (1ull << (osize & 63)) - 1; /* mask */
+ uint64_t m = _cbits_bit(osize) - 1; /* mask */
value ? (self->data64[old_n - 1] |= ~m) : (self->data64[old_n - 1] &= m);
}
}
@@ -221,7 +217,7 @@ STC_DEF cbits cbits_clone(cbits other) { STC_DEF size_t cbits_count(cbits s) {
size_t count = 0, n = s.size >> 6;
for (size_t i = 0; i < n; ++i) count += cpopcount64(s.data64[i]);
- if (s.size & 63) count += cpopcount64(s.data64[n] & ((1ull << (s.size & 63)) - 1));
+ if (s.size & 63) count += cpopcount64(s.data64[n] & (_cbits_bit(s.size) - 1));
return count;
}
@@ -232,7 +228,7 @@ STC_DEF size_t cbits_count(cbits s) { if ((s.data64[i] OPR other.data64[i]) != x) \
return false; \
if (!(s.size & 63)) return true; \
- uint64_t i = n, m = (1ull << (s.size & 63)) - 1; \
+ uint64_t i = n, m = _cbits_bit(s.size) - 1; \
return ((s.data64[i] OPR other.data64[i]) & m) == (x & m)
STC_DEF bool cbits_subset_of(cbits s, cbits other) { _cbits_SETOP(|, s.data64[i]); }
diff --git a/include/stc/forward.h b/include/stc/forward.h index 06ec3897..2351176a 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -46,7 +46,7 @@ typedef struct { char* data; size_t size, cap; } cstr_rep_t; typedef char cstr_value;
#ifdef STC_USE_SSO
typedef union {
- struct { char data[sizeof(cstr_rep_t) - 1]; uint8_t last; } sso;
+ struct { char data[sizeof(cstr_rep_t) - 1]; uint8_t last; } sml;
struct { char* data; size_t size, ncap; } lon;
} cstr;
#else
|
