Enlightenment CVS committal Author : pfritz Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore Modified Files: Ecore_Data.h ecore_list.c Log Message: add ecore_list_merge() and ecore_dlist_merge() =================================================================== RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/Ecore_Data.h,v retrieving revision 1.52 retrieving revision 1.53 diff -u -3 -r1.52 -r1.53 --- Ecore_Data.h 11 Nov 2007 17:08:20 -0000 1.52 +++ Ecore_Data.h 8 Jan 2008 21:49:57 -0000 1.53 @@ -134,6 +134,8 @@ char order); EAPI int ecore_list_heapsort(Ecore_List *list, Ecore_Compare_Cb compare, char order); + EAPI void ecore_list_merge(Ecore_List *list, Ecore_List *l2, + Ecore_Compare_Cb, char order); /* Check to see if there is any data in the list */ EAPI int ecore_list_empty_is(Ecore_List * list); @@ -207,6 +209,8 @@ char order); # define ecore_dlist_heapsort(list, compare, order) \ ecore_list_heapsort(list, compare, order) + EAPI void ecore_dlist_merge(Ecore_DList *list, Ecore_DList *l2, + Ecore_Compare_Cb, char order); /* Check to see if there is any data in the list */ EAPI int ecore_dlist_empty_is(Ecore_DList * _e_dlist); =================================================================== RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_list.c,v retrieving revision 1.43 retrieving revision 1.44 diff -u -3 -r1.43 -r1.44 --- ecore_list.c 19 Nov 2007 04:15:26 -0000 1.43 +++ ecore_list.c 8 Jan 2008 21:49:57 -0000 1.44 @@ -1195,6 +1195,45 @@ return 1; } +/** + * Merge the @p l2 into the @p list using the compare function @p compare. + * Both lists need to be sorted else a corrupt list could be the result. + * @param list The list. + * @param l2 The second list, this list will be empty after the merge + * @param compare The function to compare the data of @p list and @p l2 + * @param order The sort direction, possible values are ECORE_SORT_MIN and + * ECORE_SORT_MAX + */ +EAPI void +ecore_list_merge(Ecore_List *list, Ecore_List *l2, Ecore_Compare_Cb compare, char order) +{ + Ecore_List_Node *node; + + CHECK_PARAM_POINTER("list", list); + CHECK_PARAM_POINTER("l2", l2); + + if (ecore_list_empty_is(l2)) return; + + if (ecore_list_empty_is(list)) + { + ecore_list_append_list(list, l2); + return; + } + + if (order == ECORE_SORT_MIN) + order = 1; + else + order = -1; + + list->first = _ecore_list_node_merge(list->first, l2->first, compare, order); + + if ((order * compare(list->last->data, l2->last->data)) < 0) + list->last = l2->last; + + list->nodes += l2->nodes; + ecore_list_init(l2); +} + /* this is the internal recrusive function for the merge sort */ static Ecore_List_Node * _ecore_list_node_mergesort(Ecore_List_Node *first, int n, @@ -2048,6 +2087,43 @@ _ecore_list_first_goto(list); return 1; +} + +/** + * Merge the @p l2 into the @p list using the compare function @p compare. + * Both lists need to be sorted else a corrupt list could be the result. + * @param list The list. + * @param l2 The second list, this list will be empty after the merge + * @param compare The function to compare the data of @p list and @p l2 + * @param order The sort direction, possible values are ECORE_SORT_MIN and + * ECORE_SORT_MAX + */ +EAPI void +ecore_dlist_merge(Ecore_DList *list, Ecore_DList *l2, Ecore_Compare_Cb compare, char order) +{ + CHECK_PARAM_POINTER("list", list); + CHECK_PARAM_POINTER("l2", l2); + + if (ecore_dlist_empty_is(l2)) return; + + if (ecore_dlist_empty_is(list)) + { + ecore_dlist_append_list(list, l2); + return; + } + + if (order == ECORE_SORT_MIN) + order = 1; + else + order = -1; + + list->first = _ecore_dlist_node_merge(list->first, l2->first, compare, order); + + if ((order * compare(list->last->data, l2->last->data)) < 0) + list->last = l2->last; + + list->nodes += l2->nodes; + ecore_dlist_init(l2); } /* this is the internal recrusive function for the merge sort */ ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs