mirror of
https://gitee.com/apaki/unicstl.git
synced 2026-05-29 07:04:20 +08:00
- 将所有打印和比较函数的参数指针从 `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` 成员 - 在头文件中补充关键函数的时间复杂度注释
73 lines
1.5 KiB
C
73 lines
1.5 KiB
C
/**
|
|
* @file deque.h
|
|
* @author wenjf (Orig5826@163.com)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2024-06-23
|
|
*
|
|
* @copyright Copyright (c) 2024
|
|
*
|
|
*/
|
|
#ifndef _DEQUE_H_
|
|
#define _DEQUE_H_
|
|
|
|
#include "unicstl_internal.h"
|
|
|
|
enum _deque_order
|
|
{
|
|
DEQUE_FORWARD,
|
|
DEQUE_REVERSE,
|
|
};
|
|
|
|
struct _deque_node
|
|
{
|
|
void* obj;
|
|
struct _deque_node* prev;
|
|
struct _deque_node* next;
|
|
};
|
|
|
|
struct _deque
|
|
{
|
|
// -------------------- private --------------------
|
|
struct _deque_node* _head;
|
|
struct _deque_node* _tail;
|
|
|
|
uint32_t _obj_size;
|
|
uint32_t _size;
|
|
// uint32_t _capacity;
|
|
// uint32_t _ratio;
|
|
|
|
struct _iterator _iter;
|
|
|
|
void (*_destory)(struct _deque* self);
|
|
|
|
// -------------------- public --------------------
|
|
// kernel
|
|
bool (*push_back)(struct _deque* self, void* obj);
|
|
bool (*push_front)(struct _deque* self, void* obj);
|
|
bool (*pop_back)(struct _deque* self, void* obj);
|
|
bool (*pop_front)(struct _deque* self, void* obj);
|
|
bool (*back)(struct _deque* self, void* obj);
|
|
bool (*front)(struct _deque* self, void* obj);
|
|
|
|
// base
|
|
uint32_t(*size)(struct _deque* self);
|
|
bool (*clear)(struct _deque* self);
|
|
bool (*empty)(struct _deque* self);
|
|
|
|
// iter
|
|
iterator_t (*iter)(struct _deque* self, enum _deque_order order);
|
|
|
|
// -------------------- debug --------------------
|
|
void (*print)(struct _deque* self);
|
|
void (*print_obj)(const void* obj);
|
|
};
|
|
typedef struct _deque* deque_t;
|
|
|
|
// create and free deque
|
|
deque_t deque_new(uint32_t obj_size);
|
|
|
|
void deque_free(deque_t* deque);
|
|
|
|
#endif
|