1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-02-28 09:21:53 -05:00

New alpm_list_join function

This O(1) function joins 2 lists.

Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Nagy Gabor 2007-11-20 09:11:40 +01:00 committed by Dan McGee
parent 967a78f5e4
commit 4696ad6cad
2 changed files with 34 additions and 0 deletions

View File

@ -184,6 +184,39 @@ alpm_list_t SYMEXPORT *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_
}
}
/**
* @brief Join two lists.
* The two lists must be independent. Do not free the original lists after
* calling this function, as this is not a copy operation. The list pointers
* passed in should be considered invalid after calling this function.
*
* @param first the first list
* @param second the second list
*
* @return the resultant joined list
*/
alpm_list_t SYMEXPORT *alpm_list_join(alpm_list_t *first, alpm_list_t *second)
{
alpm_list_t *tmp;
if (first == NULL) {
return second;
}
if (second == NULL) {
return first;
}
/* tmp is the last element of the first list */
tmp = first->prev;
/* link the first list to the second */
tmp->next = second;
/* link the second list to the first */
first->prev = second->prev;
/* set the back reference to the tail */
second->prev = tmp;
return(first);
}
/**
* @brief Merge the two sorted sublists into one sorted list.
*

View File

@ -54,6 +54,7 @@ void alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn);
/* item mutators */
alpm_list_t *alpm_list_add(alpm_list_t *list, void *data);
alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cmp fn);
alpm_list_t *alpm_list_join(alpm_list_t *first, alpm_list_t *second);
alpm_list_t *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn);
alpm_list_t *alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn);
alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data);