summaryrefslogtreecommitdiff
path: root/sql/sql_list.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_list.h')
-rw-r--r--sql/sql_list.h39
1 files changed, 38 insertions, 1 deletions
diff --git a/sql/sql_list.h b/sql/sql_list.h
index 5cd24236644..78549b73cef 100644
--- a/sql/sql_list.h
+++ b/sql/sql_list.h
@@ -54,7 +54,7 @@ public:
static void operator delete[](void *ptr, MEM_ROOT *mem_root)
{ /* never called */ }
static void operator delete[](void *ptr, size_t size) { TRASH(ptr, size); }
-#ifdef HAVE_purify
+#ifdef HAVE_valgrind
bool dummy;
inline Sql_alloc() :dummy(0) {}
inline ~Sql_alloc() {}
@@ -521,6 +521,43 @@ public:
/*
+ Exchange sort algorithm for List<T>.
+*/
+template <class T>
+inline void exchange_sort(List<T> *list_to_sort,
+ int (*sort_func)(T *a, T *b, void *arg), void *arg)
+{
+ bool swap;
+ List_iterator<T> it(*list_to_sort);
+ do
+ {
+ T *item1= it++;
+ T **ref1= it.ref();
+ T *item2;
+
+ swap= FALSE;
+ while ((item2= it++))
+ {
+ T **ref2= it.ref();
+ if (sort_func(item1, item2, arg) < 0)
+ {
+ T *item= *ref1;
+ *ref1= *ref2;
+ *ref2= item;
+ swap= TRUE;
+ }
+ else
+ {
+ item1= item2;
+ ref1= ref2;
+ }
+ }
+ it.rewind();
+ } while (swap);
+}
+
+
+/*
A simple intrusive list which automaticly removes element from list
on delete (for THD element)
*/