Files

51 lines
1.6 KiB
C
Raw Permalink Normal View History

2026-08-30 22:24:45 +08:00
#ifndef INCLUDED_C_MINPQ_H
#define INCLUDED_C_MINPQ_H
#ifndef INCLUDED_C_SORTCOMPARE_H
#include <c_SortCompare.h>
#endif /*INCLUDED_C_SORTCOMPARE_H*/
#ifndef INCLUDED_C_ALLOCATOR_H
#include <c_Allocator.h>
#endif /*INCLUDED_C_ALLOCATOR_H*/
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
typedef struct {
char* data; // 底层动态连续字节流载体
c_size_t capacity; // 当前容器的最大可容纳插槽数
c_size_t size; // 当前已存储的有效元素总数
c_size_t elem_size; // 单个数据元素占用的字节大小 (sizeof)
c_SortCompare_t cmp; // 动态回调比对器
void* args; // 自定义上下文参数指针
c_Allocator_t allocator; // 完全继承非指针内联组合定义与默认缺省机制
} c_MinPQ_t;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_err_t c_MinPQ_Init(c_MinPQ_t* self, c_size_t initial_capacity, c_size_t elem_size, c_SortCompare_t cmp, void* args, c_Allocator_t* allocator);
c_err_t c_MinPQ_Push(c_MinPQ_t* pq, const void* item);
c_err_t c_MinPQ_Pop(c_MinPQ_t* pq, void* out_item);
c_err_t c_MinPQ_Peek(const c_MinPQ_t* pq, void* out_item);
void c_MinPQ_Destroy(c_MinPQ_t* pq);
C_STATIC_FORCE_INLINE
c_size_t c_MinPQ_Size(c_MinPQ_t* pq) {
if (!pq) return 0;
return pq->size;
}
C_STATIC_FORCE_INLINE
bool c_MinPQ_IsEmpty(c_MinPQ_t* pq) {
if (!pq) return true;
return pq->size == 0;
}
#endif /*INCLUDED_C_MINPQ_H*/