1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
get_ptr_compare(len) returns a pointer to a optimal byte-compare function
18
for a array of stringpointer where all strings have size len.
19
The bytes are compare as unsigned chars.
22
#include "mysys_priv.h"
23
#include <myisampack.h>
25
static int ptr_compare(size_t *compare_length, uchar **a, uchar **b);
26
static int ptr_compare_0(size_t *compare_length, uchar **a, uchar **b);
27
static int ptr_compare_1(size_t *compare_length, uchar **a, uchar **b);
28
static int ptr_compare_2(size_t *compare_length, uchar **a, uchar **b);
29
static int ptr_compare_3(size_t *compare_length, uchar **a, uchar **b);
31
/* Get a pointer to a optimal byte-compare function for a given size */
33
qsort2_cmp get_ptr_compare (size_t size)
36
return (qsort2_cmp) ptr_compare;
38
case 0: return (qsort2_cmp) ptr_compare_0;
39
case 1: return (qsort2_cmp) ptr_compare_1;
40
case 2: return (qsort2_cmp) ptr_compare_2;
41
case 3: return (qsort2_cmp) ptr_compare_3;
43
return 0; /* Impossible */
48
Compare to keys to see witch is smaller.
49
Loop unrolled to make it quick !!
52
#define cmp(N) if (first[N] != last[N]) return (int) first[N] - (int) last[N]
54
static int ptr_compare(size_t *compare_length, uchar **a, uchar **b)
56
register int length= *compare_length;
57
register uchar *first,*last;
62
if (*first++ != *last++)
63
return (int) first[-1] - (int) last[-1];
65
return (int) first[0] - (int) last[0];
69
static int ptr_compare_0(size_t *compare_length,uchar **a, uchar **b)
71
register int length= *compare_length;
72
register uchar *first,*last;
90
static int ptr_compare_1(size_t *compare_length,uchar **a, uchar **b)
92
register int length= *compare_length-1;
93
register uchar *first,*last;
95
first= *a+1; last= *b+1;
111
static int ptr_compare_2(size_t *compare_length,uchar **a, uchar **b)
113
register int length= *compare_length-2;
114
register uchar *first,*last;
116
first= *a +2 ; last= *b +2;
133
static int ptr_compare_3(size_t *compare_length,uchar **a, uchar **b)
135
register int length= *compare_length-3;
136
register uchar *first,*last;
138
first= *a +3 ; last= *b +3;
156
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos)
158
switch (pack_length) {
160
case 8: mi_int8store(buff,pos); break;
161
case 7: mi_int7store(buff,pos); break;
162
case 6: mi_int6store(buff,pos); break;
163
case 5: mi_int5store(buff,pos); break;
165
case 4: mi_int4store(buff,pos); break;
166
case 3: mi_int3store(buff,pos); break;
167
case 2: mi_int2store(buff,pos); break;
168
case 1: buff[0]= (uchar) pos; break;
169
default: DBUG_ASSERT(0);
174
my_off_t my_get_ptr(uchar *ptr, size_t pack_length)
177
switch (pack_length) {
179
case 8: pos= (my_off_t) mi_uint8korr(ptr); break;
180
case 7: pos= (my_off_t) mi_uint7korr(ptr); break;
181
case 6: pos= (my_off_t) mi_uint6korr(ptr); break;
182
case 5: pos= (my_off_t) mi_uint5korr(ptr); break;
184
case 4: pos= (my_off_t) mi_uint4korr(ptr); break;
185
case 3: pos= (my_off_t) mi_uint3korr(ptr); break;
186
case 2: pos= (my_off_t) mi_uint2korr(ptr); break;
187
case 1: pos= (my_off_t) *(uchar*) ptr; break;
188
default: DBUG_ASSERT(0); return 0;