~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
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.
6
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.
11
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 */
15
16
/*
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
21
*/
22
23
#include "mysys_priv.h"
212.5.18 by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype.
24
#include <mystrings/m_string.h>
1 by brian
clean slate
25
26
	/* Radixsort */
27
482 by Brian Aker
Remove uint.
28
void radixsort_for_str_ptr(unsigned char **base, uint32_t number_of_elements, size_t size_of_element, unsigned char **buffer)
1 by brian
clean slate
29
{
481 by Brian Aker
Remove all of uchar.
30
  unsigned char **end,**ptr,**buffer_ptr;
205 by Brian Aker
uint32 -> uin32_t
31
  uint32_t *count_ptr,*count_end,count[256];
1 by brian
clean slate
32
  int pass;
33
34
  end=base+number_of_elements; count_end=count+256;
35
  for (pass=(int) size_of_element-1 ; pass >= 0 ; pass--)
36
  {
212.6.14 by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove().
37
    memset(count, 0, sizeof(uint32_t)*256);
1 by brian
clean slate
38
    for (ptr= base ; ptr < end ; ptr++)
39
      count[ptr[0][pass]]++;
40
    if (count[0] == number_of_elements)
41
      goto next;
42
    for (count_ptr=count+1 ; count_ptr < count_end ; count_ptr++)
43
    {
44
      if (*count_ptr == number_of_elements)
45
	goto next;
46
      (*count_ptr)+= *(count_ptr-1);
47
    }
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++;
52
  next:;
53
  }
54
}