main
 1#ifndef KC_HEADER_ARRAY_INCLUDED
 2#define KC_HEADER_ARRAY_INCLUDED
 3
 4#include "./types.h"
 5
 6#define DECLARE_DYNAMIC_ARRAY(T)                                    \
 7	typedef struct _##T##Arr {                                   \
 8		u64 len;  /* length */                                    \
 9		u64 cap; /* capacity*/                                    \
10		T data[];                                                 \
11	} T##Arr;                                                    \
12                                                                    \
13status T##Arr_create( T##Arr *out, u64 capacity );              \
14void T##Arr_destroy( T##Arr *array );                           \
15                                                                    \
16status T##Arr_push( T##Arr *array, T *in);                      \
17status T##Arr_pop( T##Arr *array, T *out );                     \
18                                                                    \
19status T##Arr_add_at( T##Arr *array, u64 index, T *in);         \
20status T##Arr_remove_at( T##Arr *array, u64 index, T *out);     \
21                                                                    \
22
23#define DEFINE_DYNAMIC_ARRAY(T)                                     \
24                                                                    \
25status T##Arr_create( T##Arr *out, u64 capacity );              \
26	\
27}                                                                   \
28                                                                    \
29void T##Arr_destroy( T##Arr *array );                           \
30	\
31}                                                                   \
32                                                                    \
33status T##Arr_push( T##Arr *array, T *in);                      \
34	\
35}                                                                   \
36                                                                    \
37status T##Arr_pop( T##Arr *array, T *out );                     \
38	\
39}                                                                   \
40                                                                    \
41status T##Arr_add_at( T##Arr *array, u64 index, T *in);         \
42	\
43}                                                                   \
44                                                                    \
45status T##Arr_remove_at( T##Arr *array, u64 index, T *out);     \
46	\
47}                                                                   \
48
49
50// Decided to drop this idea for now. Maybe when I actually find a use for it I'll add it
51// #define DECLARE_DYNAMIC_ARRAY_WITH_FREELIST(T)                                \
52// ASSERT(sizeof(T) >= sizeof(u64)) /* Make sure we can store a next index */    \
53// typedef struct _##T##ArrFl {                                                \
54// 	u64 freelist; /* index + 1 so 0 means no freelist */                     \
55// 	T##Arr array;                                                          \
56// };                                                                            \
57//                                                                               \
58// status T##ArrFl_add( T##Arr *array, T *in);                               \
59// status T##ArrFl_remove( T##Arr *array, u64 index, T *out);                \
60//                                                                               \
61// 
62// 
63// DECLARE_DYNAMIC_ARRAY(int);
64// //DECLARE_DYNAMIC_ARRAY_WITH_FREELIST(u64);
65
66
67
68#endif