~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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
23
#include <config.h>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
24
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
25
#include <drizzled/internal/my_sys.h>
26
#include <drizzled/internal/m_string.h>
1 by brian
clean slate
27
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
28
namespace drizzled
29
{
30
namespace internal
31
{
32
1 by brian
clean slate
33
	/* Radixsort */
34
482 by Brian Aker
Remove uint.
35
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
36
{
481 by Brian Aker
Remove all of uchar.
37
  unsigned char **end,**ptr,**buffer_ptr;
205 by Brian Aker
uint32 -> uin32_t
38
  uint32_t *count_ptr,*count_end,count[256];
1 by brian
clean slate
39
  int pass;
40
41
  end=base+number_of_elements; count_end=count+256;
42
  for (pass=(int) size_of_element-1 ; pass >= 0 ; pass--)
43
  {
212.6.14 by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove().
44
    memset(count, 0, sizeof(uint32_t)*256);
1 by brian
clean slate
45
    for (ptr= base ; ptr < end ; ptr++)
46
      count[ptr[0][pass]]++;
47
    if (count[0] == number_of_elements)
48
      goto next;
49
    for (count_ptr=count+1 ; count_ptr < count_end ; count_ptr++)
50
    {
51
      if (*count_ptr == number_of_elements)
52
	goto next;
53
      (*count_ptr)+= *(count_ptr-1);
54
    }
55
    for (ptr= end ; ptr-- != base ;)
56
      buffer[--count[ptr[0][pass]]]= *ptr;
57
    for (ptr=base, buffer_ptr=buffer ; ptr < end ;)
58
      (*ptr++) = *buffer_ptr++;
59
  next:;
60
  }
61
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
62
63
} /* namespace internal */
64
} /* namespace drizzled */