Index: src/lib/ecore/Ecore_Data.h
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/Ecore_Data.h,v
retrieving revision 1.30
diff -u -r1.30 Ecore_Data.h
--- src/lib/ecore/Ecore_Data.h 28 Jan 2007 02:46:13 -0000 1.30
+++ src/lib/ecore/Ecore_Data.h 31 Jan 2007 16:56:59 -0000
@@ -40,6 +40,9 @@
EAPI extern const unsigned int ecore_prime_table[];
+# define ECORE_SORT_MIN 0
+# define ECORE_SORT_MAX 1
+
typedef void (*Ecore_For_Each) (void *value, void *user_data);
# define ECORE_FOR_EACH(function) ((Ecore_For_Each)function)
@@ -119,9 +122,11 @@
const void *user_data);
/* Sorting the list */
- EAPI void ecore_list_mergesort(Ecore_List *list, Ecore_Compare_Cb compare,
+ EAPI int ecore_list_sort(Ecore_List *list, Ecore_Compare_Cb compare,
+ char order);
+ EAPI int ecore_list_mergesort(Ecore_List *list, Ecore_Compare_Cb compare,
char order);
- EAPI void ecore_list_heapsort(Ecore_List *list, Ecore_Compare_Cb compare,
+ EAPI int ecore_list_heapsort(Ecore_List *list, Ecore_Compare_Cb compare,
char order);
/* Check to see if there is any data in the list */
@@ -326,9 +331,6 @@
EAPI Ecore_List *ecore_plugin_get_available(int group_id);
-
-# define ECORE_SHEAP_MIN 0
-# define ECORE_SHEAP_MAX 1
typedef struct _ecore_heap Ecore_Sheap;
# define ECORE_HEAP(heap) ((Ecore_Sheap *)heap)
Index: src/lib/ecore/ecore_list.c
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_list.c,v
retrieving revision 1.35
diff -u -r1.35 ecore_list.c
--- src/lib/ecore/ecore_list.c 28 Jan 2007 02:46:13 -0000 1.35
+++ src/lib/ecore/ecore_list.c 31 Jan 2007 16:57:00 -0000
@@ -1121,24 +1121,51 @@
}
/**
- * Sort data in @p list using the compare function @p func
+ * Sort data in @p list using the compare function @p compare
* @param list The list.
* @param compare The function to compare the data of @p list
* @param order The sort direction
*
+ * @return true on success
+ *
+ * This is a wrapper function for mergesort and heapsort. It
+ * tries to choose the fastest algorithm depending on the
+ * number of notes. Note: The sort may be unstable.
+ */
+EAPI int
+ecore_list_sort(Ecore_List *list, Ecore_Compare_Cb compare, char order)
+{
+ CHECK_PARAM_POINTER_RETURN("list", list, 0);
+
+ if (list->nodes < 2)
+ return 1;
+ if (list->nodes < 80000)
+ return ecore_list_mergesort(list, compare, order);
+ if (!ecore_list_heapsort(list, compare, order))
+ return ecore_list_mergesort(list, compare, order);
+
+ return 1;
+}
+/**
+ * Sort data in @p list using the compare function @p compare
+ * @param list The list.
+ * @param compare The function to compare the data of @p list
+ * @param order The sort direction
+ *
+ * @return true on success
+ *
* Mergesort is a stable, in-place sorting algorithm
*/
-EAPI void
+EAPI int
ecore_list_mergesort(Ecore_List *list, Ecore_Compare_Cb compare, char order)
{
Ecore_List_Node *node;
- CHECK_PARAM_POINTER("list", list);
- if (!list || list->nodes < 2)
- {
- return;
- }
- if (order == ECORE_SHEAP_MIN)
+ CHECK_PARAM_POINTER_RETURN("list", list, 0);
+ if (list->nodes < 2)
+ return 1;
+
+ if (order == ECORE_SORT_MIN)
order = 1;
else
order = -1;
@@ -1152,6 +1179,8 @@
list->last = node;
_ecore_list_goto_first(list);
+
+ return 1;
}
/* this is the internal recrusive function for the merge sort */
@@ -1244,26 +1273,31 @@
}
/**
- * Sort data in @p list using the compare function @p func
+ * Sort data in @p list using the compare function @p compare
* @param list The list.
* @param compare The function to compare the data of @p list
* @param order The sort direction
*
+ * @return true on success
+ *
* Heapsort is a unstable sorting algorithm, it needs to allocate extra memomry,
* but there for it is for a great number of nodes faster than mergesort
*/
-EAPI void
+EAPI int
ecore_list_heapsort(Ecore_List *list, Ecore_Compare_Cb compare, char order)
{
Ecore_Sheap *heap;
Ecore_List_Node *node;
void *data;
- CHECK_PARAM_POINTER("list", list);
+ CHECK_PARAM_POINTER_RETURN("list", list, 0);
/*
* Push the data into a heap.
*/
heap = ecore_sheap_new(compare, list->nodes);
+ if (!heap)
+ return 0;
+
ecore_sheap_set_order(heap, order);
_ecore_list_goto_first(list);
while ((data = _ecore_list_next(list)))
@@ -1284,6 +1318,7 @@
ecore_sheap_destroy(heap);
_ecore_list_goto_first(list);
+ return 1;
}
/* Initialize a node to starting values */
Index: src/lib/ecore/ecore_sheap.c
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_sheap.c,v
retrieving revision 1.11
diff -u -r1.11 ecore_sheap.c
--- src/lib/ecore/ecore_sheap.c 23 Jun 2006 06:41:44 -0000 1.11
+++ src/lib/ecore/ecore_sheap.c 31 Jan 2007 16:57:01 -0000
@@ -54,7 +54,7 @@
heap->compare = ecore_direct_compare;
else
heap->compare = compare;
- heap->order = ECORE_SHEAP_MIN;
+ heap->order = ECORE_SORT_MIN;
heap->data = (void **)malloc(heap->space * sizeof(void *));
if (!heap->data)
@@ -149,7 +149,7 @@
* data. The loop is placed inside the if statement to reduce the
* number of branching decisions that must be predicted.
*/
- if (heap->order == ECORE_SHEAP_MIN)
+ if (heap->order == ECORE_SORT_MIN)
{
while ((position > 0) && heap->compare(heap->data[parent],
heap->data[position]) > 0)
@@ -383,7 +383,7 @@
int left = LEFT(i);
int right = RIGHT(i);
- if (heap->order == ECORE_SHEAP_MIN)
+ if (heap->order == ECORE_SORT_MIN)
{
if (left <= heap->size && heap->compare(heap->data[left - 1],
heap->data[i - 1]) < 0)
Index: src/lib/ecore_file/ecore_file.c
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_file/ecore_file.c,v
retrieving revision 1.51
diff -u -r1.51 ecore_file.c
--- src/lib/ecore_file/ecore_file.c 29 Oct 2006 01:08:28 -0000 1.51
+++ src/lib/ecore_file/ecore_file.c 31 Jan 2007 16:57:01 -0000
@@ -295,7 +295,6 @@
DIR *dirp;
struct dirent *dp;
Ecore_List *list;
- Ecore_Sheap *heap;
dirp = opendir(dir);
if (!dirp) return NULL;
@@ -312,25 +311,8 @@
}
}
closedir(dirp);
-
- /*
- * Push the data into a heap.
- */
- heap = ecore_sheap_new(ECORE_COMPARE_CB(strcasecmp), ecore_list_nodes(list));
- while ((f = ecore_list_remove_first(list)))
- {
- ecore_sheap_insert(heap, f);
- }
-
- /*
- * Extract in sorted order.
- */
- while ((f = ecore_sheap_extract(heap)))
- {
- ecore_list_append(list, f);
- }
-
- ecore_sheap_destroy(heap);
+
+ ecore_list_sort(list, ECORE_COMPARE_CB(strcasecmp), ECORE_SORT_MIN);
ecore_list_goto_first(list);
return list;