~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysys/mf_radix.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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"
 
24
#include <m_string.h>
 
25
 
 
26
        /* Radixsort */
 
27
 
 
28
void radixsort_for_str_ptr(uchar **base, uint number_of_elements, size_t size_of_element, uchar **buffer)
 
29
{
 
30
  uchar **end,**ptr,**buffer_ptr;
 
31
  uint32 *count_ptr,*count_end,count[256];
 
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
  {
 
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)
 
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
}