summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/alpm_list.c
diff options
context:
space:
mode:
authorNagy Gabor <ngaba@bibl.u-szeged.hu>2007-11-20 09:11:40 +0100
committerDan McGee <dan@archlinux.org>2007-11-21 06:31:40 +0100
commit4696ad6cad9c659728e9e061689728fc0417ad73 (patch)
treed196162c7528243711886558e7c18a32009e697d /lib/libalpm/alpm_list.c
parent967a78f5e476030c2d13104a7dadc5ce4daf5882 (diff)
downloadpacman-4696ad6cad9c659728e9e061689728fc0417ad73.tar.gz
pacman-4696ad6cad9c659728e9e061689728fc0417ad73.tar.xz
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>
Diffstat (limited to 'lib/libalpm/alpm_list.c')
-rw-r--r--lib/libalpm/alpm_list.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index e854cf63..69cd3479 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -185,6 +185,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.
*
* @param left the first list