编码统一使用utf8

This commit is contained in:
建峰 2024-08-30 14:18:17 +08:00
parent 349889ea98
commit 170c2a5421
16 changed files with 73 additions and 88 deletions

View File

@ -1,6 +1,6 @@
{
"cmake.configureOnOpen": true,
"files.encoding": "gb18030",
"files.encoding": "utf8",
"files.associations": {
"common.h": "c",
"unicstl.h": "c",

View File

@ -1,11 +1,11 @@
# 0. cmake 最低版本号要求
# 0. cmake 最低版本号要求
cmake_minimum_required(VERSION 3.29)
# 0. 项目信息
# 0. 项目信息
project(demo VERSION 0.0.01)
# 2. 支持GDB
# 2. 支持GDB
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g --std=c99")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall --std=c99")
@ -14,11 +14,11 @@ set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall --std=c99")
set(CMAKE_INSTALL_PREFIX "release")
# 1. 添加头文件路径
# 1. 添加头文件路径
include_directories(include)
include_directories(3rdparty/unicstl-unity/src)
# 1. 添加子目录
# 1. 添加子目录
add_subdirectory(src)
add_subdirectory(demo)
add_subdirectory(3rdparty)

View File

@ -10,7 +10,7 @@
*/
#include "demo.h"
// vs2022 ア默<EFBDB1>袁サ
// if vs2022 has error: 'max': macro redefinition
#ifdef max
#undef max
#endif

View File

@ -1,7 +1,6 @@
# tree
日志
```
----- unicstl test -----

View File

@ -22,13 +22,13 @@ struct _deque_node
struct _deque
{
struct _deque_node* _head; // 头节点
struct _deque_node* _tail; // 尾节点
struct _deque_node* _head;
struct _deque_node* _tail;
uint32_t _obj_size; // 元素大小
uint32_t _size; // 栈大小
// uint32_t _capacity; // 总容量
// uint32_t _ratio; // 扩展比率
uint32_t _obj_size;
uint32_t _size;
// uint32_t _capacity;
// uint32_t _ratio;
// kernel
bool (*push_back)(struct _deque* self, void* obj);

View File

@ -17,12 +17,12 @@ struct _heap
{
void * obj;
uint32_t _size; // 栈大小
uint32_t _obj_size; // 元素大小
uint32_t _capacity; // 总容量
uint32_t _ratio; // 扩展比率
uint32_t _size;
uint32_t _obj_size;
uint32_t _capacity;
uint32_t _ratio;
bool _min_flag; // 最大/小堆标志
bool _min_flag;
// kernel
bool (*peek)(struct _heap* self, void* obj);

View File

@ -17,11 +17,11 @@ struct _list
{
void * obj;
uint32_t _obj_size; // 元素大小
uint32_t _size; // 栈大小
uint32_t _capacity; // 总容量
uint32_t _ratio; // 扩展比率
uint32_t _cur; // 当前索引
uint32_t _obj_size;
uint32_t _size;
uint32_t _capacity;
uint32_t _ratio;
uint32_t _cur;
// kernel
bool (*append)(struct _list* self, void* obj); // Append object to the end of the list.
@ -31,8 +31,8 @@ struct _list
int (*index)(struct _list* self, void* obj); // Return first index of obj. Return -1 if the obj is not present.
bool (*remove)(struct _list* self, void *obj); // Remove first occurrence of obj.
bool (*get)(struct _list* self, int index, void* obj); // 根据索引,获取对象
bool (*set)(struct _list* self, int index, void* obj); // 根据索引,修改对象
bool (*get)(struct _list* self, int index, void* obj);
bool (*set)(struct _list* self, int index, void* obj);
// iter
void* (*begin)(struct _list* self);

View File

@ -27,10 +27,10 @@ struct _queue
uint32_t _index_front;
uint32_t _index_back;
uint32_t _obj_size; // 元素大小
uint32_t _size; // 栈大小
uint32_t _capacity; // 总容量
uint32_t _ratio; // 扩展比率
uint32_t _obj_size;
uint32_t _size;
uint32_t _capacity;
uint32_t _ratio;
// kernel
bool (*push)(struct _queue* self, void* obj);

View File

@ -23,10 +23,10 @@ struct _stack
{
struct _stack_node * _head;
uint32_t _size; // 栈大小
uint32_t _obj_size; // 元素大小
uint32_t _capacity; // 总容量
uint32_t _ratio; // 扩展比率
uint32_t _size;
uint32_t _obj_size;
uint32_t _capacity;
uint32_t _ratio;
// kernel
bool (*peek)(struct _stack* self, void* obj);

View File

@ -36,12 +36,12 @@ struct _tree
{
struct _tree_node * _root;
uint32_t _size; // 栈大小
uint32_t _obj_size; // 元素大小
uint32_t _capacity; // 总容量
uint32_t _ratio; // 扩展比率
uint32_t _size;
uint32_t _obj_size;
uint32_t _capacity;
uint32_t _ratio;
bool _right_priority; // 右优先
bool _right_priority;
// kernel
bool (*insert)(struct _tree* self, void* obj);

View File

@ -76,7 +76,7 @@ static void heap_fixed_up(struct _heap* self, int i)
while(1)
{
p = parent(i);
// 若当前节点大于其父节点,则交换位置,否则退出循环
// if current node is greater than its parent, swap the position. otherwise break out of loop
if(p < 0 || self->compare((char *)self->obj + i * self->_obj_size, (char *)self->obj + p * self->_obj_size) <= 0)
{
break;
@ -90,7 +90,7 @@ static void heap_fixed_up(struct _heap* self, int i)
while(1)
{
p = parent(i);
// 若当前节点大于其父节点,则交换位置,否则退出循环
// if current node is less than its parent, swap the position. otherwise break out of loop
if(p < 0 || self->compare((char *)self->obj + i * self->_obj_size, (char *)self->obj + p * self->_obj_size) >= 0)
{
break;

View File

@ -61,7 +61,7 @@ bool list_insert(struct _list* self, int index, void* obj)
bool list_pop(struct _list* self, int index, void* obj)
{
assert(self != NULL);
assert(index >= (int)(0 - self->size(self)) && index < (int)self->size(self)); // list空的时候也会报错太严格了有点
assert(index >= (int)(0 - self->size(self)) && index < (int)self->size(self));
if (self->empty(self))
{
@ -193,7 +193,7 @@ void* list_end(struct _list* self)
void* list_next(struct _list* self)
{
void *obj = NULL;
// 加了判断之后,回不到下一个了
// if add this, can't go to end
// if(self->_cur < self->_size - 1)
{
self->_cur += 1;

View File

@ -85,14 +85,10 @@ static bool stack_pop(struct _stack* self, void* obj)
if (obj != NULL)
{
// 将弹出的数据输出
memmove(obj, node->obj, self->_obj_size);
}
// 更新指针
self->_head->next = node->next;
// 释放数据和节点
free(node->obj);
free(node);
@ -111,10 +107,8 @@ static bool stack_clear(struct _stack* self)
struct _stack_node* node = self->_head->next;
while (node != NULL)
{
// 更新指针
self->_head->next = node->next;
// 释放数据和节点
free(node->obj);
free(node);
@ -321,7 +315,7 @@ bool stack_init2(struct _stack* self, uint32_t obj_size, uint32_t capacity)
return false;
}
// self->_head->obj = NULL;
self->_head->next = NULL; // 无效参数
self->_head->next = NULL;
// 4. set array
self->_head->obj = (void *)calloc(self->_capacity, self->_obj_size);

View File

@ -185,14 +185,14 @@ int32_t tree_height(struct _tree* self, struct _tree_node* root)
/**
* @brief
*
* balance = rigth - left
* if balance = rigth - leftso
*
* | | root->balance | node->balance | |
* | case | root->balance | node->balance | function |
* | ---- | ------------ | -------------- | -------- |
* | 1 | 2 | >= 0 |
* | 2 | 2 | < 0 |
* | 3 | -2 | <= 0 |
* | 4 | -2 | > 0 |
* | 1 | 2 | >= 0 | left rotation
* | 2 | 2 | < 0 | first right rotation, then left rotation
* | 3 | -2 | <= 0 | right rotation
* | 4 | -2 | > 0 | forth left rotation, then right rotation
*
* @param self
* @return true
@ -347,10 +347,10 @@ static bool tree_node_free(struct _tree_node* node)
}
/**
* @brief
* @brief find the position to insert or find object
*
* @param self
* @param obj
* @param self
* @param obj
*/
struct _tree_node * tree_find_pos(struct _tree* self, void* obj)
{
@ -1185,14 +1185,14 @@ bool tree_rb_insert(struct _tree* self, void* obj)
/**
* @brief
*
* balance = rigth - left
* balance = rigth - left
*
* | | root->balance | node->balance | |
* | | root->balance | node->balance | |
* | ---- | ------------ | -------------- | -------- |
* | 1 | 2 | >= 0 |
* | 2 | 2 | < 0 |
* | 3 | -2 | <= 0 |
* | 4 | -2 | > 0 |
* | 1 | 2 | >= 0 |
* | 2 | 2 | < 0 |
* | 3 | -2 | <= 0 |
* | 4 | -2 | > 0 |
*
* @param self
* @return true
@ -1210,18 +1210,18 @@ static bool tree_rb_rebalance(struct _tree* self, struct _tree_node* node)
struct _tree_node* uncle = NULL;
/**
* @brief
* @brief
*
* [1-3][4-6]
* [1-3][4-6]
*
*
*
*
* | | | |
* | | | |
* | ---- | --- | -------- |
* | 0 | |
* | 1 | |
* | 2 | | /
* | 3 | | /
* | 0 | |
* | 1 | |
* | 2 | | /
* | 3 | | /
*/
while(node->parent != NULL && node->parent->color == RBT_RED)
{

View File

@ -56,7 +56,7 @@ void print_str(void* obj)
// --------------------------------------------------
// 测试用例
// 测试用例
// --------------------------------------------------
void setUp(void)
{

View File

@ -10,10 +10,6 @@
*/
#include "test.h"
/**
* @brief
* init一次destory一次
*/
static void test_queue_init(void)
{
struct _queue queue;
@ -36,10 +32,6 @@ static void test_queue_init(void)
queue.destory(&queue);
}
/**
* @brief
* init一次free一次
*/
static void test_queue_new(void)
{
queue_t queue = NULL;