158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1991, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 658f0484fSRodney W. Grimes.\" are met: 758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 858f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1058f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1158f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 12*580b4d18SEd Maste.\" 3. Neither the name of the University nor the names of its contributors 1358f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1458f0484fSRodney W. Grimes.\" without specific prior written permission. 1558f0484fSRodney W. Grimes.\" 1658f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1758f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1858f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1958f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2058f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2158f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2258f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2358f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2458f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2558f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2658f0484fSRodney W. Grimes.\" SUCH DAMAGE. 2758f0484fSRodney W. Grimes.\" 2858f0484fSRodney W. Grimes.\" @(#)radixsort.3 8.2 (Berkeley) 1/27/94 297f3dea24SPeter Wemm.\" $FreeBSD$ 3058f0484fSRodney W. Grimes.\" 3158f0484fSRodney W. Grimes.Dd January 27, 1994 3258f0484fSRodney W. Grimes.Dt RADIXSORT 3 3358f0484fSRodney W. Grimes.Os 3458f0484fSRodney W. Grimes.Sh NAME 35cb30b9c5SRuslan Ermilov.Nm radixsort , sradixsort 3658f0484fSRodney W. Grimes.Nd radix sort 3725bb73e0SAlexey Zelkin.Sh LIBRARY 3825bb73e0SAlexey Zelkin.Lb libc 3958f0484fSRodney W. Grimes.Sh SYNOPSIS 408aefde06SJeroen Ruigrok van der Werven.In limits.h 418aefde06SJeroen Ruigrok van der Werven.In stdlib.h 4258f0484fSRodney W. Grimes.Ft int 43a3315650SBruce Evans.Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" 4458f0484fSRodney W. Grimes.Ft int 45a3315650SBruce Evans.Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" 4658f0484fSRodney W. Grimes.Sh DESCRIPTION 4758f0484fSRodney W. GrimesThe 4858f0484fSRodney W. Grimes.Fn radixsort 4958f0484fSRodney W. Grimesand 5058f0484fSRodney W. Grimes.Fn sradixsort 5158f0484fSRodney W. Grimesfunctions 5258f0484fSRodney W. Grimesare implementations of radix sort. 5358f0484fSRodney W. Grimes.Pp 5458f0484fSRodney W. GrimesThese functions sort an array of pointers to byte strings, the initial 5558f0484fSRodney W. Grimesmember of which is referenced by 5658f0484fSRodney W. Grimes.Fa base . 5758f0484fSRodney W. GrimesThe byte strings may contain any values; the end of each string 5858f0484fSRodney W. Grimesis denoted by the user-specified value 5958f0484fSRodney W. Grimes.Fa endbyte . 6058f0484fSRodney W. Grimes.Pp 6158f0484fSRodney W. GrimesApplications may specify a sort order by providing the 6258f0484fSRodney W. Grimes.Fa table 6358f0484fSRodney W. Grimesargument. 6458f0484fSRodney W. GrimesIf 6558f0484fSRodney W. Grimes.Pf non- Dv NULL , 6658f0484fSRodney W. Grimes.Fa table 6758f0484fSRodney W. Grimesmust reference an array of 6858f0484fSRodney W. Grimes.Dv UCHAR_MAX 6958f0484fSRodney W. Grimes+ 1 bytes which contains the sort 7058f0484fSRodney W. Grimesweight of each possible byte value. 7158f0484fSRodney W. GrimesThe end-of-string byte must have a sort weight of 0 or 255 7258f0484fSRodney W. Grimes(for sorting in reverse order). 7358f0484fSRodney W. GrimesMore than one byte may have the same sort weight. 7458f0484fSRodney W. GrimesThe 7558f0484fSRodney W. Grimes.Fa table 7658f0484fSRodney W. Grimesargument 7758f0484fSRodney W. Grimesis useful for applications which wish to sort different characters 7858f0484fSRodney W. Grimesequally, for example, providing a table with the same weights 7958f0484fSRodney W. Grimesfor A-Z as for a-z will result in a case-insensitive sort. 8058f0484fSRodney W. GrimesIf 8158f0484fSRodney W. Grimes.Fa table 8258f0484fSRodney W. Grimesis NULL, the contents of the array are sorted in ascending order 8358f0484fSRodney W. Grimesaccording to the 8458f0484fSRodney W. Grimes.Tn ASCII 8558f0484fSRodney W. Grimesorder of the byte strings they reference and 8658f0484fSRodney W. Grimes.Fa endbyte 8758f0484fSRodney W. Grimeshas a sorting weight of 0. 8858f0484fSRodney W. Grimes.Pp 8958f0484fSRodney W. GrimesThe 9058f0484fSRodney W. Grimes.Fn sradixsort 9158f0484fSRodney W. Grimesfunction is stable, that is, if two elements compare as equal, their 9258f0484fSRodney W. Grimesorder in the sorted array is unchanged. 9358f0484fSRodney W. GrimesThe 9458f0484fSRodney W. Grimes.Fn sradixsort 9558f0484fSRodney W. Grimesfunction uses additional memory sufficient to hold 9658f0484fSRodney W. Grimes.Fa nmemb 9758f0484fSRodney W. Grimespointers. 9858f0484fSRodney W. Grimes.Pp 9958f0484fSRodney W. GrimesThe 10058f0484fSRodney W. Grimes.Fn radixsort 10158f0484fSRodney W. Grimesfunction is not stable, but uses no additional memory. 10258f0484fSRodney W. Grimes.Pp 10358f0484fSRodney W. GrimesThese functions are variants of most-significant-byte radix sorting; in 1041a0a9345SRuslan Ermilovparticular, see 1051a0a9345SRuslan Ermilov.An "D.E. Knuth" Ns 's 1061a0a9345SRuslan Ermilov.%T "Algorithm R" 1071a0a9345SRuslan Ermilovand section 5.2.5, exercise 10. 10858f0484fSRodney W. GrimesThey take linear time relative to the number of bytes in the strings. 10958f0484fSRodney W. Grimes.Sh RETURN VALUES 110b1250632SYaroslav Tykhiy.Rv -std radixsort 11158f0484fSRodney W. Grimes.Sh ERRORS 11258f0484fSRodney W. Grimes.Bl -tag -width Er 11358f0484fSRodney W. Grimes.It Bq Er EINVAL 11458f0484fSRodney W. GrimesThe value of the 11558f0484fSRodney W. Grimes.Fa endbyte 11658f0484fSRodney W. Grimeselement of 11758f0484fSRodney W. Grimes.Fa table 11858f0484fSRodney W. Grimesis not 0 or 255. 11958f0484fSRodney W. Grimes.El 12058f0484fSRodney W. Grimes.Pp 12158f0484fSRodney W. GrimesAdditionally, the 12258f0484fSRodney W. Grimes.Fn sradixsort 12358f0484fSRodney W. Grimesfunction 12458f0484fSRodney W. Grimesmay fail and set 12558f0484fSRodney W. Grimes.Va errno 12658f0484fSRodney W. Grimesfor any of the errors specified for the library routine 12758f0484fSRodney W. Grimes.Xr malloc 3 . 12858f0484fSRodney W. Grimes.Sh SEE ALSO 12958f0484fSRodney W. Grimes.Xr sort 1 , 13058f0484fSRodney W. Grimes.Xr qsort 3 13158f0484fSRodney W. Grimes.Pp 13258f0484fSRodney W. Grimes.Rs 13358f0484fSRodney W. Grimes.%A Knuth, D.E. 13458f0484fSRodney W. Grimes.%D 1968 13558f0484fSRodney W. Grimes.%B "The Art of Computer Programming" 13658f0484fSRodney W. Grimes.%T "Sorting and Searching" 13758f0484fSRodney W. Grimes.%V Vol. 3 13858f0484fSRodney W. Grimes.%P pp. 170-178 13958f0484fSRodney W. Grimes.Re 14058f0484fSRodney W. Grimes.Rs 14158f0484fSRodney W. Grimes.%A Paige, R. 14258f0484fSRodney W. Grimes.%D 1987 14358f0484fSRodney W. Grimes.%T "Three Partition Refinement Algorithms" 14458f0484fSRodney W. Grimes.%J "SIAM J. Comput." 14558f0484fSRodney W. Grimes.%V Vol. 16 14658f0484fSRodney W. Grimes.%N No. 6 14758f0484fSRodney W. Grimes.Re 14858f0484fSRodney W. Grimes.Rs 14958f0484fSRodney W. Grimes.%A McIlroy, P. 15058f0484fSRodney W. Grimes.%D 1993 15158f0484fSRodney W. Grimes.%B "Engineering Radix Sort" 15258f0484fSRodney W. Grimes.%T "Computing Systems" 15358f0484fSRodney W. Grimes.%V Vol. 6:1 15458f0484fSRodney W. Grimes.%P pp. 5-27 15558f0484fSRodney W. Grimes.Re 15658f0484fSRodney W. Grimes.Sh HISTORY 15758f0484fSRodney W. GrimesThe 15858f0484fSRodney W. Grimes.Fn radixsort 1597bdf80e5SMike Pritchardfunction first appeared in 1607bdf80e5SMike Pritchard.Bx 4.4 . 161