56 lines
2.2 KiB
C
56 lines
2.2 KiB
C
#ifndef INCLUDED_C_INDEXMINPQ_H
|
|||
|
|
#define INCLUDED_C_INDEXMINPQ_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; // 迭代器或外部图允许的最大唯一索引上限 (Index Max Limit)
|
||
|
|
c_size_t size; // 当前优先队列内有效驻留的索引总个数
|
||
|
|
c_size_t elem_size; // 单个关联数据元素占用的物理字节大小 (sizeof)
|
||
|
|
|
||
|
|
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_IndexMinPQ_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
c_err_t c_IndexMinPQ_Init(c_IndexMinPQ_t* self, c_size_t max_elements, c_size_t elem_size, c_SortCompare_t cmp, void* args, c_Allocator_t* allocator);
|
||
|
|
|
||
|
|
bool c_IndexMinPQ_Contains(const c_IndexMinPQ_t* pq, c_size_t index);
|
||
|
|
|
||
|
|
c_err_t c_IndexMinPQ_Push(c_IndexMinPQ_t* pq, c_size_t index, const void* item);
|
||
|
|
|
||
|
|
c_err_t c_IndexMinPQ_Pop(c_IndexMinPQ_t* pq, c_size_t* out_index);
|
||
|
|
|
||
|
|
c_err_t c_IndexMinPQ_Change(c_IndexMinPQ_t* pq, c_size_t index, const void* new_item);
|
||
|
|
|
||
|
|
c_err_t c_IndexMinPQ_Peek(const c_IndexMinPQ_t* pq, c_size_t* out_index);
|
||
|
|
|
||
|
|
void c_IndexMinPQ_Destroy(c_IndexMinPQ_t* pq);
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_INDEXMINPQ_H*/
|