/* ihex Copyright (C) 2025 Thomas Albers Raviola This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef ARRAY_H #define ARRAY_H #include struct array { size_t length; size_t elem_size; size_t capacity; void *data; }; void init_array(struct array *arr, size_t elem_size); void free_array(struct array *arr); void * array_append(struct array *arr, const void *data); void array_remove(struct array *arr, size_t n, void *dest); void array_sort(struct array *arr, int (*compar)(const void *, const void *)); void * array_search(struct array *arr, const void *key, int (*compar)(const void *, const void *)); static inline void * array_elt(struct array *arr, size_t n) { return (void *)((char *)arr->data + n * arr->elem_size); } #define ARRAY_ELT(ARRAY, TYPE, N) ((TYPE *)(ARRAY)->data)[N] #endif /* ARRAY_H */