diff --git a/README.md b/README.md index fb79883d..67f2fe5e 100644 --- a/README.md +++ b/README.md @@ -702,14 +702,15 @@ Insert 'x' after the position pointed by 'it' (which is an iterator of the list Remove the element 'it' from the list 'list'. After wise, 'it' points to the next element of the list. -##### void list\_name\_move\_back(list\_name\_t list1, list\_name\_t list2, list\_it\_name\_t it) +##### void list\_name\_splice\_back(list\_name\_t list1, list\_name\_t list2, list\_it\_name\_t it) Move the element pointed by 'it' (which is an iterator of 'list2') from the list 'list2' to the back position of 'list1'. After wise, 'it' points to the next element of 'list2'. -##### void list\_name\_slice(list\_name\_t list1, list\_name\_t list2) +##### void list\_name\_splice(list\_name\_t list1, list\_name\_t list2) -Move all the element of 'list2' into 'list1". +Move all the element of 'list2' into 'list1", moving the last element +of 'list2' after the first element of 'list1'. After-wise, 'list2' is emptied. ##### void list\_name\_reverse(list\_name\_t list) diff --git a/m-dict.h b/m-dict.h index 87056960..94e0fb5d 100644 --- a/m-dict.h +++ b/m-dict.h @@ -238,7 +238,7 @@ assert( (hash & (new_size-1)) == (i + old_size)); \ M_C3(list_dict_pair_,name,_t) *new_list = \ M_C3(array_list_dict_pair_,name,_get)(map->table, i + old_size); \ - M_C3(list_dict_pair_,name,_move_back)(*new_list, *list, it); \ + M_C3(list_dict_pair_,name,_splice_back)(*new_list, *list, it); \ } else { \ M_C3(list_dict_pair_,name,_next)(it); \ } \ @@ -271,7 +271,7 @@ assert ((hash & (new_size -1)) == i - new_size); \ M_C3(list_dict_pair_,name,_t) *new_list = \ M_C3(array_list_dict_pair_,name,_get)(map->table, i - new_size); \ - M_C3(list_dict_pair_,name,_move_back)(*new_list, *list, it); \ + M_C3(list_dict_pair_,name,_splice_back)(*new_list, *list, it); \ } \ } \ /* Resize the dictionary */ \ diff --git a/m-list.h b/m-list.h index 08f0c97b..c3eac510 100644 --- a/m-list.h +++ b/m-list.h @@ -379,27 +379,6 @@ } \ \ static inline void \ - M_C3(list_, name, _move_back)(list_t nv, list_t ov, list_it_t it) \ - { \ - assert (nv != NULL && ov != NULL && it != NULL && nv != ov); \ - assert(it[0].l[0] != NULL); \ - assert(M_C3(list_, name, _sublist_p)(ov, it)); \ - /* Remove it from ov */ \ - struct M_C3(list_, name, _s) *next = it[0].l[0]->next; \ - struct M_C3(list_, name, _s) *current = it[0].l[0]; \ - if (it->previous == NULL) { \ - *ov = next; \ - } else { \ - it->previous->next = next; \ - } \ - /* Update it to next element */ \ - it[0].l[0] = next; \ - /* Move current in nv */ \ - current->next = *nv; \ - *nv = current; \ - } \ - \ - static inline void \ M_C3(list_, name, _set)(list_t list, const list_t org) \ { \ assert (list != NULL && org != NULL); \ @@ -447,8 +426,30 @@ M_C3(list_, name, _init_move)(list, org); \ } \ \ + \ static inline void \ - M_C3(list_, name, _slice)(list_t list1, list_t list2) \ + M_C3(list_, name, _splice_back)(list_t nv, list_t ov, list_it_t it) \ + { \ + assert (nv != NULL && ov != NULL && it != NULL && nv != ov); \ + assert(it[0].l[0] != NULL); \ + assert(M_C3(list_, name, _sublist_p)(ov, it)); \ + /* Remove it from ov */ \ + struct M_C3(list_, name, _s) *next = it[0].l[0]->next; \ + struct M_C3(list_, name, _s) *current = it[0].l[0]; \ + if (it->previous == NULL) { \ + *ov = next; \ + } else { \ + it->previous->next = next; \ + } \ + /* Update it to next element */ \ + it[0].l[0] = next; \ + /* Move current in nv */ \ + current->next = *nv; \ + *nv = current; \ + } \ + \ + static inline void \ + M_C3(list_, name, _splice)(list_t list1, list_t list2) \ { \ assert (list1 != NULL && list2 != NULL && list1 != list2); \ struct M_C3(list_, name, _s) **update_list = list1; \ diff --git a/tests/test-mlist.c b/tests/test-mlist.c index 40f26bf7..84383c71 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -135,7 +135,7 @@ static void test_uint(void) assert (list_uint_size(v2) == 998); list_uint_set (v, v2); - list_uint_slice (v, v2); + list_uint_splice (v, v2); assert (list_uint_empty_p(v) == false); assert (list_uint_empty_p(v2) == true); assert (list_uint_size(v) == 998*2);