开始设计
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#ifndef INCLUDED_C_MINHEAP_H
|
||||
#define INCLUDED_C_MINHEAP_H
|
||||
|
||||
#ifndef INCLUDED_C_BASE_H
|
||||
#include <c_Base.h>
|
||||
#endif /*INCLUDED_C_BASE_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef int (*c_MinHeap_Compare_f)(const void* a, const void* b);
|
||||
|
||||
// 最小堆控制結構體
|
||||
typedef struct {
|
||||
void* array; // 連續記憶體陣列,以平鋪樹(Array-based Tree)方式儲存節點
|
||||
int obj_size; // 每個單個元素的位元組大小
|
||||
c_size_t capacity; // 當前緩衝區可容納的最大元素量
|
||||
c_size_t size; // 目前堆中已儲存的元素數量
|
||||
c_MinHeap_Compare_f compare; // 使用者定義的優先級比較函數
|
||||
} c_MinHeap_t;
|
||||
|
||||
c_err_t c_MinHeap_Init(c_MinHeap_t* self, int obj_size, c_size_t initial_capacity, c_MinHeap_Compare_f compare);
|
||||
void c_MinHeap_Destroy(c_MinHeap_t* self);
|
||||
|
||||
c_err_t c_MinHeap_Push(c_MinHeap_t* self, const void* obj);
|
||||
c_err_t c_MinHeap_Pop(c_MinHeap_t* self, void* out_obj);
|
||||
void* c_MinHeap_Peek(c_MinHeap_t* self);
|
||||
c_size_t c_MinHeap_GetSize(const c_MinHeap_t* self);
|
||||
c_bool_t c_MinHeap_IsEmpty(const c_MinHeap_t* self);
|
||||
|
||||
#endif /*INCLUDED_C_MINHEAP_H*/
|
||||
Reference in New Issue
Block a user