暂时用不到的函数就先屏蔽了

This commit is contained in:
建峰 2025-04-25 01:30:37 +08:00
parent ecc568bb90
commit 08ba5296be
8 changed files with 55 additions and 51 deletions

View File

@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.29) cmake_minimum_required(VERSION 3.29)
# 0. 项目信息 # 0. 项目信息
project(demo VERSION 0.0.01) project(demo VERSION 0.0.02)
# 2. 支持GDB # 2. 支持GDB
set(CMAKE_BUILD_TYPE "Debug") set(CMAKE_BUILD_TYPE "Debug")

View File

@ -63,8 +63,8 @@ struct _deque
bool (*set)(struct _deque* self, int index, void* obj); bool (*set)(struct _deque* self, int index, void* obj);
// compare // compare
int (*cmp)(void* obj, void* obj2); // int (*compare)(void* obj, void* obj2);
bool (*sort)(struct _deque* self, uint8_t reserve); // bool (*sort)(struct _deque* self, uint8_t reserve);
// -------------------- debug -------------------- // -------------------- debug --------------------
void (*print)(struct _deque* self); void (*print)(struct _deque* self);

View File

@ -49,11 +49,8 @@ struct _heap
iterator_t (*iter)(struct _heap* self); iterator_t (*iter)(struct _heap* self);
// config // config
// !!! you have to implement this function compare_fun_t compare; // !!! you have to implement this function
compare_fun_t compare;
// register function
// void (*register_compare)(struct _heap* self, compare_fun_t cmp_fun);
// -------------------- debug -------------------- // -------------------- debug --------------------
void (*print)(struct _heap* self); void (*print)(struct _heap* self);
void (*print_obj)(void* obj); void (*print_obj)(void* obj);

View File

@ -16,6 +16,7 @@
struct _list struct _list
{ {
// -------------------- private --------------------
void * obj; void * obj;
uint32_t _obj_size; uint32_t _obj_size;
@ -26,6 +27,9 @@ struct _list
struct _iterator _iter; struct _iterator _iter;
void (*_destory)(struct _list* self);
// -------------------- public --------------------
// kernel // kernel
bool (*append)(struct _list* self, void* obj); // Append object to the end of the list. bool (*append)(struct _list* self, void* obj); // Append object to the end of the list.
bool (*insert)(struct _list* self, int index, void* obj); // Insert object before index. bool (*insert)(struct _list* self, int index, void* obj); // Insert object before index.
@ -37,30 +41,25 @@ struct _list
bool (*get)(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); bool (*set)(struct _list* self, int index, void* obj);
// iter
iterator_t (*iter)(struct _list* self);
// base // base
uint32_t(*size)(struct _list* self); uint32_t(*size)(struct _list* self);
bool (*empty)(struct _list* self); bool (*empty)(struct _list* self);
// clear and free node
bool (*clear)(struct _list* self); bool (*clear)(struct _list* self);
void (*destory)(struct _list* self);
// iter
iterator_t (*iter)(struct _list* self);
// sort // sort
bool (*reverse)(struct _list* self); // Reverse *IN PLACE*. // bool (*reverse)(struct _list* self); // Reverse *IN PLACE*.
/** /**
Sort the list in ascending order and return false. Sort the list in ascending order and return false.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
order of two equal elements is maintained). order of two equal elements is maintained).
The reverse flag can be set to sort in descending order. The reverse flag can be set to sort in descending order.
*/ */
bool (*sort)(struct _list* self, uint8_t reserve, int (*compare)(void* obj, void* obj2)); // bool (*sort)(struct _list* self, uint8_t reserve, int (*compare)(void* obj, void* obj2));
// print // -------------------- debug --------------------
void (*print)(struct _list* self); void (*print)(struct _list* self);
void (*print_obj)(void* obj); void (*print_obj)(void* obj);
}; };

View File

@ -71,7 +71,7 @@ struct _tree
struct _iterator _iter; struct _iterator _iter;
void (*destory)(struct _tree* self); void (*_destory)(struct _tree* self);
// -------------------- public -------------------- // -------------------- public --------------------
// kernel // kernel
@ -107,4 +107,3 @@ tree_t tree_rb_new(uint32_t obj_size);
void tree_free(tree_t* tree); void tree_free(tree_t* tree);
#endif // _TREE_H_ #endif // _TREE_H_

View File

