Foundations
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#ifndef INCLUDED_C_LINKLIST_H
|
||||
#define INCLUDED_C_LINKLIST_H
|
||||
|
||||
#ifndef INCLUDED_C_TYPES_H
|
||||
#include <c_Types.h>
|
||||
#endif /*INCLUDED_C_TYPES_H*/
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct c_LinkListNode_t {
|
||||
void* data;
|
||||
struct c_LinkListNode_t* next;
|
||||
}c_LinkListNode_t;
|
||||
|
||||
typedef struct {
|
||||
c_LinkListNode_t* head;
|
||||
int obj_size;
|
||||
c_size_t size;
|
||||
}c_LinkList_t;
|
||||
|
||||
typedef struct {
|
||||
c_LinkList_t* list;
|
||||
c_LinkListNode_t** node;
|
||||
}c_LinkListIter_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_err_t c_LinkList_Init(c_LinkList_t* self, c_size_t obj_size);
|
||||
|
||||
void c_LinkList_Destroy(c_LinkList_t* self);
|
||||
|
||||
c_err_t c_LinkList_Add(c_LinkList_t* self, void* obj);
|
||||
|
||||
c_err_t c_LinkList_Remove(c_LinkList_t* self, void* obj);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
void c_LinkListIter_Init(c_LinkListIter_t* self, c_LinkList_t* list) {
|
||||
if (!self || !list) return;
|
||||
self->list = list;
|
||||
self->node = &list->head;
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
c_bool_t c_LinkListIter_HasNext(c_LinkListIter_t* self) {
|
||||
if (!self) return C_FALSE;
|
||||
return (self->node != NULL) && (*(self->node) != NULL);
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
void* c_LinkListIter_Next(c_LinkListIter_t* self) {
|
||||
if (!self || !self->node || !*(self->node)) return NULL;
|
||||
void* data = (*(self->node))->data;
|
||||
self->node = &(*(self->node))->next;
|
||||
return data;
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
void* c_LinkListIter_Get(c_LinkListIter_t* self) {
|
||||
if (!self || !self->node || !*(self->node)) return NULL;
|
||||
return (*(self->node))->data;
|
||||
}
|
||||
|
||||
void c_LinkListIter_Remove(c_LinkListIter_t* self);
|
||||
|
||||
#endif /*INCLUDED_C_LINKLIST_H*/
|
||||
Reference in New Issue
Block a user