mariadb/include/ut0sort.h
marko 1a8a63d0cd branches/zip: Reimplement merge sort in fast index creation.
The creation of the primary key does not work.  We will have to flag
externally stored columns and copy the externally stored part from
the old table.

row_build_index_for_mysql(): Rename to row_merge_build_indexes().
Move from row0mysql.c to row0merge.c.

Remove private declarations from row0merge.h.  Make many functions static
in row0merge.c.

cmp_rec_rec_simple(): A new comparison function.

dict_index_get_min_size(): New function.

OS_FILE_FROM_FD(fd): A macro for converting from int to os_file_t.

rec_convert_dtuple_to_rec_comp(): Make the interface lower-level.

rec_get_converted_size_comp(): Return also extra_size.

UT_SORT_FUNCTION_BODY(): Remove reference to an obsolete test program.

row_rec_to_index_entry_low(): New function.

row0merge.c: Implement merge sort based on file streams instead of
fixed-size blocks.  Sort the small blocks as arrays of dfield_t*,
because it is faster than invoking rec_get_offsets() for every
comparison.
2007-06-08 07:37:07 +00:00

90 lines
2.6 KiB
C

/**********************************************************************
Sort utility
(c) 1995 Innobase Oy
Created 11/9/1995 Heikki Tuuri
***********************************************************************/
#ifndef ut0sort_h
#define ut0sort_h
#include "univ.i"
/* This module gives a macro definition of the body of
a standard sort function for an array of elements of any
type. The comparison function is given as a parameter to
the macro. The sort algorithm is mergesort which has logarithmic
worst case.
*/
/***********************************************************************
This macro expands to the body of a standard sort function.
The sort function uses mergesort and must be defined separately
for each type of array.
Also the comparison function has to be defined individually
for each array cell type. SORT_FUN is the sort function name.
The function takes the array to be sorted (ARR),
the array of auxiliary space (AUX_ARR) of same size,
and the low (LOW), inclusive, and high (HIGH), noninclusive,
limits for the sort interval as arguments.
CMP_FUN is the comparison function name. It takes as arguments
two elements from the array and returns 1, if the first is bigger,
0 if equal, and -1 if the second bigger. */
#define UT_SORT_FUNCTION_BODY(SORT_FUN, ARR, AUX_ARR, LOW, HIGH, CMP_FUN)\
{\
ulint ut_sort_mid77;\
ulint ut_sort_i77;\
ulint ut_sort_low77;\
ulint ut_sort_high77;\
\
ut_ad((LOW) < (HIGH));\
ut_ad(ARR);\
ut_ad(AUX_ARR);\
\
if ((LOW) == (HIGH) - 1) {\
return;\
} else if ((LOW) == (HIGH) - 2) {\
if (CMP_FUN((ARR)[LOW], (ARR)[(HIGH) - 1]) > 0) {\
(AUX_ARR)[LOW] = (ARR)[LOW];\
(ARR)[LOW] = (ARR)[(HIGH) - 1];\
(ARR)[(HIGH) - 1] = (AUX_ARR)[LOW];\
}\
return;\
}\
\
ut_sort_mid77 = ((LOW) + (HIGH)) / 2;\
\
SORT_FUN((ARR), (AUX_ARR), (LOW), ut_sort_mid77);\
SORT_FUN((ARR), (AUX_ARR), ut_sort_mid77, (HIGH));\
\
ut_sort_low77 = (LOW);\
ut_sort_high77 = ut_sort_mid77;\
\
for (ut_sort_i77 = (LOW); ut_sort_i77 < (HIGH); ut_sort_i77++) {\
\
if (ut_sort_low77 >= ut_sort_mid77) {\
(AUX_ARR)[ut_sort_i77] = (ARR)[ut_sort_high77];\
ut_sort_high77++;\
} else if (ut_sort_high77 >= (HIGH)) {\
(AUX_ARR)[ut_sort_i77] = (ARR)[ut_sort_low77];\
ut_sort_low77++;\
} else if (CMP_FUN((ARR)[ut_sort_low77],\
(ARR)[ut_sort_high77]) > 0) {\
(AUX_ARR)[ut_sort_i77] = (ARR)[ut_sort_high77];\
ut_sort_high77++;\
} else {\
(AUX_ARR)[ut_sort_i77] = (ARR)[ut_sort_low77];\
ut_sort_low77++;\
}\
}\
\
for (ut_sort_i77 = (LOW); ut_sort_i77 < (HIGH); ut_sort_i77++) {\
(ARR)[ut_sort_i77] = (AUX_ARR)[ut_sort_i77];\
}\
}\
#endif