2026-08-29 01:50:50 +08:00
|
|
|
#ifndef INCLUDED_C_ARRAYQUEUE_H
|
|
|
|
|
#define INCLUDED_C_ARRAYQUEUE_H
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_C_TYPES_H
|
|
|
|
|
#include <c_Types.h>
|
|
|
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
#ifndef INCLUDED_C_ALLOCATOR_H
|
|
|
|
|
#include <c_Allocator.h>
|
|
|
|
|
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
2026-08-29 01:50:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
|
|
|
/* */
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2026-08-30 01:48:03 +08:00
|
|
|
void* array; // 连续的动态环形缓冲区
|
|
|
|
|
c_size_t item_size; // 单个元素的字节大小
|
|
|
|
|
c_size_t capacity; // 环形缓冲区当前最大可承纳的元素容量
|
|
|
|
|
c_size_t size; // 当前队列中已有的元素个数
|
|
|
|
|
c_size_t head; // 指向队头元素的索引
|
|
|
|
|
c_size_t tail; // 指向队尾下一个待插入坑位的索引
|
|
|
|
|
c_Allocator_t allocator; // 绑定的内存管理器(支持自定义/伙伴系统)
|
|
|
|
|
} c_ArrayQueue_t;
|
2026-08-29 01:50:50 +08:00
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
|
|
|
/* */
|
2026-08-29 01:50:50 +08:00
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
c_err_t c_ArrayQueue_Init(c_ArrayQueue_t* self, c_size_t item_size, c_size_t capacity, c_Allocator_t* allocator);
|
2026-08-29 01:50:50 +08:00
|
|
|
void c_ArrayQueue_Destroy(c_ArrayQueue_t* self);
|
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
// 核心队列操作 API
|
|
|
|
|
c_err_t c_ArrayQueue_Enqueue(c_ArrayQueue_t* self, const void* item);
|
|
|
|
|
c_err_t c_ArrayQueue_Dequeue(c_ArrayQueue_t* self, void* out_item);
|
|
|
|
|
void* c_ArrayQueue_Peek(const c_ArrayQueue_t* self);
|
|
|
|
|
c_err_t c_ArrayQueue_Resize(c_ArrayQueue_t* self, c_size_t new_capacity);
|
2026-08-29 01:50:50 +08:00
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
// 内联高频辅助接口
|
|
|
|
|
C_STATIC_FORCE_INLINE
|
|
|
|
|
c_size_t c_ArrayQueue_Size(const c_ArrayQueue_t* self) {
|
|
|
|
|
if (!self) return 0;
|
|
|
|
|
return self->size;
|
|
|
|
|
}
|
2026-08-29 01:50:50 +08:00
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
C_STATIC_FORCE_INLINE
|
|
|
|
|
bool c_ArrayQueue_IsEmpty(const c_ArrayQueue_t* self) {
|
|
|
|
|
return c_ArrayQueue_Size(self) == 0;
|
|
|
|
|
}
|
2026-08-29 01:50:50 +08:00
|
|
|
|
|
|
|
|
#endif /*INCLUDED_C_ARRAYQUEUE_H*/
|