mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-18 03:51:35 +08:00
Compare commits
No commits in common. "1081cda4fe880ef895d96153939fe914d25854a8" and "32f2605656883c1a1c7810f0f644d0e2df0cf374" have entirely different histories.
1081cda4fe
...
32f2605656
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -29,7 +29,6 @@
|
||||
"iterator.h": "c",
|
||||
"assert.h": "c",
|
||||
"limits.h": "c",
|
||||
"cstdint": "c",
|
||||
"unicstl_internal.h": "c"
|
||||
"cstdint": "c"
|
||||
}
|
||||
}
|
@ -165,15 +165,12 @@ unicstl_stack_v1.2.5_20240717-a0.zip
|
||||
|
||||
## 修改日志
|
||||
|
||||
### Unicstl 0.0.02 (2025-05-06)
|
||||
### Unicstl 0.0.02 (2025-04-24)
|
||||
- new features
|
||||
- graph add function: add/del/find vertex/edge
|
||||
- graph add function: bfs/dfs
|
||||
- tree add new iterator and optimize code
|
||||
- deque add order select and delete some functions
|
||||
- iter change the name of container/index...
|
||||
- list optimize code and add slice function
|
||||
- unicstl add default function
|
||||
- tree remove old iterator and add new iterator
|
||||
- deque add order select
|
||||
- bugfixed:
|
||||
- none
|
||||
- others:
|
||||
|
@ -64,7 +64,6 @@ int main()
|
||||
demo_deque();
|
||||
demo_tree();
|
||||
demo_heap();
|
||||
demo_graph();
|
||||
}
|
||||
|
||||
printf("----- unicstl ok -----\n");
|
||||
|
@ -45,7 +45,6 @@ void demo_deque(void);
|
||||
void demo_queue(void);
|
||||
void demo_tree(void);
|
||||
void demo_heap(void);
|
||||
void demo_graph(void);
|
||||
|
||||
#endif // _DEMO_H_
|
||||
|
||||
|
@ -1,67 +0,0 @@
|
||||
/**
|
||||
* @file demo_graph.c
|
||||
* @author wenjf (Orig5826@163.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2025-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2025
|
||||
*
|
||||
*/
|
||||
#include "demo.h"
|
||||
|
||||
void demo_graph_add_vertex(void)
|
||||
{
|
||||
const int size = 10;
|
||||
int data[10] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
};
|
||||
int temp = 11;
|
||||
uint32_t i = 0;
|
||||
|
||||
graph_t graph = graph_new(sizeof(int));
|
||||
graph->compare = compare_num;
|
||||
graph->print_obj = print_num;
|
||||
|
||||
// test add_vertex
|
||||
for(i = 0; i < size; i++)
|
||||
{
|
||||
graph->add_vertex(graph, &data[i]);
|
||||
}
|
||||
// graph->print(graph);
|
||||
|
||||
// test add_edge
|
||||
graph->add_edge(graph, &data[0], &data[1], 12);
|
||||
graph->add_edge(graph, &data[0], &data[2], 13);
|
||||
graph->add_edge(graph, &data[1], &data[3], 24);
|
||||
graph->add_edge(graph, &data[5], &data[6], 67);
|
||||
graph->add_edge(graph, &data[7], &data[6], 87);
|
||||
graph->add_edge(graph, &data[8], &data[2], 92);
|
||||
|
||||
graph->add_edge(graph, &temp, &data[1], 0);
|
||||
graph->print(graph);
|
||||
|
||||
iterator_t iter_vertex = NULL;
|
||||
iter_vertex = graph->iter(graph, GRAPH_BFS, &data[0]);
|
||||
while(iter_vertex->hasnext(iter_vertex))
|
||||
{
|
||||
temp = *(int *)iter_vertex->next(iter_vertex);
|
||||
graph->print_obj(&temp);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
iter_vertex = graph->iter(graph, GRAPH_DFS, &data[0]);
|
||||
while(iter_vertex->hasnext(iter_vertex))
|
||||
{
|
||||
temp = *(int *)iter_vertex->next(iter_vertex);
|
||||
graph->print_obj(&temp);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
graph_free(&graph);
|
||||
}
|
||||
|
||||
void demo_graph(void)
|
||||
{
|
||||
demo_graph_add_vertex();
|
||||
}
|
@ -200,6 +200,7 @@ static void demo_stack_struct(void)
|
||||
}
|
||||
}
|
||||
|
||||
stack->_destory(stack);
|
||||
stack_free(&stack);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @file unicstl_internal.h
|
||||
* @file common.h
|
||||
* @author wenjf (Orig5826@163.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2025-04-30
|
||||
* @date 2024-07-03
|
||||
*
|
||||
* @copyright Copyright (c) 2025
|
||||
* @copyright Copyright (c) 2024
|
||||
*
|
||||
*/
|
||||
#ifndef _COMMON_H_
|
@ -11,7 +11,7 @@
|
||||
#ifndef _DEQUE_H_
|
||||
#define _DEQUE_H_
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
enum _deque_order
|
||||
{
|
||||
|
@ -11,7 +11,7 @@
|
||||
#ifndef _GRAPH_H
|
||||
#define _GRAPH_H
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "stack.h"
|
||||
#include "queue.h"
|
||||
|
@ -11,7 +11,7 @@
|
||||
#ifndef _HEAP_H_
|
||||
#define _HEAP_H_
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -11,7 +11,7 @@
|
||||
#ifndef _ITER_H_
|
||||
#define _ITER_H_
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
struct _iterator
|
||||
{
|
||||
|
@ -15,7 +15,7 @@
|
||||
#ifndef _LIST_H_
|
||||
#define _LIST_H_
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
#include "iterator.h"
|
||||
|
||||
#define LIST_UNLIMITED INT32_MAX
|
||||
|
@ -11,7 +11,7 @@
|
||||
#ifndef _QUEUE_H_
|
||||
#define _QUEUE_H_
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
struct _queue_node
|
||||
{
|
||||
|
@ -11,7 +11,7 @@
|
||||
#ifndef _STACK_H_
|
||||
#define _STACK_H_
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
struct _stack_node
|
||||
{
|
||||
|
@ -11,7 +11,7 @@
|
||||
#ifndef _TREE_H_
|
||||
#define _TREE_H_
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "stack.h"
|
||||
#include "queue.h"
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define UNICSTL_VERSION_MICRO 2
|
||||
#define UNICSTL_VERSION ((UNICSTL_VERSION_MAJOR << 16) | (UNICSTL_VERSION_MINOR << 8) | UNICSTL_VERSION_MICRO)
|
||||
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "list.h"
|
||||
#include "stack.h"
|
||||
|
@ -341,9 +341,6 @@ static bool deque_init(struct _deque* self, uint32_t obj_size)
|
||||
// iter
|
||||
self->iter = deque_iter;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
// -------------------- debug --------------------
|
||||
self->print = deque_print;
|
||||
|
||||
|
@ -1056,11 +1056,10 @@ static bool graph_init(struct _graph *self, uint32_t obj_size)
|
||||
// others
|
||||
self->from_matrix = NULL;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->compare = default_compare;
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
self->compare = NULL;
|
||||
// -------------------- debug --------------------
|
||||
self->print_obj = NULL;
|
||||
self->print = graph_print;
|
||||
|
||||
return true;
|
||||
|
@ -326,10 +326,6 @@ static bool heap_init2(struct _heap* self, uint32_t obj_size, uint32_t capacity)
|
||||
// config
|
||||
self->compare = NULL;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->compare = default_compare;
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
// -------------------- debug --------------------
|
||||
self->print = heap_print;
|
||||
return true;
|
||||
|
63
src/list.c
63
src/list.c
@ -364,64 +364,63 @@ iterator_t list_iter(struct _list* self)
|
||||
return iter;
|
||||
}
|
||||
|
||||
static bool list_init2(struct _list* self, uint32_t obj_size, uint32_t capacity)
|
||||
static bool list_init2(struct _list* list, uint32_t obj_size, uint32_t capacity)
|
||||
{
|
||||
assert(self != NULL);
|
||||
if (self == NULL || obj_size == 0 || capacity == 0)
|
||||
assert(list != NULL);
|
||||
if (list == NULL || obj_size == 0 || capacity == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------- private --------------------
|
||||
self->_obj_size = obj_size;
|
||||
self->_size = 0;
|
||||
self->_capacity = capacity;
|
||||
self->_ratio = 2;
|
||||
self->_cur = 0;
|
||||
list->_obj_size = obj_size;
|
||||
list->_size = 0;
|
||||
list->_capacity = capacity;
|
||||
list->_ratio = 2;
|
||||
list->_cur = 0;
|
||||
|
||||
self->obj = (void*)malloc(self->_capacity * self->_obj_size);
|
||||
if (self->obj == NULL)
|
||||
list->obj = (void*)malloc(list->_capacity * list->_obj_size);
|
||||
if (list->obj == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
self->_iter.next = list_iter_next;
|
||||
self->_iter.hasnext = list_iter_hasnext;
|
||||
list->_iter.next = list_iter_next;
|
||||
list->_iter.hasnext = list_iter_hasnext;
|
||||
|
||||
self->_destory = list_destory;
|
||||
list->_destory = list_destory;
|
||||
|
||||
// -------------------- public --------------------
|
||||
// kernel
|
||||
self->append = list_append;
|
||||
self->pop = list_pop;
|
||||
list->append = list_append;
|
||||
list->pop = list_pop;
|
||||
|
||||
self->insert = list_insert;
|
||||
self->delete = list_delete;
|
||||
list->insert = list_insert;
|
||||
list->delete = list_delete;
|
||||
|
||||
self->get = list_get;
|
||||
self->set = list_set;
|
||||
list->get = list_get;
|
||||
list->set = list_set;
|
||||
|
||||
self->index = list_index;
|
||||
// self->contains = list_contains;
|
||||
list->index = list_index;
|
||||
// list->contains = list_contains;
|
||||
|
||||
// base
|
||||
self->clear = list_clear;
|
||||
self->size = list_size;
|
||||
self->empty = list_empty;
|
||||
self->capacity = list_capacity;
|
||||
list->clear = list_clear;
|
||||
list->size = list_size;
|
||||
list->empty = list_empty;
|
||||
list->capacity = list_capacity;
|
||||
|
||||
// iter
|
||||
self->iter = list_iter;
|
||||
list->iter = list_iter;
|
||||
|
||||
// others
|
||||
self->slice = list_slice;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->compare = default_compare;
|
||||
self->print_obj = default_print_obj;
|
||||
list->slice = list_slice;
|
||||
|
||||
// config
|
||||
list->compare = default_compare;
|
||||
// -------------------- debug --------------------
|
||||
self->print = list_print;
|
||||
list->print_obj = default_print_obj;
|
||||
list->print = list_print;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -420,9 +420,6 @@ static bool queue_init(struct _queue * self, uint32_t obj_size)
|
||||
// iter
|
||||
self->iter = queue_iter;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
// -------------------- debug --------------------
|
||||
self->print = queue_print;
|
||||
|
||||
@ -486,9 +483,6 @@ static bool queue_init2(struct _queue * self, uint32_t obj_size, uint32_t capaci
|
||||
// iter
|
||||
self->iter = queue2_iter;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
// -------------------- debug --------------------
|
||||
self->print = queue2_print;
|
||||
|
||||
|
21
src/stack.c
21
src/stack.c
@ -124,6 +124,7 @@ static uint32_t stack_capacity(struct _stack* self)
|
||||
static bool stack_clear(struct _stack* self)
|
||||
{
|
||||
assert(self != NULL);
|
||||
assert(self->_head != NULL);
|
||||
if (self->empty(self))
|
||||
{
|
||||
return true;
|
||||
@ -322,7 +323,7 @@ static bool stack_init(struct _stack* self, uint32_t obj_size)
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------- private --------------------
|
||||
// ---------- private ----------
|
||||
self->_obj_size = obj_size;
|
||||
self->_size = 0;
|
||||
self->_capacity = UINT32_MAX;
|
||||
@ -338,7 +339,7 @@ static bool stack_init(struct _stack* self, uint32_t obj_size)
|
||||
|
||||
self->_destory = stack_destory;
|
||||
|
||||
// -------------------- public --------------------
|
||||
// ---------- public ----------
|
||||
// kernel
|
||||
self->push = stack_push;
|
||||
self->pop = stack_pop;
|
||||
@ -353,12 +354,8 @@ static bool stack_init(struct _stack* self, uint32_t obj_size)
|
||||
// iter
|
||||
self->iter = stack_iter;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
// -------------------- debug --------------------
|
||||
// ---------- debug ----------
|
||||
self->print = stack_print;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -370,7 +367,7 @@ static bool stack_init2(struct _stack* self, uint32_t obj_size, uint32_t capacit
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------- private --------------------
|
||||
// ---------- private ----------
|
||||
self->_obj_size = obj_size;
|
||||
self->_size = 0;
|
||||
self->_capacity = capacity;
|
||||
@ -396,7 +393,7 @@ static bool stack_init2(struct _stack* self, uint32_t obj_size, uint32_t capacit
|
||||
|
||||
self->_destory = stack2_destory;
|
||||
|
||||
// -------------------- public --------------------
|
||||
// ---------- public ----------
|
||||
// kernel
|
||||
self->push = stack2_push;
|
||||
self->pop = stack2_pop;
|
||||
@ -411,12 +408,8 @@ static bool stack_init2(struct _stack* self, uint32_t obj_size, uint32_t capacit
|
||||
// iter
|
||||
self->iter = stack_iter;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
// -------------------- debug --------------------
|
||||
// ---------- debug ----------
|
||||
self->print = stack2_print;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1420,10 +1420,6 @@ static bool tree_avl_init(struct _tree* self, uint32_t obj_size)
|
||||
// others
|
||||
self->max = tree_max;
|
||||
self->min = tree_min;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->compare = default_compare;
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1473,10 +1469,6 @@ static bool tree_rb_init(struct _tree* self, uint32_t obj_size)
|
||||
self->max = tree_max;
|
||||
self->min = tree_min;
|
||||
|
||||
// -------------------- default --------------------
|
||||
self->compare = default_compare;
|
||||
self->print_obj = default_print_obj;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
* @copyright Copyright (c) 2025
|
||||
*
|
||||
*/
|
||||
#include "unicstl_internal.h"
|
||||
#include "common.h"
|
||||
|
||||
int default_compare(void* obj1, void* obj2)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user