summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-19 09:04:23 +0100
committerTyge Løvset <[email protected]>2022-12-19 09:04:23 +0100
commit1d4ad83d6f3388982cb0aeadbc9815b4776df504 (patch)
tree6d0d389219644b127eaa83c8a54ccd93deef96b7 /include
parent26a75a218a115a10cee82534be568a606c83dbb2 (diff)
downloadSTC-modified-1d4ad83d6f3388982cb0aeadbc9815b4776df504.tar.gz
STC-modified-1d4ad83d6f3388982cb0aeadbc9815b4776df504.zip
Renames:
cstr_null => cstr_NULL csview_null => csview_NULL cstr_npos => c_NPOS csview_npos => c_NPOS c_ARGsv(sv) => c_ARGSV(sv) c_init(x) => c_INIT(x)
Diffstat (limited to 'include')
-rw-r--r--include/stc/alt/csmap.h4
-rw-r--r--include/stc/alt/cstr.h36
-rw-r--r--include/stc/carc.h4
-rw-r--r--include/stc/carr2.h4
-rw-r--r--include/stc/carr3.h4
-rw-r--r--include/stc/cbits.h4
-rw-r--r--include/stc/cbox.h6
-rw-r--r--include/stc/ccommon.h18
-rw-r--r--include/stc/cdeq.h8
-rw-r--r--include/stc/clist.h6
-rw-r--r--include/stc/cmap.h8
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/crandom.h4
-rw-r--r--include/stc/csmap.h4
-rw-r--r--include/stc/cstack.h4
-rw-r--r--include/stc/cstr.h35
-rw-r--r--include/stc/csview.h26
-rw-r--r--include/stc/cvec.h8
18 files changed, 92 insertions, 93 deletions
diff --git a/include/stc/alt/csmap.h b/include/stc/alt/csmap.h
index c1ceb756..65a9f80b 100644
--- a/include/stc/alt/csmap.h
+++ b/include/stc/alt/csmap.h
@@ -130,7 +130,7 @@ _cx_memb(_clear)(_cx_self* self)
STC_INLINE _cx_raw
_cx_memb(_value_toraw)(_cx_value* val) {
return _i_SET_ONLY( i_keyto(val) )
- _i_MAP_ONLY( c_init(_cx_raw){i_keyto((&val->first)),
+ _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)),
i_valto((&val->second))} );
}
@@ -471,7 +471,7 @@ _cx_memb(_clone_r_)(_cx_node *tn) {
STC_DEF _cx_self
_cx_memb(_clone)(_cx_self cx) {
- return c_init(_cx_self){_cx_memb(_clone_r_)(cx.root), cx.size};
+ return c_INIT(_cx_self){_cx_memb(_clone_r_)(cx.root), cx.size};
}
#endif // !i_no_clone
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h
index ba0eb0bb..4496fb35 100644
--- a/include/stc/alt/cstr.h
+++ b/include/stc/alt/cstr.h
@@ -31,16 +31,18 @@
#include <stdio.h> /* vsnprintf */
#include <ctype.h>
+#define c_unchecked_container_of(ptr, type, member) \
+ ((type*)((char*)(ptr) - offsetof(type, member)))
+
typedef char cstr_value;
typedef struct { cstr_value* str; } cstr;
-#define cstr_npos (SIZE_MAX >> 1)
typedef struct { size_t size, cap; char chr[1]; } cstr_priv;
#define _cstr_p(self) c_unchecked_container_of((self)->str, cstr_priv, chr)
#ifdef i_static
static cstr_priv _cstr_nullrep = {0, 0, {0}};
- static const cstr cstr_null = {_cstr_nullrep.chr};
+ static const cstr cstr_NULL = {_cstr_nullrep.chr};
#else
- extern const cstr cstr_null;
+ extern const cstr cstr_NULL;
#endif
/* optimal memory: based on malloc_usable_size() sequence: 24, 40, 56, ... */
#define _cstr_opt_mem(cap) ((((offsetof(cstr_priv, chr) + (cap) + 8)>>4)<<4) + 8)
@@ -61,11 +63,11 @@ STC_API size_t cstr_find(const cstr* self, const char* needle);
STC_API size_t cstr_find_at(const cstr* self, size_t pos, const char* needle);
STC_API bool cstr_getdelim(cstr *self, int delim, FILE *stream);
-STC_INLINE cstr cstr_init() { return cstr_null; }
+STC_INLINE cstr cstr_init() { return cstr_NULL; }
STC_INLINE const char* cstr_str(const cstr* self) { return self->str; }
#define cstr_toraw(self) (self)->str
STC_INLINE csview cstr_sv(const cstr* self)
- { return c_init(csview){self->str, _cstr_p(self)->size}; }
+ { return c_INIT(csview){self->str, _cstr_p(self)->size}; }
#define cstr_new(literal) \
cstr_from_n(literal, c_strlen_lit(literal))
STC_INLINE cstr cstr_from(const char* str)
@@ -116,17 +118,17 @@ STC_INLINE bool cstr_getline(cstr *self, FILE *stream)
STC_INLINE cstr_buf cstr_buffer(cstr* s) {
cstr_priv* p = _cstr_p(s);
- return c_init(cstr_buf){s->str, p->size, p->cap};
+ return c_INIT(cstr_buf){s->str, p->size, p->cap};
}
STC_INLINE cstr cstr_with_capacity(const size_t cap) {
- cstr s = cstr_null;
+ cstr s = cstr_NULL;
cstr_reserve(&s, cap);
return s;
}
STC_INLINE cstr cstr_with_size(const size_t len, const char fill) {
- cstr s = cstr_null;
+ cstr s = cstr_NULL;
cstr_resize(&s, len, fill);
return s;
}
@@ -147,7 +149,7 @@ STC_INLINE cstr* cstr_take(cstr* self, cstr s) {
STC_INLINE cstr cstr_move(cstr* self) {
cstr tmp = *self;
- *self = cstr_null;
+ *self = cstr_NULL;
return tmp;
}
@@ -192,7 +194,7 @@ cstr_replace(cstr* self, const char* find, const char* repl, unsigned count) {
#ifndef i_static
static cstr_priv _cstr_nullrep = {0, 0, {0}};
-const cstr cstr_null = {_cstr_nullrep.chr};
+const cstr cstr_NULL = {_cstr_nullrep.chr};
#endif
STC_DEF char*
@@ -219,7 +221,7 @@ cstr_resize(cstr* self, const size_t len, const char fill) {
STC_DEF cstr
cstr_from_n(const char* str, const size_t n) {
- if (n == 0) return cstr_null;
+ if (n == 0) return cstr_NULL;
cstr_priv* prv = (cstr_priv*) c_malloc(_cstr_opt_mem(n));
cstr s = {(char *) memcpy(prv->chr, str, n)};
s.str[prv->size = n] = '\0';
@@ -254,7 +256,7 @@ cstr_vfmt(cstr* self, const char* fmt, va_list args) {
STC_DEF cstr
cstr_from_fmt(const char* fmt, ...) {
- cstr ret = cstr_null;
+ cstr ret = cstr_NULL;
va_list args; va_start(args, fmt);
cstr_vfmt(&ret, fmt, args);
va_end(args);
@@ -263,7 +265,7 @@ cstr_from_fmt(const char* fmt, ...) {
STC_DEF int
cstr_printf(cstr* self, const char* fmt, ...) {
- cstr ret = cstr_null;
+ cstr ret = cstr_NULL;
va_list args;
va_start(args, fmt);
int n = cstr_vfmt(&ret, fmt, args);
@@ -320,7 +322,7 @@ cstr_replace_at_sv(cstr* self, const size_t pos, size_t len, csview repl) {
STC_DEF cstr
cstr_replace_sv(csview str, csview find, csview repl, unsigned count) {
- cstr out = cstr_null;
+ cstr out = cstr_NULL;
size_t from = 0; char* res;
if (count == 0) count = ~0;
if (find.size)
@@ -368,14 +370,14 @@ cstr_getdelim(cstr *self, const int delim, FILE *fp) {
STC_DEF size_t
cstr_find(const cstr* self, const char* needle) {
char* res = strstr(self->str, needle);
- return res ? res - self->str : cstr_npos;
+ return res ? res - self->str : c_NPOS;
}
STC_DEF size_t
cstr_find_at(const cstr* self, const size_t pos, const char* needle) {
- if (pos > _cstr_p(self)->size) return cstr_npos;
+ if (pos > _cstr_p(self)->size) return c_NPOS;
char* res = strstr(self->str + pos, needle);
- return res ? res - self->str : cstr_npos;
+ return res ? res - self->str : c_NPOS;
}
#endif
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 78887073..509bc595 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -71,7 +71,7 @@ int main() {
#define c_atomic_dec_and_test(v) (atomic_fetch_sub(v, 1) == 1)
#endif
-#define carc_null {NULL, NULL}
+#define carc_NULL {NULL, NULL}
#define _cx_carc_rep struct _cx_memb(_rep_)
#endif // CARC_H_INCLUDED
@@ -94,7 +94,7 @@ _cx_deftypes(_c_carc_types, _cx_self, i_key);
_cx_carc_rep { catomic_long counter; i_key value; };
STC_INLINE _cx_self _cx_memb(_init)(void)
- { return c_init(_cx_self){NULL, NULL}; }
+ { return c_INIT(_cx_self){NULL, NULL}; }
STC_INLINE long _cx_memb(_use_count)(const _cx_self* self)
{ return self->use_count ? *self->use_count : 0; }
diff --git a/include/stc/carr2.h b/include/stc/carr2.h
index 2574a933..4a12c2e3 100644
--- a/include/stc/carr2.h
+++ b/include/stc/carr2.h
@@ -91,11 +91,11 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y) {
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
size_t n = self->xdim*self->ydim;
- return c_init(_cx_iter){n ? *self->data : NULL, *self->data + n};
+ return c_INIT(_cx_iter){n ? *self->data : NULL, *self->data + n};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_init(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; }
+ { return c_INIT(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
diff --git a/include/stc/carr3.h b/include/stc/carr3.h
index 0197e4f5..c22536cb 100644
--- a/include/stc/carr3.h
+++ b/include/stc/carr3.h
@@ -94,11 +94,11 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y, size_
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
size_t n = _cx_memb(_size)(self);
- return c_init(_cx_iter){n ? **self->data : NULL, **self->data + n};
+ return c_INIT(_cx_iter){n ? **self->data : NULL, **self->data + n};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_init(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; }
+ { return c_INIT(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index 031ef80c..8c0db10f 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -123,7 +123,7 @@ STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, cons
struct { uint64_t *data64; size_t _size; } typedef i_type;
-STC_INLINE cbits cbits_init(void) { return c_init(cbits){NULL}; }
+STC_INLINE cbits cbits_init(void) { return c_INIT(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 size_t cbits_size(const cbits* self) { return self->_size; }
@@ -195,7 +195,7 @@ STC_INLINE cbits cbits_with_pattern(const size_t size, const uint64_t pattern) {
struct { uint64_t data64[(i_capacity - 1)/64 + 1]; } typedef i_type;
-STC_INLINE i_type _i_memb(_init)(void) { return c_init(i_type){0}; }
+STC_INLINE i_type _i_memb(_init)(void) { return c_INIT(i_type){0}; }
STC_INLINE void _i_memb(_create)(i_type* self) {}
STC_INLINE void _i_memb(_drop)(i_type* self) {}
STC_INLINE size_t _i_memb(_size)(const i_type* self) { return i_capacity; }
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index a5e01519..4cbd5f84 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -64,7 +64,7 @@ int main() {
#include <stdlib.h>
#include <string.h>
-#define cbox_null {NULL}
+#define cbox_NULL {NULL}
#endif // CBOX_H_INCLUDED
#ifndef _i_prefix
@@ -79,13 +79,13 @@ _cx_deftypes(_c_cbox_types, _cx_self, i_key);
// constructors (takes ownsership)
STC_INLINE _cx_self _cx_memb(_init)(void)
- { return c_init(_cx_self){NULL}; }
+ { return c_INIT(_cx_self){NULL}; }
STC_INLINE long _cx_memb(_use_count)(const _cx_self* self)
{ return (long)(self->get != NULL); }
STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p)
- { return c_init(_cx_self){p}; }
+ { return c_INIT(_cx_self){p}; }
// c++: std::make_unique<i_key>(val)
STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) {
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 0777d0ce..c33f5f59 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -32,8 +32,10 @@
#if SIZE_MAX == UINT32_MAX
#define c_ZU PRIu32
+ #define c_NPOS INT32_MAX
#elif SIZE_MAX == UINT64_MAX
#define c_ZU PRIu64
+ #define c_NPOS INT64_MAX
#endif
#if defined(_MSC_VER)
@@ -61,22 +63,20 @@
#define c_static_assert(cond) \
typedef char c_paste(_static_assert_line_, __LINE__)[(cond) ? 1 : -1]
-#define c_unchecked_container_of(ptr, type, member) \
- ((type*)((char*)(ptr) - offsetof(type, member)))
#define c_container_of(p, T, m) \
((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m)))
#ifndef __cplusplus
#define c_alloc(T) c_malloc(sizeof(T))
#define c_alloc_n(T, n) c_malloc(sizeof(T)*(n))
- #define c_init(T) (T)
#define c_new(T, ...) ((T*)memcpy(c_alloc(T), (T[]){__VA_ARGS__}, sizeof(T)))
+ #define c_INIT(T) (T)
#else
#include <new>
#define c_alloc(T) static_cast<T*>(c_malloc(sizeof(T)))
#define c_alloc_n(T, n) static_cast<T*>(c_malloc(sizeof(T)*(n)))
- #define c_init(T) T
#define c_new(T, ...) new (c_alloc(T)) T(__VA_ARGS__)
+ #define c_INIT(T) T
#endif
#ifndef c_malloc
#define c_malloc(sz) malloc(sz)
@@ -116,12 +116,12 @@ typedef const char* crawstr;
#define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp))
#define crawstr_hash(p) cstrhash(*(p))
-#define c_strlen_lit(literal) (sizeof "" literal - 1U)
+#define c_strlen_lit(literal) (sizeof("" literal) - 1U)
#define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__)
-#define c_sv1(lit) (c_init(csview){lit, c_strlen_lit(lit)})
-#define c_sv2(str, n) (c_init(csview){str, n})
-#define c_PRIsv ".*s"
-#define c_ARGsv(sv) (int)(sv).size, (sv).str
+#define c_sv1(lit) c_sv2(lit, c_strlen_lit(lit))
+#define c_sv2(str, n) (c_INIT(csview){str, n})
+#define c_ARGsv(sv) c_ARGSV(sv) /* [deprecated] */
+#define c_ARGSV(sv) (int)(sv).size, (sv).str /* use with "%.*s" */
#define c_PAIR(ref) (ref)->first, (ref)->second
#define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index 11bc82d2..a8a704b4 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -99,11 +99,11 @@ STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
size_t n = self->_len;
- return c_init(_cx_iter){n ? self->data : NULL, self->data + n};
+ return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_init(_cx_iter){NULL, self->data + self->_len}; }
+ { return c_INIT(_cx_iter){NULL, self->data + self->_len}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
@@ -343,7 +343,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) {
self->_len += n;
pos = self->data + idx;
}
- return c_init(_cx_iter){pos, self->data + self->_len};
+ return c_INIT(_cx_iter){pos, self->data + self->_len};
}
STC_DEF _cx_value*
@@ -375,7 +375,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) {
{ i_keydrop(p); }
memmove(p1, p2, (size_t)(end - p2)*sizeof *p1);
self->_len -= (size_t)len;
- return c_init(_cx_iter){p2 == end ? NULL : p1, end - len};
+ return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len};
}
#if !defined i_no_clone
diff --git a/include/stc/clist.h b/include/stc/clist.h
index cb692eae..8b96eabf 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -133,7 +133,7 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw)
{ return _cx_memb(_push_back)(self, i_keyfrom(raw)); }
#endif // !i_no_emplace
-STC_INLINE _cx_self _cx_memb(_init)(void) { return c_init(_cx_self){NULL}; }
+STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){NULL}; }
STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { return true; }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) { return self->last == NULL; }
STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_drop)(self); }
@@ -157,12 +157,12 @@ _cx_memb(_count)(const _cx_self* self) {
STC_INLINE _cx_iter
_cx_memb(_begin)(const _cx_self* self) {
_cx_value* head = self->last ? &self->last->next->value : NULL;
- return c_init(_cx_iter){head, &self->last, self->last};
+ return c_INIT(_cx_iter){head, &self->last, self->last};
}
STC_INLINE _cx_iter
_cx_memb(_end)(const _cx_self* self)
- { return c_init(_cx_iter){NULL}; }
+ { return c_INIT(_cx_iter){NULL}; }
STC_INLINE void
_cx_memb(_next)(_cx_iter* it) {
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index ff7c7840..dabb1138 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -107,7 +107,7 @@ STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawke
STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey);
STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val);
-STC_INLINE _cx_self _cx_memb(_init)(void) { return c_init(_cx_self){0}; }
+STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){0}; }
STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); }
STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; }
@@ -167,7 +167,7 @@ _cx_memb(_emplace)(_cx_self* self, _cx_rawkey rkey _i_MAP_ONLY(, i_valraw rmappe
STC_INLINE _cx_raw
_cx_memb(_value_toraw)(const _cx_value* val) {
return _i_SET_ONLY( i_keyto(val) )
- _i_MAP_ONLY( c_init(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} );
+ _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} );
}
STC_INLINE void
@@ -208,7 +208,7 @@ _cx_memb(_begin)(const _cx_self* self) {
STC_INLINE _cx_iter
_cx_memb(_end)(const _cx_self* self)
- { return c_init(_cx_iter){NULL}; }
+ { return c_INIT(_cx_iter){NULL}; }
STC_INLINE void
_cx_memb(_next)(_cx_iter* it) {
@@ -226,7 +226,7 @@ STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) {
size_t idx;
if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx])
- return c_init(_cx_iter){self->table + idx,
+ return c_INIT(_cx_iter){self->table + idx,
self->table + self->bucket_count,
self->_hashx + idx};
return _cx_memb(_end)(self);
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 996e1a22..9cf4b167 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -45,7 +45,7 @@ STC_API void _cx_memb(_erase_at)(_cx_self* self, size_t idx);
STC_API void _cx_memb(_push)(_cx_self* self, _cx_value value);
STC_INLINE _cx_self _cx_memb(_init)(void)
- { return c_init(_cx_self){NULL}; }
+ { return c_INIT(_cx_self){NULL}; }
STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) {
if (cap != self->_len && cap <= self->_cap) return true;
diff --git a/include/stc/crandom.h b/include/stc/crandom.h
index 6c41be83..6f65c84c 100644
--- a/include/stc/crandom.h
+++ b/include/stc/crandom.h
@@ -100,12 +100,12 @@ STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) {
/* Init uniform distributed float64 RNG, range [low, high). */
STC_INLINE stc64_uniformf_t stc64_uniformf_new(double low, double high) {
- return c_init(stc64_uniformf_t){low, high - low};
+ return c_INIT(stc64_uniformf_t){low, high - low};
}
/* Marsaglia polar method for gaussian/normal distribution, float64. */
STC_INLINE stc64_normalf_t stc64_normalf_new(double mean, double stddev) {
- return c_init(stc64_normalf_t){mean, stddev, 0.0, 0};
+ return c_INIT(stc64_normalf_t){mean, stddev, 0.0, 0};
}
/* -------------------------- IMPLEMENTATION ------------------------- */
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 68b69831..5c73294e 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -144,7 +144,7 @@ _cx_memb(_clear)(_cx_self* self)
STC_INLINE _cx_raw
_cx_memb(_value_toraw)(const _cx_value* val) {
return _i_SET_ONLY( i_keyto(val) )
- _i_MAP_ONLY( c_init(_cx_raw){i_keyto((&val->first)),
+ _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)),
i_valto((&val->second))} );
}
@@ -232,7 +232,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t cap) {
_cx_node* nodes = (_cx_node*)c_realloc(self->nodes, (cap + 1)*sizeof(_cx_node));
if (!nodes)
return false;
- nodes[0] = c_init(_cx_node){{0, 0}, 0};
+ nodes[0] = c_INIT(_cx_node){{0, 0}, 0};
self->nodes = nodes;
self->cap = (i_size)cap;
return true;
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 7aacb076..23778e3c 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -170,12 +170,12 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val)
#endif // !i_no_clone
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
- return c_init(_cx_iter){self->_len ? (_cx_value*)self->data : NULL,
+ return c_INIT(_cx_iter){self->_len ? (_cx_value*)self->data : NULL,
(_cx_value*)self->data + self->_len};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_init(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; }
+ { return c_INIT(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 29a2e4a4..b60a072e 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -71,8 +71,7 @@ STC_API char* _cstr_internal_move(cstr* self, size_t pos1, size_t pos2);
/**************************** PUBLIC API **********************************/
#define cstr_new(literal) cstr_from_n(literal, c_strlen_lit(literal))
-#define cstr_npos (SIZE_MAX >> 1)
-#define cstr_null (c_init(cstr){{{0}, 0}})
+#define cstr_NULL (c_INIT(cstr){{{0}, 0}})
#define cstr_toraw(self) cstr_str(self)
STC_API char* cstr_reserve(cstr* self, size_t cap);
@@ -92,16 +91,16 @@ STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, unsigned
STC_INLINE cstr_buf cstr_buffer(cstr* s) {
return cstr_is_long(s)
- ? c_init(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)}
- : c_init(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap};
+ ? c_INIT(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)}
+ : c_INIT(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap};
}
STC_INLINE csview cstr_sv(const cstr* s) {
- return cstr_is_long(s) ? c_init(csview){s->lon.data, cstr_l_size(s)}
- : c_init(csview){s->sml.data, cstr_s_size(s)};
+ return cstr_is_long(s) ? c_INIT(csview){s->lon.data, cstr_l_size(s)}
+ : c_INIT(csview){s->sml.data, cstr_s_size(s)};
}
STC_INLINE cstr cstr_init(void)
- { return cstr_null; }
+ { return cstr_NULL; }
STC_INLINE cstr cstr_from_n(const char* str, const size_t len) {
cstr s;
@@ -136,7 +135,7 @@ STC_INLINE cstr* cstr_take(cstr* self, const cstr s) {
STC_INLINE cstr cstr_move(cstr* self) {
cstr tmp = *self;
- *self = cstr_null;
+ *self = cstr_NULL;
return tmp;
}
@@ -224,11 +223,11 @@ STC_INLINE csview cstr_u8_chr(const cstr* self, size_t u8idx) {
STC_INLINE cstr_iter cstr_begin(const cstr* self) {
csview sv = cstr_sv(self);
- if (!sv.size) return c_init(cstr_iter){NULL};
- return c_init(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}};
+ if (!sv.size) return c_INIT(cstr_iter){NULL};
+ return c_INIT(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}};
}
STC_INLINE cstr_iter cstr_end(const cstr* self) {
- (void)self; return c_init(cstr_iter){NULL};
+ (void)self; return c_INIT(cstr_iter){NULL};
}
STC_INLINE void cstr_next(cstr_iter* it) {
it->ref += it->u8.chr.size;
@@ -283,7 +282,7 @@ STC_INLINE bool cstr_iequals(const cstr* self, const char* str)
STC_INLINE size_t cstr_find(const cstr* self, const char* search) {
const char *str = cstr_str(self), *res = strstr((char*)str, search);
- return res ? (size_t)(res - str) : cstr_npos;
+ return res ? (size_t)(res - str) : c_NPOS;
}
STC_API size_t cstr_find_sv(const cstr* self, csview search);
@@ -296,7 +295,7 @@ STC_INLINE bool cstr_contains(const cstr* self, const char* search)
{ return strstr((char*)cstr_str(self), search) != NULL; }
STC_INLINE bool cstr_contains_sv(const cstr* self, csview search)
- { return cstr_find_sv(self, search) != cstr_npos; }
+ { return cstr_find_sv(self, search) != c_NPOS; }
STC_INLINE bool cstr_contains_s(const cstr* self, cstr search)
{ return strstr((char*)cstr_str(self), cstr_str(&search)) != NULL; }
@@ -450,7 +449,7 @@ STC_DEF uint64_t cstr_hash(const cstr *self) {
STC_DEF size_t cstr_find_sv(const cstr* self, csview search) {
csview sv = cstr_sv(self);
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
- return res ? (size_t)(res - sv.str) : cstr_npos;
+ return res ? (size_t)(res - sv.str) : c_NPOS;
}
STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t pos2) {
@@ -522,9 +521,9 @@ STC_DEF void cstr_resize(cstr* self, const size_t size, const char value) {
STC_DEF size_t cstr_find_at(const cstr* self, const size_t pos, const char* search) {
csview sv = cstr_sv(self);
- if (pos > sv.size) return cstr_npos;
+ if (pos > sv.size) return c_NPOS;
const char* res = strstr((char*)sv.str + pos, search);
- return res ? (size_t)(res - sv.str) : cstr_npos;
+ return res ? (size_t)(res - sv.str) : c_NPOS;
}
STC_DEF char* cstr_assign_n(cstr* self, const char* str, const size_t len) {
@@ -568,7 +567,7 @@ STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) {
STC_DEF cstr
cstr_replace_sv(csview in, csview search, csview repl, unsigned count) {
- cstr out = cstr_null;
+ cstr out = cstr_NULL;
size_t from = 0; char* res;
if (!count) count = ~0U;
if (search.size)
@@ -627,7 +626,7 @@ STC_DEF size_t cstr_vfmt(cstr* self, size_t start, const char* fmt, va_list args
#endif
STC_DEF cstr cstr_from_fmt(const char* fmt, ...) {
- cstr s = cstr_null;
+ cstr s = cstr_NULL;
va_list args;
va_start(args, fmt);
cstr_vfmt(&s, 0, fmt, args);
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 4bd37173..e0f2ad0e 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -27,19 +27,17 @@
#include "forward.h"
#include "utf8.h"
-#define csview_null c_sv("")
-#define csview_npos (SIZE_MAX >> 1)
-
-#define csview_init() csview_null
-#define csview_drop c_default_drop
-#define csview_clone c_default_clone
-#define csview_from_n c_sv
+#define csview_NULL c_sv1("")
+#define csview_init() csview_NULL
+#define csview_drop(p) c_default_drop(p)
+#define csview_clone(sv) c_default_clone(sv)
+#define csview_from_n(str, n) c_sv2(str, n)
STC_API size_t csview_find_sv(csview sv, csview search);
STC_INLINE csview csview_from(const char* str)
- { return c_init(csview){str, strlen(str)}; }
-STC_INLINE void csview_clear(csview* self) { *self = csview_null; }
+ { return c_INIT(csview){str, strlen(str)}; }
+STC_INLINE void csview_clear(csview* self) { *self = csview_NULL; }
STC_INLINE size_t csview_size(csview sv) { return sv.size; }
STC_INLINE bool csview_empty(csview sv) { return sv.size == 0; }
@@ -51,7 +49,7 @@ STC_INLINE size_t csview_find(csview sv, const char* str)
{ return csview_find_sv(sv, c_sv(str, strlen(str))); }
STC_INLINE bool csview_contains(csview sv, const char* str)
- { return csview_find(sv, str) != csview_npos; }
+ { return csview_find(sv, str) != c_NPOS; }
STC_INLINE bool csview_starts_with(csview sv, const char* str) {
size_t n = strlen(str);
@@ -77,12 +75,12 @@ STC_INLINE csview csview_slice(csview sv, size_t p1, size_t p2) {
/* utf8 iterator */
STC_INLINE csview_iter csview_begin(const csview* self) {
- if (!self->size) return c_init(csview_iter){NULL};
- return c_init(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)},
+ if (!self->size) return c_INIT(csview_iter){NULL};
+ return c_INIT(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)},
self->str + self->size}};
}
STC_INLINE csview_iter csview_end(const csview* self) {
- return c_init(csview_iter){.u8 = {{NULL}, self->str + self->size}};
+ return c_INIT(csview_iter){.u8 = {{NULL}, self->str + self->size}};
}
STC_INLINE void csview_next(csview_iter* it) {
it->ref += it->u8.chr.size;
@@ -164,7 +162,7 @@ STC_API uint64_t csview_hash(const csview *self);
STC_DEF size_t csview_find_sv(csview sv, csview search) {
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
- return res ? (size_t)(res - sv.str) : csview_npos;
+ return res ? (size_t)(res - sv.str) : c_NPOS;
}
STC_DEF uint64_t csview_hash(const csview *self)
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 7a674228..ae6e452c 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -196,11 +196,11 @@ _cx_memb(_at_mut)(_cx_self* self, const size_t idx) {
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
size_t n = self->_len;
- return c_init(_cx_iter){n ? self->data : NULL, self->data + n};
+ return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n};
}
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_init(_cx_iter){NULL, self->data + self->_len}; }
+ { return c_INIT(_cx_iter){NULL, self->data + self->_len}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it)
{ if (++it->ref == it->end) it->ref = NULL; }
@@ -325,7 +325,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) {
memmove(pos + n, pos, (self->_len - idx)*sizeof *pos);
self->_len += n;
}
- return c_init(_cx_iter){pos, self->data + self->_len};
+ return c_INIT(_cx_iter){pos, self->data + self->_len};
}
STC_DEF _cx_iter
@@ -345,7 +345,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) {
{ i_keydrop(p); }
memmove(p1, p2, (size_t)(end - p2)*sizeof *p1);
self->_len -= len;
- return c_init(_cx_iter){p2 == end ? NULL : p1, end - len};
+ return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len};
}
#if !defined i_no_clone