blob: 7a45d4ec86574f43dd15d9063efb7585faf10086 (
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
|
#ifndef DYN_ARR_H_
#define DYN_ARR_H_
#include "common.h"
#define TY_LIST_MIN_CAP 8
#define TY_LIST_GROW_RATE 2
#define ty_list_create(T, init_capacity) \
((T*)_ty_list_create(sizeof(T), init_capacity))
#define ty_list_len_ptr(arr) ((int*)arr - 2)
#define ty_list_len(arr) (*ty_list_len_ptr(arr))
#define ty_list_cap_ptr(arr) ((int*)arr - 1)
#define ty_list_cap(arr) (*ty_list_cap_ptr(arr))
#define ty_list_base(arr) ((void*)ty_list_len_ptr(arr))
#define ty_list_append_slot(T, arr) \
((T*)_ty_list_append_slot(sizeof(T), (void**)arr))
#define ty_list_append(T, arr, elem) \
(*ty_list_append_slot(T, arr) = elem)
#define ty_list_clear(arr) \
(*ty_list_len_ptr(arr) = 0)
void *_ty_list_create(size_t type_size, int init_cap);
void *_ty_list_append_slot(size_t type_size, void **arr);
void ty_list_free(void *arr);
#endif // DYN_ARR_H_
|