2024-01-26 21:58:02 +00:00
|
|
|
#ifndef CUTES_LIST_H
|
|
|
|
#define CUTES_LIST_H
|
2024-01-25 13:08:23 +00:00
|
|
|
|
|
|
|
#include "stddef.h"
|
|
|
|
|
|
|
|
typedef struct List List;
|
|
|
|
struct List {
|
|
|
|
void* data;
|
|
|
|
size_t cap;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
size_t element_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern List list_init(size_t element_size);
|
2024-01-26 11:02:56 +00:00
|
|
|
extern List list_with_len(size_t element_size, size_t len);
|
2024-01-25 13:08:23 +00:00
|
|
|
extern List list_copy(const List* source);
|
|
|
|
extern void list_empty(List* list);
|
|
|
|
|
|
|
|
extern void list_reserve(List* self, size_t at_least);
|
2024-01-26 10:49:49 +00:00
|
|
|
extern void list_set_len(List* self, size_t len);
|
2024-01-25 13:08:23 +00:00
|
|
|
extern void* list_at(List* list, size_t at);
|
|
|
|
extern void* list_at_unchecked(List* self, size_t at);
|
|
|
|
|
|
|
|
extern size_t list_add(List* self, void* item);
|
|
|
|
extern void list_insert(List* self, void* item, size_t at);
|
|
|
|
extern void list_erase(List* self, size_t at);
|
|
|
|
|
|
|
|
extern void* list_iterator_begin(List* self);
|
|
|
|
extern void* list_iterator_end(List* self);
|
|
|
|
|
2024-09-10 13:07:19 +00:00
|
|
|
extern size_t list_find(List* self, void* query);
|
2024-01-25 13:08:23 +00:00
|
|
|
|
|
|
|
#define list_from_type(T) list_init(sizeof(T))
|
2024-01-26 11:02:56 +00:00
|
|
|
#define list_from_type_with_len(T, __len) list_with_len(sizeof(T), __len)
|
2024-01-25 13:08:23 +00:00
|
|
|
#define list_foreach(T, iter, list) for(T iter = list_iterator_begin(list); iter != (T)list_iterator_end(list); ++iter)
|
|
|
|
#define list_at_as(T, __list, __i) ((T*)(list_at(__list, __i)))
|
|
|
|
|
|
|
|
#define list_iterator_begin_as(T, __list) ((T*)(list_iterator_begin(__list)))
|
|
|
|
|
2024-01-26 21:58:02 +00:00
|
|
|
#endif // !CUTES_LIST_H
|