Drizzled Public API Documentation

mf_radix.cc
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /*
00017   Radixsort for pointers to fixed length strings.
00018   A very quick sort for not to long (< 20 char) strings.
00019   Neads a extra buffers of number_of_elements pointers but is
00020   2-3 times faster than quicksort
00021 */
00022 
00023 #include <config.h>
00024 
00025 #include <drizzled/internal/my_sys.h>
00026 #include <drizzled/internal/m_string.h>
00027 
00028 namespace drizzled
00029 {
00030 namespace internal
00031 {
00032 
00033   /* Radixsort */
00034 
00035 void radixsort_for_str_ptr(unsigned char **base, uint32_t number_of_elements, size_t size_of_element, unsigned char **buffer)
00036 {
00037   unsigned char **end,**ptr,**buffer_ptr;
00038   uint32_t *count_ptr,*count_end,count[256];
00039   int pass;
00040 
00041   end=base+number_of_elements; count_end=count+256;
00042   for (pass=(int) size_of_element-1 ; pass >= 0 ; pass--)
00043   {
00044     memset(count, 0, sizeof(uint32_t)*256);
00045     for (ptr= base ; ptr < end ; ptr++)
00046       count[ptr[0][pass]]++;
00047     if (count[0] == number_of_elements)
00048       goto next;
00049     for (count_ptr=count+1 ; count_ptr < count_end ; count_ptr++)
00050     {
00051       if (*count_ptr == number_of_elements)
00052   goto next;
00053       (*count_ptr)+= *(count_ptr-1);
00054     }
00055     for (ptr= end ; ptr-- != base ;)
00056       buffer[--count[ptr[0][pass]]]= *ptr;
00057     for (ptr=base, buffer_ptr=buffer ; ptr < end ;)
00058       (*ptr++) = *buffer_ptr++;
00059   next:;
00060   }
00061 }
00062 
00063 } /* namespace internal */
00064 } /* namespace drizzled */