Files
cKit/Sort/c_IndexMaxPQ.h
2026-08-30 22:24:45 +08:00

56 lines
2.1 KiB
C

#ifndef INCLUDED_C_INDEXMAXPQ_H
#define INCLUDED_C_INDEXMAXPQ_H
#ifndef INCLUDED_C_TYPES_H
#include <c_Types.h>
#endif /*INCLUDED_C_TYPES_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 {
c_size_t max_elements; // 允许传入的外部全局唯一索引上限边界
c_size_t size; // 当前容器内有效驻留的索引总个数
c_size_t elem_size; // 单个关联数据元素占用的物理字节大小
c_size_t* pq; // 物理堆数组:pq[i] 代表处于堆物理位置 i 处的用户唯一索引 (index)
c_size_t* qp; // 逆向映射路由:qp[index] 代表外部唯一索引在堆数组中的物理物理下标 (Heap Position)
// 特殊约束:若某个索引未入队,其 qp[index] 的值恒被安全填充为 (c_size_t)-1
char* keys; // 密集关联数据存储块:keys[index * elem_size] 存储该索引对应的真实优先级数据
c_SortCompare_t cmp; // 动态比对器
void* args; // 自定义上下文
c_Allocator_t allocator; // 内联组合分配器实体,支持自适应Fallback缺省
} c_IndexMaxPQ_t;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_err_t c_IndexMaxPQ_Init(c_IndexMaxPQ_t* self, c_size_t max_elements, c_size_t elem_size, c_SortCompare_t cmp, void* args, c_Allocator_t* allocator);
bool c_IndexMaxPQ_Contains(const c_IndexMaxPQ_t* pq, c_size_t index);
c_err_t c_IndexMaxPQ_Push(c_IndexMaxPQ_t* pq, c_size_t index, const void* item);
c_err_t c_IndexMaxPQ_Pop(c_IndexMaxPQ_t* pq, c_size_t* out_index);
c_err_t c_IndexMaxPQ_Change(c_IndexMaxPQ_t* pq, c_size_t index, const void* new_item);
c_err_t c_IndexMaxPQ_Peek(const c_IndexMaxPQ_t* pq, c_size_t* out_index);
void c_IndexMaxPQ_Destroy(c_IndexMaxPQ_t* pq);
#endif /*INCLUDED_C_INDEXMAXPQ_H*/