28 lines
664 B
C
28 lines
664 B
C
#ifndef DA_H_
|
|
#define DA_H_
|
|
|
|
#include <stdlib.h>
|
|
|
|
#define da_append(da, item) \
|
|
do { \
|
|
if ((da)->count == 0) { \
|
|
(da)->capacity = 1; \
|
|
(da)->items = malloc(sizeof(item)*sizeof((da)->capacity)); \
|
|
} else { \
|
|
if ((da)->count == (da)->capacity) { \
|
|
(da)->capacity *= 2; \
|
|
(da)->items = realloc((da)->items, (da)->capacity * sizeof((item))); \
|
|
} \
|
|
} \
|
|
(da)->items[(da)->count++] = (item); \
|
|
} while(0)
|
|
|
|
#define da_deinit(da) \
|
|
do { \
|
|
if ((da)->count > 0) { \
|
|
free((da)->items); \
|
|
} \
|
|
} while(0)
|
|
|
|
#endif // DA_H_
|