From d762bf21cc0fa7a96b7135b4d5cf716d15a32fc8 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 1 Sep 2009 00:02:09 +0400 Subject: MWL#17: Table-elimination - Addressing review feedback, generation 4. include/my_global.h: Make ALIGN_PTR's action correspond to that of ALIGN_SIZE sql/item.cc: MWL#17: Table-elimination - Review feedback: function renames, better comments sql/item.h: MWL#17: Table-elimination - Review feedback: function renames, better comments sql/item_cmpfunc.cc: MWL#17: Table-elimination - Review feedback: function renames, better comments sql/item_subselect.cc: MWL#17: Table-elimination - Review feedback: function renames, better comments sql/item_subselect.h: MWL#17: Table-elimination - Review feedback: function renames, better comments sql/opt_table_elimination.cc: MWL#17: Table-elimination - Addressing review feedback, generation 4: abstract everything in case we would need to change it for something else in the future. sql/sql_list.h: MWL#17: Table-elimination - Introduce exchange_sort(List ...) template function sql/sql_select.cc: MWL#17: Table-elimination - Review feedback: function renames, better comments --- sql/sql_list.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'sql/sql_list.h') diff --git a/sql/sql_list.h b/sql/sql_list.h index 6edf9a00b87..eb580120c1b 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -442,6 +442,43 @@ public: }; +/* + Exchange sort algorithm for List. +*/ +template +inline void exchange_sort(List *list_to_sort, + int (*sort_func)(T *a, T *b, void *arg), void *arg) +{ + bool swap; + List_iterator 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) -- cgit v1.2.1