Commit 7ab5543a authored by Sebastian Ramacher's avatar Sebastian Ramacher

implement girara_list_merge

parent 77c44a68
......@@ -4,6 +4,7 @@
#include <glib.h>
#include "datastructures.h"
#include "utils.h"
struct girara_tree_node_s
{
......@@ -316,6 +317,27 @@ girara_list_foreach(girara_list_t* list, girara_list_callback_t callback, void*
g_list_foreach(list->start, callback, data);
}
girara_list_t*
girara_list_merge(girara_list_t* list, girara_list_t* other)
{
if (list == NULL) {
return other;
}
if (other == NULL) {
return list;
}
if (list->free != other->free) {
girara_warning("girara_list_merge: merging lists with different free functions!");
}
other->free = NULL;
GIRARA_LIST_FOREACH(other, void*, iter, data)
girara_list_append(list, data);
GIRARA_LIST_FOREACH_END(other, void*, iter, data);
return list;
}
girara_tree_node_t*
girara_node_new(void* data)
{
......
......@@ -210,6 +210,16 @@ void girara_list_foreach(girara_list_t* list, girara_list_callback_t callback, v
girara_list_iterator_free(iter); \
} while(0)
/**
* Merge a kist into another one. Both lists need to have the same free
* function. If other has a source free function set it will be set to NULL as
* the elements then belong to list.
* @param list the target list
* @param other the source list
* @returns list with the elements from other.
*/
girara_list_t* girara_list_merge(girara_list_t* list, girara_list_t* other);
/**
* Create a new node.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment