diff options
| author | Tyge Løvset <[email protected]> | 2023-02-14 07:54:01 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-14 07:54:01 +0100 |
| commit | e456085a392d063df1a2495422523a2474ea6a18 (patch) | |
| tree | 363250af394400d0fb6a33763f5a89acd1b4dd61 /include | |
| parent | 7dc6fddc079f4f572c8fb7c0ffd5a27e03291a2d (diff) | |
| parent | 6df7f90dbabf7f60e37109335f2cb8f8b6b5d02f (diff) | |
| download | STC-modified-e456085a392d063df1a2495422523a2474ea6a18.tar.gz STC-modified-e456085a392d063df1a2495422523a2474ea6a18.zip | |
Merge pull request #48 from tylov/dev411
Release V4.1.1
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/filter.h | 8 | ||||
| -rw-r--r-- | include/stc/cbits.h | 74 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 16 | ||||
| -rw-r--r-- | include/stc/cstr.h | 16 | ||||
| -rw-r--r-- | include/stc/csview.h | 8 | ||||
| -rw-r--r-- | include/stc/priv/altnames.h | 3 | ||||
| -rw-r--r-- | include/stc/utf8.h | 2 |
7 files changed, 63 insertions, 64 deletions
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h index 8357cb4d..6f8e1654 100644 --- a/include/stc/algo/filter.h +++ b/include/stc/algo/filter.h @@ -50,15 +50,15 @@ int main() #include <stc/ccommon.h> #ifndef c_NFILTERS - #define c_NFILTERS 14 /* 22, 30, .. */ +#define c_NFILTERS 32 #endif -#define c_flt_take(i, n) (++(i).s1[(i).s1top++] <= (n)) -#define c_flt_skip(i, n) (++(i).s1[(i).s1top++] > (n)) +#define c_flt_take(i, n) (c_flt_count(i) <= (n)) +#define c_flt_skip(i, n) (c_flt_count(i) > (n)) #define c_flt_skipwhile(i, pred) ((i).s2[(i).s2top++] |= !(pred)) #define c_flt_takewhile(i, pred) !c_flt_skipwhile(i, pred) #define c_flt_last(i) (i).s1[(i).s1top-1] -#define c_flt_lastwhile(i) (i).s2[(i).s2top-1] +#define c_flt_count(i) ++(i).s1[(i).s1top++] #define c_forfilter(...) c_MACRO_OVERLOAD(c_forfilter, __VA_ARGS__) diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 0c169b88..c3167dae 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -56,7 +56,7 @@ int main() { #include <string.h> #define _cbits_bit(i) ((uint64_t)1 << ((i) & 63)) -#define _cbits_words(n) (intptr_t)(((n) + 63)>>6) +#define _cbits_words(n) (int64_t)(((n) + 63)>>6) #define _cbits_bytes(n) (_cbits_words(n) * c_sizeof(uint64_t)) #if defined(__GNUC__) || defined(__clang__) @@ -73,23 +73,23 @@ int main() { } #endif -STC_INLINE intptr_t _cbits_count(const uint64_t* set, const intptr_t sz) { - const intptr_t n = sz>>6; - intptr_t count = 0; - for (intptr_t i = 0; i < n; ++i) +STC_INLINE int64_t _cbits_count(const uint64_t* set, const int64_t sz) { + const int64_t n = sz>>6; + int64_t count = 0; + for (int64_t i = 0; i < n; ++i) count += cpopcount64(set[i]); if (sz & 63) count += cpopcount64(set[n] & (_cbits_bit(sz) - 1)); return count; } -STC_INLINE char* _cbits_to_str(const uint64_t* set, const intptr_t sz, - char* out, intptr_t start, intptr_t stop) { +STC_INLINE char* _cbits_to_str(const uint64_t* set, const int64_t sz, + char* out, int64_t start, int64_t stop) { if (stop > sz) stop = sz; assert(start <= stop); c_memset(out, '0', stop - start); - for (intptr_t i = start; i < stop; ++i) + for (int64_t i = start; i < stop; ++i) if ((set[i>>6] & _cbits_bit(i)) != 0) out[i - start] = '1'; out[stop - start] = '\0'; @@ -97,19 +97,19 @@ STC_INLINE char* _cbits_to_str(const uint64_t* set, const intptr_t sz, } #define _cbits_OPR(OPR, VAL) \ - const uint64_t n = (uint64_t)sz>>6; \ - for (uint64_t i = 0; i < n; ++i) \ + const int64_t n = sz>>6; \ + for (int64_t i = 0; i < n; ++i) \ if ((set[i] OPR other[i]) != VAL) \ return false; \ if (!(sz & 63)) \ return true; \ - const uint64_t i = n, m = _cbits_bit(sz) - 1; \ + const uint64_t i = (uint64_t)n, m = _cbits_bit(sz) - 1; \ return ((set[i] OPR other[i]) & m) == (VAL & m) -STC_INLINE bool _cbits_subset_of(const uint64_t* set, const uint64_t* other, const intptr_t sz) +STC_INLINE bool _cbits_subset_of(const uint64_t* set, const uint64_t* other, const int64_t sz) { _cbits_OPR(|, set[i]); } -STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, const intptr_t sz) +STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, const int64_t sz) { _cbits_OPR(&, 0); } #endif // CBITS_H_INCLUDED @@ -121,12 +121,12 @@ STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, cons #define _i_assert(x) assert(x) #define i_type cbits -struct { uint64_t *data64; intptr_t _size; } typedef i_type; +struct { uint64_t *data64; int64_t _size; } typedef i_type; STC_INLINE cbits cbits_init(void) { return c_LITERAL(cbits){NULL}; } STC_INLINE void cbits_create(cbits* self) { self->data64 = NULL; self->_size = 0; } STC_INLINE void cbits_drop(cbits* self) { c_free(self->data64); } -STC_INLINE intptr_t cbits_size(const cbits* self) { return self->_size; } +STC_INLINE int64_t cbits_size(const cbits* self) { return self->_size; } STC_INLINE cbits* cbits_take(cbits* self, cbits other) { if (self->data64 != other.data64) { @@ -137,7 +137,7 @@ STC_INLINE cbits* cbits_take(cbits* self, cbits other) { } STC_INLINE cbits cbits_clone(cbits other) { - const intptr_t bytes = _cbits_bytes(other._size); + const int64_t bytes = _cbits_bytes(other._size); cbits set = {(uint64_t *)c_memcpy(c_malloc(bytes), other.data64, bytes), other._size}; return set; } @@ -151,8 +151,8 @@ STC_INLINE cbits* cbits_copy(cbits* self, const cbits* other) { return self; } -STC_INLINE void cbits_resize(cbits* self, const intptr_t size, const bool value) { - const intptr_t new_n = _cbits_words(size), osize = self->_size, old_n = _cbits_words(osize); +STC_INLINE void cbits_resize(cbits* self, const int64_t size, const bool value) { + const int64_t new_n = _cbits_words(size), osize = self->_size, old_n = _cbits_words(osize); self->data64 = (uint64_t *)c_realloc(self->data64, new_n*8); self->_size = size; if (new_n >= old_n) { @@ -174,13 +174,13 @@ STC_INLINE cbits cbits_move(cbits* self) { return tmp; } -STC_INLINE cbits cbits_with_size(const intptr_t size, const bool value) { +STC_INLINE cbits cbits_with_size(const int64_t size, const bool value) { cbits set = {(uint64_t *)c_malloc(_cbits_bytes(size)), size}; cbits_set_all(&set, value); return set; } -STC_INLINE cbits cbits_with_pattern(const intptr_t size, const uint64_t pattern) { +STC_INLINE cbits cbits_with_pattern(const int64_t size, const uint64_t pattern) { cbits set = {(uint64_t *)c_malloc(_cbits_bytes(size)), size}; cbits_set_pattern(&set, pattern); return set; @@ -198,7 +198,7 @@ struct { uint64_t data64[(i_capacity - 1)/64 + 1]; } typedef i_type; STC_INLINE i_type _i_memb(_init)(void) { return c_LITERAL(i_type){0}; } STC_INLINE void _i_memb(_create)(i_type* self) {} STC_INLINE void _i_memb(_drop)(i_type* self) {} -STC_INLINE intptr_t _i_memb(_size)(const i_type* self) { return i_capacity; } +STC_INLINE int64_t _i_memb(_size)(const i_type* self) { return i_capacity; } STC_INLINE i_type _i_memb(_move)(i_type* self) { return *self; } STC_INLINE i_type* _i_memb(_take)(i_type* self, i_type other) @@ -213,13 +213,13 @@ STC_INLINE i_type* _i_memb(_copy)(i_type* self, const i_type* other) STC_INLINE void _i_memb(_set_all)(i_type *self, const bool value); STC_INLINE void _i_memb(_set_pattern)(i_type *self, const uint64_t pattern); -STC_INLINE i_type _i_memb(_with_size)(const intptr_t size, const bool value) { +STC_INLINE i_type _i_memb(_with_size)(const int64_t size, const bool value) { assert(size <= i_capacity); i_type set; _i_memb(_set_all)(&set, value); return set; } -STC_INLINE i_type _i_memb(_with_pattern)(const intptr_t size, const uint64_t pattern) { +STC_INLINE i_type _i_memb(_with_pattern)(const int64_t size, const uint64_t pattern) { assert(size <= i_capacity); i_type set; _i_memb(_set_pattern)(&set, pattern); return set; @@ -232,36 +232,36 @@ STC_INLINE void _i_memb(_set_all)(i_type *self, const bool value) { c_memset(self->data64, value? ~0 : 0, _cbits_bytes(_i_memb(_size)(self))); } STC_INLINE void _i_memb(_set_pattern)(i_type *self, const uint64_t pattern) { - intptr_t n = _cbits_words(_i_memb(_size)(self)); + int64_t n = _cbits_words(_i_memb(_size)(self)); while (n--) self->data64[n] = pattern; } -STC_INLINE bool _i_memb(_test)(const i_type* self, const intptr_t i) +STC_INLINE bool _i_memb(_test)(const i_type* self, const int64_t i) { return (self->data64[i>>6] & _cbits_bit(i)) != 0; } -STC_INLINE bool _i_memb(_at)(const i_type* self, const intptr_t i) +STC_INLINE bool _i_memb(_at)(const i_type* self, const int64_t i) { return (self->data64[i>>6] & _cbits_bit(i)) != 0; } -STC_INLINE void _i_memb(_set)(i_type *self, const intptr_t i) +STC_INLINE void _i_memb(_set)(i_type *self, const int64_t i) { self->data64[i>>6] |= _cbits_bit(i); } -STC_INLINE void _i_memb(_reset)(i_type *self, const intptr_t i) +STC_INLINE void _i_memb(_reset)(i_type *self, const int64_t i) { self->data64[i>>6] &= ~_cbits_bit(i); } -STC_INLINE void _i_memb(_set_value)(i_type *self, const intptr_t i, const bool b) { +STC_INLINE void _i_memb(_set_value)(i_type *self, const int64_t i, const bool b) { self->data64[i>>6] ^= ((uint64_t)-(int)b ^ self->data64[i>>6]) & _cbits_bit(i); } -STC_INLINE void _i_memb(_flip)(i_type *self, const intptr_t i) +STC_INLINE void _i_memb(_flip)(i_type *self, const int64_t i) { self->data64[i>>6] ^= _cbits_bit(i); } STC_INLINE void _i_memb(_flip_all)(i_type *self) { - intptr_t n = _cbits_words(_i_memb(_size)(self)); + int64_t n = _cbits_words(_i_memb(_size)(self)); while (n--) self->data64[n] ^= ~(uint64_t)0; } STC_INLINE i_type _i_memb(_from)(const char* str) { - intptr_t n = c_strlen(str); + int64_t n = c_strlen(str); i_type set = _i_memb(_with_size)(n, false); while (n--) if (str[n] == '1') _i_memb(_set)(&set, n); return set; @@ -270,26 +270,26 @@ STC_INLINE i_type _i_memb(_from)(const char* str) { /* Intersection */ STC_INLINE void _i_memb(_intersect)(i_type *self, const i_type* other) { _i_assert(self->_size == other->_size); - intptr_t n = _cbits_words(_i_memb(_size)(self)); + int64_t n = _cbits_words(_i_memb(_size)(self)); while (n--) self->data64[n] &= other->data64[n]; } /* Union */ STC_INLINE void _i_memb(_union)(i_type *self, const i_type* other) { _i_assert(self->_size == other->_size); - intptr_t n = _cbits_words(_i_memb(_size)(self)); + int64_t n = _cbits_words(_i_memb(_size)(self)); while (n--) self->data64[n] |= other->data64[n]; } /* Exclusive disjunction */ STC_INLINE void _i_memb(_xor)(i_type *self, const i_type* other) { _i_assert(self->_size == other->_size); - intptr_t n = _cbits_words(_i_memb(_size)(self)); + int64_t n = _cbits_words(_i_memb(_size)(self)); while (n--) self->data64[n] ^= other->data64[n]; } -STC_INLINE intptr_t _i_memb(_count)(const i_type* self) +STC_INLINE int64_t _i_memb(_count)(const i_type* self) { return _cbits_count(self->data64, _i_memb(_size)(self)); } -STC_INLINE char* _i_memb(_to_str)(const i_type* self, char* out, intptr_t start, intptr_t stop) +STC_INLINE char* _i_memb(_to_str)(const i_type* self, char* out, int64_t start, int64_t stop) { return _cbits_to_str(self->data64, _i_memb(_size)(self), out, start, stop); } STC_INLINE bool _i_memb(_subset_of)(const i_type* self, const i_type* other) { diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 0b3083ef..04c26d4c 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -129,13 +129,13 @@ typedef const char* crawstr; #define crawstr_hash(p) cstrhash(*(p)) #define crawstr_len(literal) (c_sizeof("" literal) - 1) -#define c_SV(...) c_MACRO_OVERLOAD(c_SV, __VA_ARGS__) -#define c_SV_1(lit) c_SV_2(lit, crawstr_len(lit)) -#define c_SV_2(str, n) (c_LITERAL(csview){str, n}) -#define c_SVARG(sv) (int)(sv).size, (sv).str /* use with "%.*s" */ -#define c_PAIR(ref) (ref)->first, (ref)->second +#define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__) +#define c_sv_1(lit) c_sv_2(lit, crawstr_len(lit)) +#define c_sv_2(str, n) (c_LITERAL(csview){str, n}) -#define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) +#define c_SV(sv) (int)(sv).size, (sv).str // print csview: use format "%.*s" +#define c_PAIR(ref) (ref)->first, (ref)->second +#define c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) STC_INLINE uint64_t cfasthash(const void* key, intptr_t len) { const uint8_t *x = (const uint8_t*) key; @@ -143,7 +143,7 @@ STC_INLINE uint64_t cfasthash(const void* key, intptr_t len) { uint32_t u4; while (n--) { memcpy(&u8, x, 8), x += 8; - h += (_c_ROTL(u8, 26) ^ u8)*0xc6a4a7935bd1e99d; + h += (c_ROTL(u8, 26) ^ u8)*0xc6a4a7935bd1e99d; } switch (len &= 7) { case 0: return h; @@ -152,7 +152,7 @@ STC_INLINE uint64_t cfasthash(const void* key, intptr_t len) { } h += *x++; while (--len) h = (h << 10) - h + *x++; - return _c_ROTL(h, 26) ^ h; + return c_ROTL(h, 26) ^ h; } STC_INLINE uint64_t cstrhash(const char *str) diff --git a/include/stc/cstr.h b/include/stc/cstr.h index c5808d02..ce6dba81 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -181,10 +181,10 @@ STC_INLINE cstr cstr_toupper_sv(csview sv) { return cstr_tocase(sv, 2); } STC_INLINE cstr cstr_tolower(const char* str) - { return cstr_tolower_sv(c_SV(str, c_strlen(str))); } + { return cstr_tolower_sv(c_sv(str, c_strlen(str))); } STC_INLINE cstr cstr_toupper(const char* str) - { return cstr_toupper_sv(c_SV(str, c_strlen(str))); } + { return cstr_toupper_sv(c_sv(str, c_strlen(str))); } STC_INLINE void cstr_lowercase(cstr* self) { cstr_take(self, cstr_tolower_sv(cstr_sv(self))); } @@ -316,7 +316,7 @@ STC_INLINE bool cstr_starts_with_s(const cstr* self, cstr sub) STC_INLINE bool cstr_istarts_with(const cstr* self, const char* sub) { csview sv = cstr_sv(self); intptr_t len = c_strlen(sub); - return len <= sv.size && !utf8_icmp_sv(sv, c_SV(sub, len)); + return len <= sv.size && !utf8_icmp_sv(sv, c_sv(sub, len)); } @@ -330,7 +330,7 @@ STC_INLINE bool cstr_ends_with_s(const cstr* self, cstr sub) { return cstr_ends_with_sv(self, cstr_sv(&sub)); } STC_INLINE bool cstr_ends_with(const cstr* self, const char* sub) - { return cstr_ends_with_sv(self, c_SV(sub, c_strlen(sub))); } + { return cstr_ends_with_sv(self, c_sv(sub, c_strlen(sub))); } STC_INLINE bool cstr_iends_with(const cstr* self, const char* sub) { csview sv = cstr_sv(self); @@ -375,8 +375,8 @@ STC_INLINE char* cstr_append_s(cstr* self, cstr s) { #define cstr_replace(...) c_MACRO_OVERLOAD(cstr_replace, __VA_ARGS__) #define cstr_replace_3(self, search, repl) cstr_replace_4(self, search, repl, INT32_MAX) STC_INLINE void cstr_replace_4(cstr* self, const char* search, const char* repl, int32_t count) { - cstr_take(self, cstr_replace_sv(cstr_sv(self), c_SV(search, c_strlen(search)), - c_SV(repl, c_strlen(repl)), count)); + cstr_take(self, cstr_replace_sv(cstr_sv(self), c_sv(search, c_strlen(search)), + c_sv(repl, c_strlen(repl)), count)); } STC_INLINE void cstr_replace_at_sv(cstr* self, intptr_t pos, intptr_t len, const csview repl) { @@ -385,7 +385,7 @@ STC_INLINE void cstr_replace_at_sv(cstr* self, intptr_t pos, intptr_t len, const } STC_INLINE void cstr_replace_at(cstr* self, intptr_t pos, intptr_t len, const char* repl) - { cstr_replace_at_sv(self, pos, len, c_SV(repl, c_strlen(repl))); } + { cstr_replace_at_sv(self, pos, len, c_sv(repl, c_strlen(repl))); } STC_INLINE void cstr_replace_at_s(cstr* self, intptr_t pos, intptr_t len, cstr repl) { cstr_replace_at_sv(self, pos, len, cstr_sv(&repl)); } @@ -395,7 +395,7 @@ STC_INLINE void cstr_u8_replace_at(cstr* self, intptr_t bytepos, intptr_t u8len, STC_INLINE void cstr_insert(cstr* self, intptr_t pos, const char* str) - { cstr_replace_at_sv(self, pos, 0, c_SV(str, c_strlen(str))); } + { cstr_replace_at_sv(self, pos, 0, c_sv(str, c_strlen(str))); } STC_INLINE void cstr_insert_sv(cstr* self, intptr_t pos, csview sv) { cstr_replace_at_sv(self, pos, 0, sv); } diff --git a/include/stc/csview.h b/include/stc/csview.h index 748f7d30..bba3aea3 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -27,12 +27,12 @@ #include "forward.h" #include "utf8.h" -#define csview_NULL c_SV_1("") +#define csview_NULL c_sv_1("") #define csview_init() csview_NULL #define csview_drop(p) c_default_drop(p) #define csview_clone(sv) c_default_clone(sv) -#define csview_lit(literal) c_SV_1(literal) -#define csview_from_n(str, n) c_SV_2(str, n) +#define csview_lit(literal) c_sv_1(literal) +#define csview_from_n(str, n) c_sv_2(str, n) STC_API intptr_t csview_find_sv(csview sv, csview search); @@ -47,7 +47,7 @@ STC_INLINE bool csview_equals(csview sv, const char* str) { intptr_t n = c_strlen(str); return sv.size == n && !c_memcmp(sv.str, str, n); } STC_INLINE intptr_t csview_find(csview sv, const char* str) - { return csview_find_sv(sv, c_SV(str, c_strlen(str))); } + { return csview_find_sv(sv, c_sv(str, c_strlen(str))); } STC_INLINE bool csview_contains(csview sv, const char* str) { return csview_find(sv, str) != c_NPOS; } diff --git a/include/stc/priv/altnames.h b/include/stc/priv/altnames.h index bfda05ca..b10c7a11 100644 --- a/include/stc/priv/altnames.h +++ b/include/stc/priv/altnames.h @@ -35,5 +35,4 @@ #define c_DEFER c_defer #define c_NEW c_new #define c_ARRAYLEN c_arraylen -#define c_ARGSV c_SVARG -#define c_sv c_SV +#define c_ARGSV c_SV // [deprecated] diff --git a/include/stc/utf8.h b/include/stc/utf8.h index 7ad01ef4..a4cc3846 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -68,7 +68,7 @@ STC_INLINE uint32_t utf8_peek(const char* s) { /* case-insensitive utf8 string comparison */ STC_INLINE int utf8_icmp(const char* s1, const char* s2) { - return utf8_icmp_sv(c_SV(s1, INTPTR_MAX), c_SV(s2, INTPTR_MAX)); + return utf8_icmp_sv(c_sv(s1, INTPTR_MAX), c_sv(s2, INTPTR_MAX)); } STC_INLINE bool utf8_valid(const char* s) { |
