Commit 89d6e639 authored by unknown's avatar unknown

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


include/global.h:
  qsort_cmp2
include/my_tree.h:
  use qsort_cmp2
myisam/ft_boolean_search.c:
  use qsort_cmp2
myisam/ft_nlq_search.c:
  use qsort_cmp2
myisam/ft_parser.c:
  use qsort_cmp2
myisam/ft_stopwords.c:
  use qsort_cmp2
myisam/myisampack.c:
  use qsort_cmp2
mysys/tree.c:
  use qsort_cmp2
sql/sql_analyse.cc:
  use qsort_cmp2
sql/sql_analyse.h:
  use qsort_cmp2
parent 174fdf05
......@@ -349,6 +349,7 @@ typedef int pshort; /* Mixed prototypes can't take short int */
typedef double pfloat; /* Mixed prototypes can't take float */
#endif
typedef int (*qsort_cmp)(const void *,const void *);
typedef int (*qsort_cmp2)(void*, const void *,const void *);
#ifdef HAVE_mit_thread
#define qsort_t void
#undef QSORT_TYPE_IS_VOID
......
......@@ -50,7 +50,8 @@ typedef struct st_tree {
TREE_ELEMENT *root,null_element;
TREE_ELEMENT **parents[MAX_TREE_HIGHT];
uint offset_to_key,elements_in_tree,size_of_element;
qsort_cmp compare;
qsort_cmp2 compare;
void* cmp_arg;
MEM_ROOT mem_root;
my_bool with_delete;
void (*free)(void *);
......@@ -58,7 +59,7 @@ typedef struct st_tree {
/* Functions on hole tree */
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 delete_tree(TREE*);
#define is_tree_inited(tree) ((tree)->root != 0)
......
......@@ -41,7 +41,8 @@ typedef struct st_ft_superdoc {
ALL_IN_ONE *aio;
} 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)
return -1;
......
......@@ -35,7 +35,8 @@ typedef struct st_ft_superdoc {
double tmp_weight;
} 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)
return -1;
......@@ -162,7 +163,7 @@ FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query,
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);
if(!(wtree=ft_parse(&allocated_wtree,query,query_len)))
......
......@@ -38,7 +38,8 @@ typedef struct st_ft_docstat {
byte *keybuf;
} 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,
(uchar*) w1->pos,w1->len,
......@@ -225,7 +226,7 @@ TREE * ft_parse(TREE *wtree, byte *doc, int doclen)
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))
......
......@@ -25,7 +25,8 @@ typedef struct st_ft_stopwords {
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,
(uchar *)w1->pos,w1->len,
......@@ -40,7 +41,7 @@ int ft_init_stopwords(const char **sws)
if(!stopwords3)
{
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);
}
......
......@@ -124,7 +124,8 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees,
uint trees,
HUFF_COUNTS *huff_counts,
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 void check_counts(HUFF_COUNTS *huff_counts,uint trees,
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_SKIPP_ZERO))
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)
count[i].tree_pos=count[i].tree_buff =
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)
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;
for (length=global_count->field_length; length-- ;)
......
......@@ -63,7 +63,7 @@ static void rb_delete_fixup(TREE *tree,TREE_ELEMENT ***parent);
/* The actuall code for handling binary trees */
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 *))
{
DBUG_ENTER("init_tree");
......@@ -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->free=free_element;
tree->elements_in_tree=0;
tree->cmp_arg = 0;
tree->null_element.colour=BLACK;
tree->null_element.left=tree->null_element.right=0;
if (!free_element && size >= 0 &&
......@@ -152,7 +153,8 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size)
for (;;)
{
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;
if (cmp < 0)
{
......@@ -212,7 +214,8 @@ int tree_delete(TREE *tree, void *key)
{
if (element == &tree->null_element)
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;
if (cmp < 0)
{
......@@ -266,7 +269,8 @@ void *tree_search(TREE *tree, void *key)
{
if (element == &tree->null_element)
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);
if (cmp < 0)
element=element->right;
......
......@@ -38,6 +38,37 @@
#define UINT_MAX24 0xffffff
#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 *
proc_analyse_init(THD *thd, ORDER *param, select_result *result,
List<Item> &field_list)
......
......@@ -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 test_if_number(NUM_INFO *info, const char *str, uint str_len);
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_longlong2(void* cmp_arg __attribute__((unused)),
const longlong *s, const longlong *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,
List<Item> &field_list);
void free_string(String*);
......@@ -91,6 +97,11 @@ class field_info :public Sql_alloc
int collect_string(String *element, element_count count,
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
{
String min_arg, max_arg;
......@@ -106,7 +117,7 @@ class field_str :public field_info
must_be_blob(0), was_zero_fill(0),
was_maybe_zerofill(0), can_be_still_num(1)
{ 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); };
void add();
......@@ -146,7 +157,7 @@ class field_real: public field_info
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)
{ init_tree(&tree, 0, sizeof(double),
(qsort_cmp) compare_double, 0, NULL); }
(qsort_cmp2) compare_double2, 0, NULL); }
void add();
void get_opt_type(String*, ha_rows);
......@@ -192,7 +203,7 @@ class field_longlong: public field_info
field_longlong(Item* a, analyse* b) :field_info(a,b),
min_arg(0), max_arg(0), sum(0), sum_sqr(0)
{ init_tree(&tree, 0, sizeof(longlong),
(qsort_cmp) compare_longlong, 0, NULL); }
(qsort_cmp2) compare_longlong2, 0, NULL); }
void add();
void get_opt_type(String*, ha_rows);
......@@ -237,7 +248,7 @@ class field_ulonglong: public field_info
field_ulonglong(Item* a, analyse * b) :field_info(a,b),
min_arg(0), max_arg(0), sum(0),sum_sqr(0)
{ init_tree(&tree, 0, sizeof(ulonglong),
(qsort_cmp) compare_ulonglong, 0, NULL); }
(qsort_cmp2) compare_ulonglong2, 0, NULL); }
void add();
void get_opt_type(String*, ha_rows);
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