@ -13,7 +13,7 @@
#define UNICSTL_VERSION_MAJOR 0 #define UNICSTL_VERSION_MAJOR 0
#define UNICSTL_VERSION_MINOR 0 #define UNICSTL_VERSION_MINOR 0
#define UNICSTL_VERSION_MICRO 1 #define UNICSTL_VERSION_MICRO 2
#define UNICSTL_VERSION ((UNICSTL_VERSION_MAJOR << 16) | (UNICSTL_VERSION_MINOR << 8) | UNICSTL_VERSION_MICRO) #define UNICSTL_VERSION ((UNICSTL_VERSION_MAJOR << 16) | (UNICSTL_VERSION_MINOR << 8) | UNICSTL_VERSION_MICRO)
#include "common.h" #include "common.h"

View File

@ -215,42 +215,51 @@ static bool list_init2(struct _list* list, uint32_t obj_size, uint32_t capacity)
return false; return false;
} }
// 1. set attr // -------------------- private --------------------
list->_obj_size = obj_size; list->_obj_size = obj_size;
list->_size = 0; list->_size = 0;
list->_capacity = capacity; list->_capacity = capacity;
list->_ratio = 2; list->_ratio = 2;
list->_cur = 0; list->_cur = 0;
// 2. set function
// kernel
list->append = list_append;
list->get = list_get;
list->clear = list_clear;
list->destory = list_destory;
list->empty = list_empty;
list->index = list_index;
list->insert = list_insert;
list->pop = list_pop;
list->print = list_print;
list->remove = list_remove;
list->reverse = list_reverse;
list->set = list_set;
list->size = list_size;
list->sort = list_sort;
// iterator
list->iter = list_iter;
list->_iter.next = list_iter_next;
list->_iter.hasnext = list_iter_hasnext;
// 3. set array
// list->obj = (void*)calloc(list->_capacity, list->_obj_size);
list->obj = (void*)malloc(list->_capacity * list->_obj_size); list->obj = (void*)malloc(list->_capacity * list->_obj_size);
if (list->obj == NULL) if (list->obj == NULL)
{ {
return false; return false;
} }
list->_iter.next = list_iter_next;
list->_iter.hasnext = list_iter_hasnext;
list->_destory = list_destory;
// -------------------- public --------------------
// kernel
list->append = list_append;
list->insert = list_insert;
list->pop = list_pop;
list->empty = list_empty;
// base
list->clear = list_clear;
list->size = list_size;
// iter
list->iter = list_iter;
// others
list->index = list_index;
list->remove = list_remove;
list->get = list_get;
list->set = list_set;
// list->reverse = list_reverse;
// list->sort = list_sort;
// -------------------- debug --------------------
list->print = list_print;
return true; return true;
} }
@ -276,9 +285,9 @@ void list_free(list_t* list)
assert(list != NULL); assert(list != NULL);
if(list != NULL && *list != NULL) if(list != NULL && *list != NULL)
{ {
if((*list)->destory != NULL) if((*list)->_destory != NULL)
{ {
(*list)->destory(*list); (*list)->_destory(*list);
} }
free(*list); free(*list);
*list = NULL; *list = NULL;

View File

@ -1463,7 +1463,7 @@ static bool tree_avl_init(struct _tree* self, uint32_t obj_size)
self->_iter.hasnext = tree_iter_hasnext; self->_iter.hasnext = tree_iter_hasnext;
self->_iter.next = tree_iter_next; self->_iter.next = tree_iter_next;
self->destory = tree_destory; self->_destory = tree_destory;
// -------------------- public -------------------- // -------------------- public --------------------
// kernel // kernel
@ -1517,7 +1517,7 @@ static bool tree_rb_init(struct _tree* self, uint32_t obj_size)
self->_iter.hasnext = tree_iter_hasnext; self->_iter.hasnext = tree_iter_hasnext;
self->_iter.next = tree_iter_next; self->_iter.next = tree_iter_next;
self->destory = tree_destory; self->_destory = tree_destory;
// -------------------- public -------------------- // -------------------- public --------------------
// kernel // kernel
@ -1579,7 +1579,7 @@ void tree_free(tree_t* tree)
{ {
if (*tree != NULL) if (*tree != NULL)
{ {
(*tree)->destory(*tree); (*tree)->_destory(*tree);
free(*tree); free(*tree);
} }
*tree = NULL; *tree = NULL;