开始设计
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#ifndef INCLUDED_C_LINKDQUEUE_H
|
||||
#define INCLUDED_C_LINKDQUEUE_H
|
||||
|
||||
#ifndef INCLUDED_C_BASE_H
|
||||
#include <c_Base.h>
|
||||
#endif /*INCLUDED_C_BASE_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct c_LinkDQueueNode_t {
|
||||
void* data;
|
||||
struct c_LinkDQueueNode_t* prev;
|
||||
struct c_LinkDQueueNode_t* next;
|
||||
} c_LinkDQueueNode_t;
|
||||
|
||||
// 雙端佇列控制結構
|
||||
typedef struct {
|
||||
c_LinkDQueueNode_t* head;
|
||||
c_LinkDQueueNode_t* tail;
|
||||
int obj_size;
|
||||
c_size_t size;
|
||||
} c_LinkDQueue_t;
|
||||
|
||||
// 雙端佇列迭代器(維持指標的指標設計,預設從 head 往 tail 走訪)
|
||||
typedef struct {
|
||||
c_LinkDQueue_t* dqueue;
|
||||
c_LinkDQueueNode_t** node;
|
||||
} c_LinkDQueueIter_t;
|
||||
|
||||
// 核心函數宣告
|
||||
c_err_t c_LinkDQueue_Init(c_LinkDQueue_t* self, int obj_size);
|
||||
void c_LinkDQueue_Destroy(c_LinkDQueue_t* self);
|
||||
|
||||
c_err_t c_LinkDQueue_PushHead(c_LinkDQueue_t* self, void* obj);
|
||||
c_err_t c_LinkDQueue_PushTail(c_LinkDQueue_t* self, void* obj);
|
||||
|
||||
c_err_t c_LinkDQueue_PopHead(c_LinkDQueue_t* self, void* obj);
|
||||
c_err_t c_LinkDQueue_PopTail(c_LinkDQueue_t* self, void* obj);
|
||||
|
||||
void* c_LinkDQueue_PeekHead(c_LinkDQueue_t* self);
|
||||
void* c_LinkDQueue_PeekTail(c_LinkDQueue_t* self);
|
||||
|
||||
void c_LinkDQueueIter_Remove(c_LinkDQueueIter_t* self);
|
||||
|
||||
// 迭代器內聯函數
|
||||
C_STATIC_FORCE_INLINE
|
||||
void c_LinkDQueueIter_Init(c_LinkDQueueIter_t* self, c_LinkDQueue_t* dqueue) {
|
||||
if (!self || !dqueue) return;
|
||||
self->dqueue = dqueue;
|
||||
self->node = &dqueue->head;
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
c_bool_t c_LinkDQueueIter_HasNext(c_LinkDQueueIter_t* self) {
|
||||
if (!self) return C_FALSE;
|
||||
return (self->node != NULL) && (*(self->node) != NULL);
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE
|
||||
void* c_LinkDQueueIter_Next(c_LinkDQueueIter_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_LinkDQueueIter_Get(c_LinkDQueueIter_t* self) {
|
||||
if (!self || !self->node || !*(self->node)) return NULL;
|
||||
return (*(self->node))->data;
|
||||
}
|
||||
|
||||
void c_LinkDQueueIter_Remove(c_LinkDQueueIter_t* self);
|
||||
|
||||
#endif /*INCLUDED_C_LINKDQUEUE_H*/
|
||||
Reference in New Issue
Block a user