39 lines
1.1 KiB
C
39 lines
1.1 KiB
C
|
#ifndef _fencer_list_h
|
||
|
#define _fencer_list_h
|
||
|
|
||
|
#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);
|
||
|
extern List list_copy(const List* source);
|
||
|
extern void list_empty(List* list);
|
||
|
|
||
|
extern void list_reserve(List* self, size_t at_least);
|
||
|
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);
|
||
|
|
||
|
extern size_t list_contains(List* self, void* query);
|
||
|
|
||
|
#define list_from_type(T) list_init(sizeof(T))
|
||
|
#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)))
|
||
|
|
||
|
#endif // !_fencer_list_h
|