unicstl/include/heap.h
jf-home 26eeb65cc9 refactor(core)!: 重构链表核心API,增加 const 正确性与自定义断言
- 将所有打印和比较函数的参数指针从 `void*` 修改为 `const void*`,增强类型安全
- 引入自定义断言宏 `unicstl_assert` 及其实现,替换标准 `assert`
- 优化动态数组容量增长策略,新增 `unicstl_new_capacity` 函数
- 重构链表 接口:`push`/`pop` 重命名为 `push_back`/`pop_front`,新增 `push_front`/`pop_back`/`insert`/`remove`/`contains` 方法
- 移除链表结构体中未使用的 `_index_front` 和 `_index_back` 成员
- 在头文件中补充关键函数的时间复杂度注释
2026-05-12 02:26:21 +08:00

67 lines
1.4 KiB
C

/**
* @file heap.h
* @author wenjf (Orig5826@163.com)
* @brief
* @version 0.1
* @date 2024-07-03
*
* @copyright Copyright (c) 2024
*
*/
#ifndef _HEAP_H_
#define _HEAP_H_
#include "unicstl_internal.h"
typedef enum
{
HEAP_MIN = 0,
HEAP_MAX = 1,
}heap_type;
struct _heap
{
// -------------------- private --------------------
void* obj;
uint32_t _size;
uint32_t _obj_size;
uint32_t _capacity;
uint32_t _ratio;
heap_type _type;
struct _iterator _iter;
void (*_destory)(struct _heap* self);
// -------------------- public --------------------
// kernel
bool (*push)(struct _heap* self, void* obj);
bool (*pop)(struct _heap* self, void* obj);
bool (*peek)(struct _heap* self, void* obj);
// base
bool (*empty)(struct _heap* self);
uint32_t(*size)(struct _heap* self);
bool (*clear)(struct _heap* self);
// iter
iterator_t (*iter)(struct _heap* self);
// config
compare_fun_t compare; // !!! you have to implement this function
// -------------------- debug --------------------
void (*print)(struct _heap* self);
void (*print_obj)(const void* obj);
};
typedef struct _heap* heap_t;
// create and free heap
heap_t heap_max_new2(uint32_t obj_size, uint32_t capacity);
heap_t heap_min_new2(uint32_t obj_size, uint32_t capacity);
void heap_free(heap_t* heap);
#endif // _HEAP_H_