#ifndef INCLUDED_C_MAXPQ_H #define INCLUDED_C_MAXPQ_H #ifndef INCLUDED_C_TYPES_H #include #endif /*INCLUDED_C_TYPES_H*/ #ifndef INCLUDED_C_SORTCOMPARE_H #include #endif /*INCLUDED_C_SORTCOMPARE_H*/ #ifndef INCLUDED_C_ALLOCATOR_H #include #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_MaxPQ_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ c_err_t c_MaxPQ_Init(c_MaxPQ_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_MaxPQ_Push(c_MaxPQ_t* pq, const void* item); c_err_t c_MaxPQ_Pop(c_MaxPQ_t* pq, void* out_item); c_err_t c_MaxPQ_Peek(const c_MaxPQ_t* pq, void* out_item); void c_MaxPQ_Destroy(c_MaxPQ_t* pq); C_STATIC_FORCE_INLINE c_size_t c_MaxPQ_Size(c_MaxPQ_t* pq) { if (!pq) return 0; return pq->size; } C_STATIC_FORCE_INLINE bool c_MaxPQ_IsEmpty(c_MaxPQ_t* pq) { if (!pq) return true; return pq->size == 0; } #endif /*INCLUDED_C_MAXPQ_H*/