change tree to use qsort_cmp2 - compare function with 3 instead of 2 arguments

parent 15df552e
...@@ -349,6 +349,7 @@ typedef int pshort; /* Mixed prototypes can't take short int */ ...@@ -349,6 +349,7 @@ typedef int pshort; /* Mixed prototypes can't take short int */
typedef double pfloat; /* Mixed prototypes can't take float */ typedef double pfloat; /* Mixed prototypes can't take float */
#endif #endif
typedef int (*qsort_cmp)(const void *,const void *); typedef int (*qsort_cmp)(const void *,const void *);
typedef int (*qsort_cmp2)(void*, const void *,const void *);
#ifdef HAVE_mit_thread #ifdef HAVE_mit_thread
#define qsort_t void #define qsort_t void
#undef QSORT_TYPE_IS_VOID #undef QSORT_TYPE_IS_VOID
......
...@@ -50,7 +50,8 @@ typedef struct st_tree { ...@@ -50,7 +50,8 @@ typedef struct st_tree {
TREE_ELEMENT *root,null_element; TREE_ELEMENT *root,null_element;
TREE_ELEMENT **parents[MAX_TREE_HIGHT]; TREE_ELEMENT **parents[MAX_TREE_HIGHT];
uint offset_to_key,elements_in_tree,size_of_element; uint offset_to_key,elements_in_tree,size_of_element;
qsort_cmp compare; qsort_cmp2 compare;
void* cmp_arg;
MEM_ROOT mem_root; MEM_ROOT mem_root;
my_bool with_delete; my_bool with_delete;
void (*free)(void *); void (*free)(void *);
...@@ -58,7 +59,7 @@ typedef struct st_tree { ...@@ -58,7 +59,7 @@ typedef struct st_tree {
/* Functions on hole tree */ /* Functions on hole tree */
void init_tree(TREE *tree,uint default_alloc_size, int element_size, void init_tree(TREE *tree,uint default_alloc_size, int element_size,
qsort_cmp compare, my_bool with_delete, qsort_cmp2 compare, my_bool with_delete,
void (*free_element)(void*)); void (*free_element)(void*));
void delete_tree(TREE*); void delete_tree(TREE*);
#define is_tree_inited(tree) ((tree)->root != 0) #define is_tree_inited(tree) ((tree)->root != 0)
......
...@@ -41,7 +41,8 @@ typedef struct st_ft_superdoc { ...@@ -41,7 +41,8 @@ typedef struct st_ft_superdoc {
ALL_IN_ONE *aio; ALL_IN_ONE *aio;
} FT_SUPERDOC; } FT_SUPERDOC;
static int FT_SUPERDOC_cmp(FT_SUPERDOC *p1, FT_SUPERDOC *p2) static int FT_SUPERDOC_cmp(void* cmp_arg __attribute__((unused)),
FT_SUPERDOC *p1, FT_SUPERDOC *p2)
{ {
if (p1->doc.dpos < p2->doc.dpos) if (p1->doc.dpos < p2->doc.dpos)
return -1; return -1;
......
...@@ -35,7 +35,8 @@ typedef struct st_ft_superdoc { ...@@ -35,7 +35,8 @@ typedef struct st_ft_superdoc {
double tmp_weight; double tmp_weight;
} FT_SUPERDOC; } FT_SUPERDOC;
static int FT_SUPERDOC_cmp(FT_SUPERDOC *p1, FT_SUPERDOC *p2) static int FT_SUPERDOC_cmp(void* cmp_arg __attribute__((unused)),
FT_SUPERDOC *p1, FT_SUPERDOC *p2)
{ {
if (p1->doc.dpos < p2->doc.dpos) if (p1->doc.dpos < p2->doc.dpos)
return -1; return -1;
...@@ -162,7 +163,7 @@ FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query, ...@@ -162,7 +163,7 @@ FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query,
bzero(&allocated_wtree,sizeof(allocated_wtree)); bzero(&allocated_wtree,sizeof(allocated_wtree));
init_tree(&aio.dtree,0,sizeof(FT_SUPERDOC),(qsort_cmp)&FT_SUPERDOC_cmp,0, init_tree(&aio.dtree,0,sizeof(FT_SUPERDOC),(qsort_cmp2)&FT_SUPERDOC_cmp,0,
NULL); NULL);
if(!(wtree=ft_parse(&allocated_wtree,query,query_len))) if(!(wtree=ft_parse(&allocated_wtree,query,query_len)))
......
...@@ -38,7 +38,8 @@ typedef struct st_ft_docstat { ...@@ -38,7 +38,8 @@ typedef struct st_ft_docstat {
byte *keybuf; byte *keybuf;
} FT_DOCSTAT; } FT_DOCSTAT;
static int FT_WORD_cmp(FT_WORD *w1, FT_WORD *w2) static int FT_WORD_cmp(void* cmp_arg __attribute__((unused)),
FT_WORD *w1, FT_WORD *w2)
{ {
return _mi_compare_text(default_charset_info, return _mi_compare_text(default_charset_info,
(uchar*) w1->pos,w1->len, (uchar*) w1->pos,w1->len,
...@@ -225,7 +226,7 @@ TREE * ft_parse(TREE *wtree, byte *doc, int doclen) ...@@ -225,7 +226,7 @@ TREE * ft_parse(TREE *wtree, byte *doc, int doclen)
if (!is_tree_inited(wtree)) if (!is_tree_inited(wtree))
{ {
init_tree(wtree,0,sizeof(FT_WORD),(qsort_cmp)&FT_WORD_cmp,0,NULL); init_tree(wtree,0,sizeof(FT_WORD),(qsort_cmp2)&FT_WORD_cmp,0,NULL);
} }
while (ft_simple_get_word(&doc,end,&w)) while (ft_simple_get_word(&doc,end,&w))
......
...@@ -25,7 +25,8 @@ typedef struct st_ft_stopwords { ...@@ -25,7 +25,8 @@ typedef struct st_ft_stopwords {
static TREE *stopwords3=NULL; static TREE *stopwords3=NULL;
static int FT_STOPWORD_cmp(FT_STOPWORD *w1, FT_STOPWORD *w2) static int FT_STOPWORD_cmp(void* cmp_arg __attribute__((unused)),
FT_STOPWORD *w1, FT_STOPWORD *w2)
{ {
return _mi_compare_text(default_charset_info, return _mi_compare_text(default_charset_info,
(uchar *)w1->pos,w1->len, (uchar *)w1->pos,w1->len,
...@@ -40,7 +41,7 @@ int ft_init_stopwords(const char **sws) ...@@ -40,7 +41,7 @@ int ft_init_stopwords(const char **sws)
if(!stopwords3) if(!stopwords3)
{ {
if(!(stopwords3=(TREE *)my_malloc(sizeof(TREE),MYF(0)))) return -1; if(!(stopwords3=(TREE *)my_malloc(sizeof(TREE),MYF(0)))) return -1;
init_tree(stopwords3,0,sizeof(FT_STOPWORD),(qsort_cmp)&FT_STOPWORD_cmp,0, init_tree(stopwords3,0,sizeof(FT_STOPWORD),(qsort_cmp2)&FT_STOPWORD_cmp,0,
NULL); NULL);
} }
......
...@@ -124,7 +124,8 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, ...@@ -124,7 +124,8 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees,
uint trees, uint trees,
HUFF_COUNTS *huff_counts, HUFF_COUNTS *huff_counts,
uint fields); uint fields);
static int compare_tree(const uchar *s,const uchar *t); static int compare_tree(void* cmp_arg __attribute__((unused)),
const uchar *s,const uchar *t);
static int get_statistic(MRG_INFO *mrg,HUFF_COUNTS *huff_counts); static int get_statistic(MRG_INFO *mrg,HUFF_COUNTS *huff_counts);
static void check_counts(HUFF_COUNTS *huff_counts,uint trees, static void check_counts(HUFF_COUNTS *huff_counts,uint trees,
my_off_t records); my_off_t records);
...@@ -673,7 +674,7 @@ static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records) ...@@ -673,7 +674,7 @@ static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records)
(type == FIELD_NORMAL || (type == FIELD_NORMAL ||
type == FIELD_SKIPP_ZERO)) type == FIELD_SKIPP_ZERO))
count[i].max_zero_fill= count[i].field_length; count[i].max_zero_fill= count[i].field_length;
init_tree(&count[i].int_tree,0,-1,(qsort_cmp) compare_tree,0,NULL); init_tree(&count[i].int_tree,0,-1,(qsort_cmp2) compare_tree,0,NULL);
if (records && type != FIELD_BLOB && type != FIELD_VARCHAR) if (records && type != FIELD_BLOB && type != FIELD_VARCHAR)
count[i].tree_pos=count[i].tree_buff = count[i].tree_pos=count[i].tree_buff =
my_malloc(count[i].field_length > 1 ? tree_buff_length : 2, my_malloc(count[i].field_length > 1 ? tree_buff_length : 2,
...@@ -1289,7 +1290,8 @@ static int make_huff_tree(HUFF_TREE *huff_tree, HUFF_COUNTS *huff_counts) ...@@ -1289,7 +1290,8 @@ static int make_huff_tree(HUFF_TREE *huff_tree, HUFF_COUNTS *huff_counts)
return 0; return 0;
} }
static int compare_tree(register const uchar *s, register const uchar *t) static int compare_tree(void* cmp_arg __attribute__((unused)),
register const uchar *s, register const uchar *t)
{ {
uint length; uint length;
for (length=global_count->field_length; length-- ;) for (length=global_count->field_length; length-- ;)
......
...@@ -63,7 +63,7 @@ static void rb_delete_fixup(TREE *tree,TREE_ELEMENT ***parent); ...@@ -63,7 +63,7 @@ static void rb_delete_fixup(TREE *tree,TREE_ELEMENT ***parent);
/* The actuall code for handling binary trees */ /* The actuall code for handling binary trees */
void init_tree(TREE *tree, uint default_alloc_size, int size, void init_tree(TREE *tree, uint default_alloc_size, int size,
qsort_cmp compare, my_bool with_delete, qsort_cmp2 compare, my_bool with_delete,
void (*free_element) (void *)) void (*free_element) (void *))
{ {
DBUG_ENTER("init_tree"); DBUG_ENTER("init_tree");
...@@ -77,6 +77,7 @@ void init_tree(TREE *tree, uint default_alloc_size, int size, ...@@ -77,6 +77,7 @@ void init_tree(TREE *tree, uint default_alloc_size, int size,
tree->size_of_element=size > 0 ? (uint) size : 0; tree->size_of_element=size > 0 ? (uint) size : 0;
tree->free=free_element; tree->free=free_element;
tree->elements_in_tree=0; tree->elements_in_tree=0;
tree->cmp_arg = 0;
tree->null_element.colour=BLACK; tree->null_element.colour=BLACK;
tree->null_element.left=tree->null_element.right=0; tree->null_element.left=tree->null_element.right=0;
if (!free_element && size >= 0 && if (!free_element && size >= 0 &&
...@@ -152,7 +153,8 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size) ...@@ -152,7 +153,8 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size)
for (;;) for (;;)
{ {
if (element == &tree->null_element || if (element == &tree->null_element ||
(cmp=(*tree->compare)(ELEMENT_KEY(tree,element),key)) == 0) (cmp=(*tree->compare)(tree->cmp_arg,
ELEMENT_KEY(tree,element),key)) == 0)
break; break;
if (cmp < 0) if (cmp < 0)
{ {
...@@ -212,7 +214,8 @@ int tree_delete(TREE *tree, void *key) ...@@ -212,7 +214,8 @@ int tree_delete(TREE *tree, void *key)
{ {
if (element == &tree->null_element) if (element == &tree->null_element)
return 1; /* Was not in tree */ return 1; /* Was not in tree */
if ((cmp=(*tree->compare)(ELEMENT_KEY(tree,element),key)) == 0) if ((cmp=(*tree->compare)(tree->cmp_arg,
ELEMENT_KEY(tree,element),key)) == 0)
break; break;
if (cmp < 0) if (cmp < 0)
{ {
...@@ -266,7 +269,8 @@ void *tree_search(TREE *tree, void *key) ...@@ -266,7 +269,8 @@ void *tree_search(TREE *tree, void *key)
{ {
if (element == &tree->null_element) if (element == &tree->null_element)
return (void*) 0; return (void*) 0;
if ((cmp=(*tree->compare)(ELEMENT_KEY(tree,element),key)) == 0) if ((cmp=(*tree->compare)(tree->cmp_arg,
ELEMENT_KEY(tree,element),key)) == 0)
return ELEMENT_KEY(tree,element); return ELEMENT_KEY(tree,element);
if (cmp < 0) if (cmp < 0)
element=element->right; element=element->right;
......
...@@ -38,6 +38,37 @@ ...@@ -38,6 +38,37 @@
#define UINT_MAX24 0xffffff #define UINT_MAX24 0xffffff
#define UINT_MAX32 0xffffffff #define UINT_MAX32 0xffffffff
int sortcmp2(void* cmp_arg __attribute__((unused)),
const String *a,const String *b)
{
return sortcmp(a,b);
}
int stringcmp2(void* cmp_arg __attribute__((unused)),
const String *a,const String *b)
{
return stringcmp(a,b);
}
int compare_double2(void* cmp_arg __attribute__((unused)),
const double *s, const double *t)
{
return compare_double(s,t);
}
int compare_longlong2(void* cmp_arg __attribute__((unused)),
const longlong *s, const longlong *t)
{
return compare_longlong(s,t);
}
int compare_ulonglong2(void* cmp_arg __attribute__((unused)),
const ulonglong *s, const ulonglong *t)
{
return compare_ulonglong(s,t);
}
Procedure * Procedure *
proc_analyse_init(THD *thd, ORDER *param, select_result *result, proc_analyse_init(THD *thd, ORDER *param, select_result *result,
List<Item> &field_list) List<Item> &field_list)
......
...@@ -53,8 +53,14 @@ uint check_ulonglong(const char *str, uint length); ...@@ -53,8 +53,14 @@ uint check_ulonglong(const char *str, uint length);
bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num); bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num);
bool test_if_number(NUM_INFO *info, const char *str, uint str_len); bool test_if_number(NUM_INFO *info, const char *str, uint str_len);
int compare_double(const double *s, const double *t); int compare_double(const double *s, const double *t);
int compare_double2(void* cmp_arg __attribute__((unused)),
const double *s, const double *t);
int compare_longlong(const longlong *s, const longlong *t); int compare_longlong(const longlong *s, const longlong *t);
int compare_longlong2(void* cmp_arg __attribute__((unused)),
const longlong *s, const longlong *t);
int compare_ulonglong(const ulonglong *s, const ulonglong *t); int compare_ulonglong(const ulonglong *s, const ulonglong *t);
int compare_ulonglong2(void* cmp_arg __attribute__((unused)),
const ulonglong *s, const ulonglong *t);
Procedure *proc_analyse_init(THD *thd, ORDER *param, select_result *result, Procedure *proc_analyse_init(THD *thd, ORDER *param, select_result *result,
List<Item> &field_list); List<Item> &field_list);
void free_string(String*); void free_string(String*);
...@@ -91,6 +97,11 @@ class field_info :public Sql_alloc ...@@ -91,6 +97,11 @@ class field_info :public Sql_alloc
int collect_string(String *element, element_count count, int collect_string(String *element, element_count count,
TREE_INFO *info); TREE_INFO *info);
int sortcmp2(void* cmp_arg __attribute__((unused)),
const String *a,const String *b);
int stringcmp2(void* cmp_arg __attribute__((unused)),
const String *a,const String *b);
class field_str :public field_info class field_str :public field_info
{ {
String min_arg, max_arg; String min_arg, max_arg;
...@@ -106,7 +117,7 @@ class field_str :public field_info ...@@ -106,7 +117,7 @@ class field_str :public field_info
must_be_blob(0), was_zero_fill(0), must_be_blob(0), was_zero_fill(0),
was_maybe_zerofill(0), can_be_still_num(1) was_maybe_zerofill(0), can_be_still_num(1)
{ init_tree(&tree, 0, sizeof(String), a->binary ? { init_tree(&tree, 0, sizeof(String), a->binary ?
(qsort_cmp) stringcmp : (qsort_cmp) sortcmp, (qsort_cmp2) stringcmp2 : (qsort_cmp2) sortcmp2,
0, (void (*)(void*)) free_string); }; 0, (void (*)(void*)) free_string); };
void add(); void add();
...@@ -146,7 +157,7 @@ class field_real: public field_info ...@@ -146,7 +157,7 @@ class field_real: public field_info
field_real(Item* a, analyse* b) :field_info(a,b), field_real(Item* a, analyse* b) :field_info(a,b),
min_arg(0), max_arg(0), sum(0), sum_sqr(0), max_notzero_dec_len(0) min_arg(0), max_arg(0), sum(0), sum_sqr(0), max_notzero_dec_len(0)
{ init_tree(&tree, 0, sizeof(double), { init_tree(&tree, 0, sizeof(double),
(qsort_cmp) compare_double, 0, NULL); } (qsort_cmp2) compare_double2, 0, NULL); }
void add(); void add();
void get_opt_type(String*, ha_rows); void get_opt_type(String*, ha_rows);
...@@ -192,7 +203,7 @@ class field_longlong: public field_info ...@@ -192,7 +203,7 @@ class field_longlong: public field_info
field_longlong(Item* a, analyse* b) :field_info(a,b), field_longlong(Item* a, analyse* b) :field_info(a,b),
min_arg(0), max_arg(0), sum(0), sum_sqr(0) min_arg(0), max_arg(0), sum(0), sum_sqr(0)
{ init_tree(&tree, 0, sizeof(longlong), { init_tree(&tree, 0, sizeof(longlong),
(qsort_cmp) compare_longlong, 0, NULL); } (qsort_cmp2) compare_longlong2, 0, NULL); }
void add(); void add();
void get_opt_type(String*, ha_rows); void get_opt_type(String*, ha_rows);
...@@ -237,7 +248,7 @@ class field_ulonglong: public field_info ...@@ -237,7 +248,7 @@ class field_ulonglong: public field_info
field_ulonglong(Item* a, analyse * b) :field_info(a,b), field_ulonglong(Item* a, analyse * b) :field_info(a,b),
min_arg(0), max_arg(0), sum(0),sum_sqr(0) min_arg(0), max_arg(0), sum(0),sum_sqr(0)
{ init_tree(&tree, 0, sizeof(ulonglong), { init_tree(&tree, 0, sizeof(ulonglong),
(qsort_cmp) compare_ulonglong, 0, NULL); } (qsort_cmp2) compare_ulonglong2, 0, NULL); }
void add(); void add();
void get_opt_type(String*, ha_rows); void get_opt_type(String*, ha_rows);
String *get_min_arg(String *s) { s->set(min_arg); return s; } String *get_min_arg(String *s) { s->set(min_arg); return s; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment