summaryrefslogtreecommitdiffhomepage
path: root/include/stc/forward.h
blob: 78bc91737a9138a452adcb3c98dc1c8b90930a04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* MIT License
 *
 * Copyright (c) 2021 Tyge Løvset, NORCE, www.norceresearch.no
 *
 * 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 <stddef.h>

#define forward_carray2(TAG, VAL) _c_carray2_types(carray2##TAG, VAL)
#define forward_carray3(TAG, VAL) _c_carray3_types(carray2##TAG, VAL)
#define forward_cdeq(TAG, VAL) _c_cdeq_types(cdeq_##TAG, VAL)
#define forward_clist(TAG, VAL) _c_clist_types(clist_##TAG, VAL)
#define forward_cmap(TAG, KEY, VAL) _c_chash_types(cmap_##TAG, KEY, VAL, c_true, c_false)
#define forward_csmap(TAG, KEY, VAL) _c_aatree_types(csmap_##TAG, KEY, VAL, c_true, c_false)
#define forward_cset(TAG, KEY) _c_chash_types(cset_##TAG, cset, KEY, KEY, c_false, c_true)
#define forward_csset(TAG, KEY) _c_aatree_types(csset_##TAG, KEY, KEY, c_false, c_true)
#define forward_csptr(TAG, VAL) _csptr_types(csptr_##TAG, VAL)
#define forward_cpque(TAG, VAL) _c_cpque_types(cpque_##TAG, VAL)
#define forward_cstack(TAG, VAL) _c_cstack_types(cstack_##TAG, VAL)
//#define forward_cqueue(TAG, VAL) _c_cqueue_types(cqueue_##TAG, VAL)
#define forward_cvec(TAG, VAL) _c_cvec_types(cvec_##TAG, VAL)

#ifndef MAP_SIZE_T
#define MAP_SIZE_T uint32_t
#endif
#define c_true(...) __VA_ARGS__
#define c_false(...)

#define _c_carray2_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
    typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
    typedef struct { SELF##_value_t **data; size_t xdim, ydim; } SELF

#define _c_carray3_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
    typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
    typedef struct { SELF##_value_t ***data; size_t xdim, ydim, zdim; } SELF

#define _c_cdeq_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
    typedef struct {SELF##_value_t *ref; } SELF##_iter_t; \
    typedef struct {SELF##_value_t *_base, *data;} SELF

#define _c_clist_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
    typedef struct SELF##_node_t SELF##_node_t; \
\
    typedef struct { \
        SELF##_node_t *const *_last, *prev; \
        SELF##_value_t *ref; \
    } SELF##_iter_t; \
\
    typedef struct { \
        SELF##_node_t *last; \
    } SELF

#define _c_chash_types(SELF, KEY, VAL, MAP_ONLY, SET_ONLY) \
    typedef KEY SELF##_key_t; \
    typedef VAL SELF##_mapped_t; \
    typedef MAP_SIZE_T SELF##_size_t; \
\
    typedef SET_ONLY( SELF##_key_t ) \
            MAP_ONLY( struct SELF##_value_t ) \
    SELF##_value_t; \
\
    typedef struct { \
        SELF##_value_t *ref; \
        bool inserted; \
    } SELF##_result_t; \
\
    typedef struct { \
        SELF##_value_t *ref; \
        uint8_t* _hx; \
    } SELF##_iter_t; \
\
    typedef struct { \
        SELF##_value_t* table; \
        uint8_t* _hashx; \
        SELF##_size_t size, bucket_count; \
        float max_load_factor; \
    } SELF

#define _c_aatree_types(SELF, KEY, VAL, MAP_ONLY, SET_ONLY) \
    typedef KEY SELF##_key_t; \
    typedef VAL SELF##_mapped_t; \
    typedef MAP_SIZE_T SELF##_size_t; \
    typedef struct SELF##_node_t SELF##_node_t; \
\
    typedef SET_ONLY( SELF##_key_t ) \
            MAP_ONLY( struct SELF##_value_t ) \
    SELF##_value_t; \
\
    typedef struct { \
        SELF##_value_t *ref; \
        bool inserted; \
    } SELF##_result_t; \
\
    typedef struct { \
        SELF##_value_t *ref; \
        SELF##_node_t *_d; \
        int _top; \
        SELF##_size_t _tn, _st[36]; \
    } SELF##_iter_t; \
\
    typedef struct { \
        SELF##_node_t *nodes; \
    } SELF

#define _csptr_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
\
    typedef struct { \
        SELF##_value_t* get; \
        long* use_count; \
    } SELF

#define _c_cstack_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
    typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
    typedef struct SELF { \
        SELF##_value_t* data; \
        size_t size, capacity; \
    } SELF

#define _c_cpque_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
    typedef struct SELF { \
        SELF##_value_t* data; \
        size_t size, capacity; \
    } SELF

#define _c_cvec_types(SELF, VAL) \
    typedef VAL SELF##_value_t; \
    typedef struct { SELF##_value_t *ref; } SELF##_iter_t; \
    typedef struct { SELF##_value_t *data; } SELF

#endif // STC_FORWARD_H_INCLUDED