From 70d1741babab8d09389f1caa76ebac697413d397 Mon Sep 17 00:00:00 2001 From: Lamdonn Date: Fri, 10 Oct 2025 20:25:47 +0800 Subject: [PATCH] 1. Fix set and map iterate looping error issue 2. Fix the list pop back macro definition --- README.en.md | 6 +++--- README.md | 6 +++--- source/03_container/list.c | 2 +- source/03_container/list.h | 6 +++--- source/03_container/map.c | 20 +++++++++++++++----- source/03_container/map.h | 4 ++-- source/03_container/set.c | 20 +++++++++++++++----- source/03_container/set.h | 4 ++-- 8 files changed, 44 insertions(+), 24 deletions(-) diff --git a/README.en.md b/README.en.md index e2d1410..f5f8dd5 100644 --- a/README.en.md +++ b/README.en.md @@ -45,13 +45,13 @@ It has the characteristics of **simplicity, universality, and efficiency**, with | queue | 01.00.00 | [link](/doc/queue.en.md) | [path](./source/03_container) | Universal queue container | stack | 01.00.00 | [link](/doc/stack.en.md) | [path](./source/03_container) | Universal stack container | deque | 01.00.00 | [link](/doc/deque.en.md) | [path](./source/03_container) | Universal double-end queue container -| list | 01.00.00 | [link](/doc/list.en.md) | [path](./source/03_container) | Universal list container, single-link and internal iteration +| list | 01.00.01 | [link](/doc/list.en.md) | [path](./source/03_container) | Universal list container, single-link and internal iteration | vector | 01.00.00 | [link](/doc/vector.en.md) | [path](./source/03_container) | Universal vector(array) container | str | 01.00.00 | [link](/doc/str.en.md) | [path](./source/03_container) | String class | dict | 01.00.00 | [link](/doc/dict.en.md) | [path](./source/03_container) | Universal dictionarie container, implementation based on hash table | heap | 01.00.00 | [link](/doc/heap.en.md) | [path](./source/03_container) | Universal heap container -| set | 01.00.00 | [link](/doc/set.en.md) | [path](./source/03_container) | Universal set container, implementation based on RB-tree -| map | 01.00.00 | [link](/doc/map.en.md) | [path](./source/03_container) | Universal map container, implementation based on RB-tree +| set | 01.00.01 | [link](/doc/set.en.md) | [path](./source/03_container) | Universal set container, implementation based on RB-tree +| map | 01.00.01 | [link](/doc/map.en.md) | [path](./source/03_container) | Universal map container, implementation based on RB-tree | tree | 01.00.00 | [link](/doc/tree.en.md) | [path](./source/03_container) | Universal tree container | graph | 01.00.00 | [link](/doc/graph.en.md) | [path](./source/03_container) | Universal graph container | check | 01.00.00 | [link](/doc/check.en.md) | [path](./source/04_algorithm) | Verification algorithm, sum check, parity check, XOR check, LRC check diff --git a/README.md b/README.md index 23c9808..964daa6 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,13 @@ varch(we-architecture,意为我们的框架库)是嵌入式C语言常用 | queue | 01.00.00 | [link](/doc/queue.md) | [path](./source/03_container) | 通用队列容器 | stack | 01.00.00 | [link](/doc/stack.md) | [path](./source/03_container) | 通用栈式容器 | deque | 01.00.00 | [link](/doc/deque.md) | [path](./source/03_container) | 通用双端队列容器 -| list | 01.00.00 | [link](/doc/list.md) | [path](./source/03_container) | 通用列表容器,单链接和支持内部迭代器 +| list | 01.00.01 | [link](/doc/list.md) | [path](./source/03_container) | 通用列表容器,单链接和支持内部迭代器 | vector | 01.00.00 | [link](/doc/vector.md) | [path](./source/03_container) | 通用向量(数组)容器 | str | 01.00.00 | [link](/doc/str.md) | [path](./source/03_container) | 字符串类 | dict | 01.00.00 | [link](/doc/dict.md) | [path](./source/03_container) | 通用字典容器,基于哈希表实现 | heap | 01.00.00 | [link](/doc/heap.md) | [path](./source/03_container) | 通用堆容器 -| set | 01.00.00 | [link](/doc/set.md) | [path](./source/03_container) | 通用集合容器,基于RB-tree实现 -| map | 01.00.00 | [link](/doc/map.md) | [path](./source/03_container) | 通用映射容器,基于RB-tree实现 +| set | 01.00.01 | [link](/doc/set.md) | [path](./source/03_container) | 通用集合容器,基于RB-tree实现 +| map | 01.00.01 | [link](/doc/map.md) | [path](./source/03_container) | 通用映射容器,基于RB-tree实现 | tree | 01.00.00 | [link](/doc/tree.md) | [path](./source/03_container) | 通用树容器 | graph | 01.00.00 | [link](/doc/graph.md) | [path](./source/03_container) | 通用图容器 | check | 01.00.00 | [link](/doc/check.md) | [path](./source/04_algorithm) | 校验算法,求和校验,奇偶校验,异或校验,LRC校验 diff --git a/source/03_container/list.c b/source/03_container/list.c index c8afd39..db058cd 100644 --- a/source/03_container/list.c +++ b/source/03_container/list.c @@ -6,7 +6,7 @@ * \unit list * \brief This is a C language singly linked list with built-in iterators, simple, reliable, fast, small space * \author Lamdonn - * \version v1.0.0 + * \version v1.0.1 * \license GPL-2.0 * \copyright Copyright (C) 2023 Lamdonn. ********************************************************************************************************/ diff --git a/source/03_container/list.h b/source/03_container/list.h index 4b144d7..1bd8386 100644 --- a/source/03_container/list.h +++ b/source/03_container/list.h @@ -6,7 +6,7 @@ * \unit list * \brief This is a C language singly linked list with built-in iterators, simple, reliable, fast, small space * \author Lamdonn - * \version v1.0.0 + * \version v1.0.1 * \license GPL-2.0 * \copyright Copyright (C) 2023 Lamdonn. ********************************************************************************************************/ @@ -19,7 +19,7 @@ #define LIST_V_MAJOR 1 #define LIST_V_MINOR 0 -#define LIST_V_PATCH 0 +#define LIST_V_PATCH 1 /* list type definition, hiding structural members, not for external use */ @@ -123,7 +123,7 @@ int list_dsize(list_t list); * \param[out] data: the address of data * \return 1 success or 0 fail */ -#define list_pop_back(list) list_erase((list), list_size(list), 1) +#define list_pop_back(list) list_erase((list), list_size(list) - 1, 1) /** * \brief clear list. diff --git a/source/03_container/map.c b/source/03_container/map.c index ae44cfe..2a75ba5 100644 --- a/source/03_container/map.c +++ b/source/03_container/map.c @@ -6,7 +6,7 @@ * \unit map * \brief This is a general-purpose C language map module, with common data structure * \author Lamdonn - * \version v1.0.0 + * \version v1.0.1 * \license GPL-2.0 * \copyright Copyright (C) 2023 Lamdonn. ********************************************************************************************************/ @@ -694,8 +694,13 @@ static NODE* node_next(map_t map, NODE* node) } else { - if (node == node->parent->left) node = node->parent; - else node = node->parent->parent; + NODE *parent = node->parent; + while (parent != map->nil && node == parent->right) + { + node = parent; + parent = parent->parent; + } + return parent; } return node; } @@ -709,8 +714,13 @@ static NODE* node_prev(map_t map, NODE* node) } else { - if (node == node->parent->right) node = node->parent; - else node = node->parent->parent; + NODE *parent = node->parent; + while (parent != map->nil && node == parent->left) + { + node = parent; + parent = parent->parent; + } + return parent; } return node; } diff --git a/source/03_container/map.h b/source/03_container/map.h index 8a98cda..206f369 100644 --- a/source/03_container/map.h +++ b/source/03_container/map.h @@ -6,7 +6,7 @@ * \unit map * \brief This is a general-purpose C language map module, with common data structure * \author Lamdonn - * \version v1.0.0 + * \version v1.0.1 * \license GPL-2.0 * \copyright Copyright (C) 2023 Lamdonn. ********************************************************************************************************/ @@ -20,7 +20,7 @@ #define MAP_V_MAJOR 1 #define MAP_V_MINOR 0 -#define MAP_V_PATCH 0 +#define MAP_V_PATCH 1 /* map type definition, hiding structural members, not for external use */ diff --git a/source/03_container/set.c b/source/03_container/set.c index 80808ee..4b64395 100644 --- a/source/03_container/set.c +++ b/source/03_container/set.c @@ -6,7 +6,7 @@ * \unit set * \brief This is a general-purpose C language set module, with common data structure * \author Lamdonn - * \version v1.0.0 + * \version v1.0.1 * \license GPL-2.0 * \copyright Copyright (C) 2023 Lamdonn. ********************************************************************************************************/ @@ -592,8 +592,13 @@ static NODE* node_next(set_t set, NODE* node) } else { - if (node == node->parent->left) node = node->parent; - else node = node->parent->parent; + NODE *parent = node->parent; + while (parent != set->nil && node == parent->right) + { + node = parent; + parent = parent->parent; + } + return parent; } return node; } @@ -607,8 +612,13 @@ static NODE* node_prev(set_t set, NODE* node) } else { - if (node == node->parent->right) node = node->parent; - else node = node->parent->parent; + NODE *parent = node->parent; + while (parent != set->nil && node == parent->left) + { + node = parent; + parent = parent->parent; + } + return parent; } return node; } diff --git a/source/03_container/set.h b/source/03_container/set.h index f0bb620..c1d3191 100644 --- a/source/03_container/set.h +++ b/source/03_container/set.h @@ -6,7 +6,7 @@ * \unit set * \brief This is a general-purpose C language set module, with common data structure * \author Lamdonn - * \version v1.0.0 + * \version v1.0.1 * \license GPL-2.0 * \copyright Copyright (C) 2023 Lamdonn. ********************************************************************************************************/ @@ -19,7 +19,7 @@ #define SET_V_MAJOR 1 #define SET_V_MINOR 0 -#define SET_V_PATCH 0 +#define SET_V_PATCH 1 /* set type definition, hiding structural members, not for external use */