Foundations
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#ifndef INCLUDED_C_LINKSTACK_H
|
||||
#define INCLUDED_C_LINKSTACK_H
|
||||
|
||||
#ifndef INCLUDED_C_TYPES_H
|
||||
#include <c_Types.h>
|
||||
#endif /*INCLUDED_C_TYPES_H*/
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
|
||||
typedef struct c_LinkStackNode_t {
|
||||
void* data;
|
||||
struct c_LinkStackNode_t* next;
|
||||
} c_LinkStackNode_t;
|
||||
|
||||
typedef struct {
|
||||
c_LinkStackNode_t* head;
|
||||
int obj_size;
|
||||
c_size_t size;
|
||||
} c_LinkStack_t;
|
||||
|
||||
typedef struct {
|
||||
c_LinkStack_t* stack;
|
||||
c_LinkStackNode_t** node;
|
||||
} c_LinkStackIter_t;
|
||||
|
||||
c_err_t c_LinkStack_Init(c_LinkStack_t* self, int obj_size);
|
||||
void c_LinkStack_Destroy(c_LinkStack_t* self);
|
||||
c_err_t c_LinkStack_Push(c_LinkStack_t* self, void* obj);
|
||||
c_err_t c_LinkStack_Pop(c_LinkStack_t* self, void* obj);
|
||||
void* c_LinkStack_Peek(c_LinkStack_t* self);
|
||||
|
||||
// 迭代器內聯函數實作
|
||||
C_STATIC_FORCE_INLINE
|
||||
void c_LinkStackIter_Init(c_LinkStackIter_t* self, c_LinkStack_t* stack) {
|
||||
if (!self || !stack) return;
|
||||
self->stack = stack;
|
||||
self->node = &stack->head;
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
c_bool_t c_LinkStackIter_HasNext(c_LinkStackIter_t* self) {
|
||||
if (!self) return C_FALSE;
|
||||
return (self->node != NULL) && (*(self->node) != NULL);
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
void* c_LinkStackIter_Next(c_LinkStackIter_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_LinkStackIter_Get(c_LinkStackIter_t* self) {
|
||||
if (!self || !self->node || !*(self->node)) return NULL;
|
||||
return (*(self->node))->data;
|
||||
}
|
||||
|
||||
void c_LinkStackIter_Remove(c_LinkStackIter_t* self);
|
||||
|
||||
#endif /*INCLUDED_C_LINKSTACK_H*/
|
||||
Reference in New Issue
Block a user