/* MIT License * * Copyright (c) 2023 Tyge Løvset * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef STC_FORWARD_H_INCLUDED #define STC_FORWARD_H_INCLUDED #include #include #define forward_carc(CX, VAL) _c_carc_types(CX, VAL) #define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL) #define forward_cdeq(CX, VAL) _c_cdeq_types(CX, VAL) #define forward_clist(CX, VAL) _c_clist_types(CX, VAL) #define forward_cmap(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, c_true, c_false) #define forward_cset(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, c_false, c_true) #define forward_csmap(CX, KEY, VAL) _c_aatree_types(CX, KEY, VAL, c_true, c_false) #define forward_csset(CX, KEY) _c_aatree_types(CX, KEY, KEY, c_false, c_true) #define forward_cstack(CX, VAL) _c_cstack_types(CX, VAL) #define forward_cpque(CX, VAL) _c_cpque_types(CX, VAL) #define forward_cqueue(CX, VAL) _c_cdeq_types(CX, VAL) #define forward_cvec(CX, VAL) _c_cvec_types(CX, VAL) // csview : non-null terminated string view typedef const char csview_value; typedef struct csview { csview_value* buf; intptr_t size; } csview; typedef union { csview_value* ref; csview chr; struct { csview chr; csview_value* end; } u8; } csview_iter; // crawstr : null-terminated string view typedef csview_value crawstr_value; typedef struct crawstr { crawstr_value* str; intptr_t size; } crawstr; typedef union { crawstr_value* ref; csview chr; struct { csview chr; } u8; // [deprecated] } crawstr_iter; // cstr : null-terminated string (short string optimized - sso) typedef char cstr_value; typedef struct { cstr_value* data; intptr_t size, cap; } cstr_buf; typedef union cstr { struct { cstr_value data[sizeof(cstr_buf) - 1]; unsigned char size; } sml; struct { cstr_value* data; size_t size, ncap; } lon; } cstr; typedef union { cstr_value* ref; csview chr; struct { csview chr; } u8; // [deprecated] } cstr_iter; #define c_true(...) __VA_ARGS__ #define c_false(...) #define _c_carc_types(SELF, VAL) \ typedef VAL SELF##_value; \ typedef struct SELF { \ SELF##_value* get; \ catomic_long* use_count; \ } SELF #define _c_cbox_types(SELF, VAL) \ typedef VAL SELF##_value; \ typedef struct SELF { \ SELF##_value* get; \ } SELF #define _c_cdeq_types(SELF, VAL) \ typedef VAL SELF##_value; \ \ typedef struct SELF { \ SELF##_value *data; \ intptr_t start, end, capmask; \ } SELF; \ \ typedef struct { \ SELF##_value *ref; \ intptr_t pos; \ const SELF* _s; \ } SELF##_iter #define _c_clist_types(SELF, VAL) \ typedef VAL SELF##_value; \ typedef struct SELF##_node SELF##_node; \ \ typedef struct { \ SELF##_value *ref; \ SELF##_node *const *_last, *prev; \ } SELF##_iter; \ \ typedef struct SELF { \ SELF##_node *last; \ } SELF #define _c_chash_types(SELF, KEY, VAL, MAP_ONLY, SET_ONLY) \ typedef KEY SELF##_key; \ typedef VAL SELF##_mapped; \ \ typedef SET_ONLY( SELF##_key ) \ MAP_ONLY( struct SELF##_value ) \ SELF##_value; \ \ typedef struct { \ SELF##_value *ref; \ bool inserted; \ uint8_t hashx; \ } SELF##_result; \ \ typedef struct { \ SELF##_value *ref, *_end; \ struct chash_slot* sref; \ } SELF##_iter; \ \ typedef struct SELF { \ SELF##_value* data; \ struct chash_slot* slot; \ intptr_t size, bucket_count; \ } SELF #define _c_aatree_types(SELF, KEY, VAL, MAP_ONLY, SET_ONLY) \ typedef KEY SELF##_key; \ typedef VAL SELF##_mapped; \ typedef struct SELF##_node SELF##_node; \ \ typedef SET_ONLY( SELF##_key ) \ MAP_ONLY( struct SELF##_value ) \ SELF##_value; \ \ typedef struct { \ SELF##_value *ref; \ bool inserted; \ } SELF##_result; \ \ typedef struct { \ SELF##_value *ref; \ SELF##_node *_d; \ int _top; \ int32_t _tn, _st[36]; \ } SELF##_iter; \ \ typedef struct SELF { \ SELF##_node *nodes; \ int32_t root, disp, head, size, cap; \ } SELF #define _c_cstack_fixed(SELF, VAL, CAP) \ typedef VAL SELF##_value; \ typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct SELF { SELF##_value data[CAP]; intptr_t _len; } SELF #define _c_cstack_types(SELF, VAL) \ typedef VAL SELF##_value; \ typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct SELF { SELF##_value* data; intptr_t _len, _cap; } SELF #define _c_cvec_types(SELF, VAL) \ typedef VAL SELF##_value; \ typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct SELF { SELF##_value *data; intptr_t _len, _cap; } SELF #define _c_cpque_types(SELF, VAL) \ typedef VAL SELF##_value; \ typedef struct SELF { SELF##_value* data; intptr_t _len, _cap; } SELF #endif // STC_FORWARD_H_INCLUDED