#ifndef TEENSY_LIST_H_ #define TEENSY_LIST_H_ #include "teensy_common.h" #include "teensy_mem.h" #define TY_LIST_MIN_CAP 8 #define TY_LIST_GROW_RATE 2 #define ty_list_last(arr) ((arr)->items[(arr)->len - 1]) #define ty_list_reserve(arr, amt) \ do { \ if ((amt) > (arr)->cap) { \ (arr)->cap = ty_max(TY_LIST_MIN_CAP, (arr)->cap); \ while ((arr)->cap < (amt)) \ (arr)->cap *= TY_LIST_GROW_RATE; \ \ (arr)->items = ty_realloc( \ (arr)->items, \ sizeof(*(arr)->items) * (arr)->cap \ ); \ } \ } while (0) #define ty_list_append(arr, elem) \ do { \ ty_list_reserve(arr, (arr)->len + 1); \ (arr)->items[(arr)->len++] = (elem); \ } while (0) #define ty_list_clear(arr) ((arr)->len = 0) #define ty_list_free(arr) ty_free((arr)->items) #endif // TEENSY_LIST_H_