开始设计
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#ifndef INCLUDED_C_LINKQUEUE_H
|
||||
#define INCLUDED_C_LINKQUEUE_H
|
||||
|
||||
#ifndef INCLUDED_C_BASE_H
|
||||
#include <c_Base.h>
|
||||
#endif /*INCLUDED_C_BASE_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct c_LinkQueueNode_t {
|
||||
void* data;
|
||||
struct c_LinkQueueNode_t * next;
|
||||
}c_LinkQueueNode_t;
|
||||
|
||||
typedef struct {
|
||||
c_LinkQueueNode_t* head;
|
||||
c_LinkQueueNode_t* tail;
|
||||
int obj_size;
|
||||
c_size_t size;
|
||||
}c_LinkQueue_t;
|
||||
|
||||
typedef struct {
|
||||
c_LinkQueue_t* queue;
|
||||
c_LinkQueueNode_t** node;
|
||||
}c_LinkQueueIter_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_err_t c_LinkQueue_Init(c_LinkQueue_t* self, int obj_size);
|
||||
|
||||
void c_LinkQueue_Destroy(c_LinkQueue_t* self);
|
||||
|
||||
c_err_t c_LinkQueue_Push(c_LinkQueue_t* self, void* obj);
|
||||
|
||||
c_err_t c_LinkQueue_Pop(c_LinkQueue_t* self, void* obj);
|
||||
|
||||
c_err_t c_LinkQueue_Peek(c_LinkQueue_t* self, void* obj);
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
void c_LinkQueueIter_Init(c_LinkQueueIter_t* self, c_LinkQueue_t* queue) {
|
||||
if (!self || !queue) return;
|
||||
self->queue = queue;
|
||||
self->node = &queue->head;
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
c_bool_t c_LinkQueueIter_HasNext(c_LinkQueueIter_t* self) {
|
||||
if (!self) return C_FALSE;
|
||||
return (self->node != NULL) && (*(self->node) != NULL);
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
void* c_LinkQueueIter_Next(c_LinkQueueIter_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_LinkQueueIter_Get(c_LinkQueueIter_t* self) {
|
||||
if (!self || !self->node || !*(self->node)) return NULL;
|
||||
return (*(self->node))->data;
|
||||
}
|
||||
|
||||
void c_LinkQueueIter_Remove(c_LinkQueueIter_t* self);
|
||||
|
||||
#endif /*INCLUDED_C_LINKQUEUE_H*/
|
||||
Reference in New Issue
Block a user