From 9e76bdaf249232e15b863bc2e8811a70a9424351 Mon Sep 17 00:00:00 2001 From: tqfx Date: Mon, 25 Mar 2024 22:46:55 +0800 Subject: [PATCH] rename a_list_shift to a_list_set --- include/a/list.h | 98 ++++++++++++++++++++++++++++---------------------------- test/list.h | 20 ++++++------ 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/include/a/list.h b/include/a/list.h index edcfa98..d0b1757 100644 --- a/include/a/list.h +++ b/include/a/list.h @@ -245,10 +245,10 @@ A_INTERN void a_list_add_prev(a_list *ctx, a_list *node) tail:prev -> head:addr [color=green] } @enddot - @param[in,out] head the head node of a list - @param[in,out] tail the tail node of a list + @param[in] head the head node of a list + @param[in] tail the tail node of a list */ -A_INTERN void a_list_del_(a_list *head, a_list *tail) +A_INTERN void a_list_del_(a_list const *head, a_list const *tail) { a_list_link(head->prev, tail->next); } @@ -270,7 +270,7 @@ A_INTERN void a_list_del_(a_list *head, a_list *tail) @enddot @param[in] node a circular doubly linked list node */ -A_INTERN void a_list_del_node(a_list *node) { a_list_del_(node, node); } +A_INTERN void a_list_del_node(a_list const *node) { a_list_del_(node, node); } /*! @brief remove a node from a list forward @@ -289,7 +289,7 @@ A_INTERN void a_list_del_node(a_list *node) { a_list_del_(node, node); } @enddot @param[in] node a circular doubly linked list node */ -A_INTERN void a_list_del_next(a_list *node) { a_list_del_(node->next, node->next); } +A_INTERN void a_list_del_next(a_list const *node) { a_list_del_(node->next, node->next); } /*! @brief remove a node from a list backward @@ -308,10 +308,45 @@ A_INTERN void a_list_del_next(a_list *node) { a_list_del_(node->next, node->next @enddot @param[in] node a circular doubly linked list node */ -A_INTERN void a_list_del_prev(a_list *node) { a_list_del_(node->prev, node->prev); } +A_INTERN void a_list_del_prev(a_list const *node) { a_list_del_(node->prev, node->prev); } + +/*! + @brief modify a section of a list + @dot + digraph a_list_set_ { + node[shape="record"] + subgraph cluster0 { + 1[label="prev|head|tail|next"] + } + subgraph cluster1 { + 2[label="prev|head|tail|next"] + } + 1:prev -> 2:head [color=green] + 2:tail -> 1:next [color=green] + } + @enddot + @param[in] head1 the head node of the list1 + @param[in] tail1 the tail node of the list1 + @param[in,out] head2 the head node of the list2 + @param[in,out] tail2 the tail node of the list2 +*/ +A_INTERN void a_list_set_(a_list const *head1, a_list const *tail1, a_list *head2, a_list *tail2) +{ + a_list_add_(tail1->next, head1->prev, head2, tail2); +} + +/*! + @brief modify a node of a list + @param[in] ctx the current node + @param[in,out] rhs the new node +*/ +A_INTERN void a_list_set_node(a_list const *ctx, a_list *rhs) +{ + a_list_add_(ctx->next, ctx->prev, rhs, rhs); +} /*! - @brief moving a list to another list forward + @brief moving a list from another list forward @dot digraph a_list_mov_next { node[shape="record"] @@ -326,15 +361,15 @@ A_INTERN void a_list_del_prev(a_list *node) { a_list_del_(node->prev, node->prev } @enddot @param[in,out] ctx points to circular doubly linked list - @param[in,out] out another circular doubly linked list + @param[in] rhs another circular doubly linked list */ -A_INTERN void a_list_mov_next(a_list *ctx, a_list *out) +A_INTERN void a_list_mov_next(a_list *ctx, a_list const *rhs) { - a_list_add_(out->next, out, ctx->next, ctx->prev); + a_list_add_(ctx->next, ctx, rhs->next, rhs->prev); } /*! - @brief moving a list to another list backward + @brief moving a list from another list backward @dot digraph a_list_mov_prev { node[shape="record"] @@ -349,11 +384,11 @@ A_INTERN void a_list_mov_next(a_list *ctx, a_list *out) } @enddot @param[in,out] ctx points to circular doubly linked list - @param[in,out] out another circular doubly linked list + @param[in] rhs another circular doubly linked list */ -A_INTERN void a_list_mov_prev(a_list *ctx, a_list *out) +A_INTERN void a_list_mov_prev(a_list *ctx, a_list const *rhs) { - a_list_add_(out, out->prev, ctx->next, ctx->prev); + a_list_add_(ctx, ctx->prev, rhs->next, rhs->prev); } /*! @@ -411,41 +446,6 @@ A_INTERN void a_list_rot_prev(a_list *ctx) } /*! - @brief shift a section of one list to a section of another list - @dot - digraph a_list_shift_ { - node[shape="record"] - subgraph cluster0 { - 1[label="prev|head|tail|next"] - } - subgraph cluster1 { - 2[label="prev|head|tail|next"] - } - 1:prev -> 2:head [color=green] - 2:tail -> 1:next [color=green] - } - @enddot - @param[in,out] head1 the head node of the list1 - @param[in,out] tail1 the tail node of the list1 - @param[in,out] head2 the head node of the list2 - @param[in,out] tail2 the tail node of the list2 -*/ -A_INTERN void a_list_shift_(a_list *head1, a_list *tail1, a_list *head2, a_list *tail2) -{ - a_list_add_(tail1->next, head1->prev, head2, tail2); -} - -/*! - @brief shift the node rhs to the node lhs - @param[in,out] lhs the current node - @param[in,out] rhs the new node -*/ -A_INTERN void a_list_shift_node(a_list *lhs, a_list *rhs) -{ - a_list_shift_(lhs, lhs, rhs, rhs); -} - -/*! @brief swap a section of one list and a section of another list @dot digraph a_list_swap_ { diff --git a/test/list.h b/test/list.h index 72335c6..026ae42 100644 --- a/test/list.h +++ b/test/list.h @@ -63,8 +63,8 @@ static void test_next(void) a_list_del_prev(list2); a_die(node); } - a_list_mov_prev(list2, list1); - a_list_init(list2); + a_list *next = list2->next; + a_list_mov_prev(list1, list2); a_list_foreach_next(it, list1) { data *node = a_list_entry(it, data, node); // NOLINT(performance-no-int-to-ptr) @@ -77,7 +77,7 @@ static void test_next(void) a_list_del_node(&node->node); a_die(node); } - if (list1->next == list1 && list2->next == list2) + if (list1->next == list1 && list2->next == next) { printf(" ok"); } @@ -110,8 +110,8 @@ static void test_prev(void) a_list_del_next(list2); a_die(node); } - a_list_mov_next(list2, list1); - a_list_init(list2); + a_list *prev = list2->prev; + a_list_mov_next(list1, list2); a_list_foreach_prev(it, list1) { data *node = a_list_entry(it, data, node); // NOLINT(performance-no-int-to-ptr) @@ -124,7 +124,7 @@ static void test_prev(void) a_list_del_node(&node->node); a_die(node); } - if (list1->prev == list1 && list2->prev == list2) + if (list1->prev == list1 && list2->prev == prev) { printf(" ok"); } @@ -155,7 +155,7 @@ static void test_func(void) ctx->data.i = -1; { a_list *ptr = list2->prev; - a_list_shift_node(list2->prev, &ctx->node); + a_list_set_node(ptr, &ctx->node); ctx = a_list_entry(ptr, data, node); // NOLINT(performance-no-int-to-ptr) } a_list_swap_node(list2->prev, list2->next); @@ -284,15 +284,15 @@ static void test_null(void) printf("failure in %s %i %" PRIz "u\n", __FILE__, __LINE__, len); } - a_list_shift_node(&list1, &list1); - a_list_shift_node(&list2, &list2); + a_list_set_node(&list1, &list1); + a_list_set_node(&list2, &list2); len = a_list_len(&list1) + a_list_len(&list2); if (len != 2) { printf("failure in %s %i %" PRIz "u\n", __FILE__, __LINE__, len); } - a_list_shift_node(&list2, &list1); + a_list_set_node(&list2, &list1); a_list_init(&list2); len = a_list_len(&list1) + a_list_len(&list2); if (len != 0) -- 2.11.4.GIT