1 /* Copyright (c) 2000, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
17 Radixsort for pointers to fixed length strings.
18 A very quick sort for not to long (< 20 char) strings.
19 Neads a extra buffers of number_of_elements pointers but is
20 2-3 times faster than quicksort
23 #include "mysys_priv.h"
28 void radixsort_for_str_ptr(uchar
**base
, uint number_of_elements
, size_t size_of_element
, uchar
**buffer
)
30 uchar
**end
,**ptr
,**buffer_ptr
;
31 uint32
*count_ptr
,*count_end
,count
[256];
34 end
=base
+number_of_elements
; count_end
=count
+256;
35 for (pass
=(int) size_of_element
-1 ; pass
>= 0 ; pass
--)
37 bzero((uchar
*) count
,sizeof(uint32
)*256);
38 for (ptr
= base
; ptr
< end
; ptr
++)
39 count
[ptr
[0][pass
]]++;
40 if (count
[0] == number_of_elements
)
42 for (count_ptr
=count
+1 ; count_ptr
< count_end
; count_ptr
++)
44 if (*count_ptr
== number_of_elements
)
46 (*count_ptr
)+= *(count_ptr
-1);
48 for (ptr
= end
; ptr
-- != base
;)
49 buffer
[--count
[ptr
[0][pass
]]]= *ptr
;
50 for (ptr
=base
, buffer_ptr
=buffer
; ptr
< end
;)
51 (*ptr
++) = *buffer_ptr
++;