Make all bucket and overflow addresses unsigned
[unix-history] / usr / src / lib / libc / stdlib / radixsort.3
CommitLineData
f944261e
KB
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
70c0cb05 6.\" @(#)radixsort.3 5.4 (Berkeley) %G%
f944261e
KB
7.\"
8.TH radixsort 3 ""
9.SH NAME
10radixsort \- radix sort
11.SH SYNOPSIS
12.nf
13.ft B
14#include <limits.h>
15#include <stdlib.h>
16
17radixsort(u_char **base, int nmemb, u_char *table, u_char endbyte);
18.ft R
19.fi
20.SH DESCRIPTION
21.I Radixsort
22is a modified radix sort.
23.PP
24The
25.I radixsort
26function sorts an array of
27.I nmemb
28pointers to byte strings, the initial member of which is referenced
29by
30.IR base .
31The byte strings may contain any values; the end of each string
32is denoted by the user-specified value
33.IR endbyte .
34The contents of the array are sorted in ascending order according
35to the ASCII order of the byte strings they reference.
36.PP
37Applications may specify a sort order by providing the
38.IR table
39argument.
40If non-NULL,
41.I table
e061e641
KB
42must reference an array of UCHAR_MAX + 1 bytes which contains the sort
43weight of each possible byte value.
f944261e
KB
44The end-of-string byte must have a sort weight of 0.
45More than one byte may have the same sort weight.
46.I Table
47is useful for applications which wish to sort different characters
48equally; for example, providing a table with the same weights
49for A-Z as for a-z will result in a case-insensitive sort.
50.PP
51.I Radixsort
52is stable, that is, if two elements compare as equal, their order in
53the sorted array is unchanged.
54.PP
55.I Radixsort
79f7b2d7
KB
56is a variant of most-significant-byte radix sorting; in particular, see
57D.E. Knuth's Algorithm R and section 5.2.5, exercise 10.
f944261e
KB
58.I Radixsort
59takes linear time relative to the number of bytes in the strings.
60.SH SEE ALSO
61sort(1), qsort(3)
79f7b2d7
KB
62.sp
63Knuth, D.E. [1968]. "The Art of Computer Programming Vol. 3:
64Sorting and Searching", pp. 170-178.
65.br
66Paige, R. [1987]. "Three Partition Refinement Algorithms",
67SIAM J. Comput. Vol. 16, No. 6.
f944261e
KB
68.SH "RETURN VALUES"
69Upon successful completion 0 is returned.
70Otherwise, \-1 is returned and the global variable
71.I errno
72is set to indicate the error.
73.SH ERRORS
74.I Radixsort
75may fail and set
76.I errno
77for any of the errors specified for the library routine
78.IR malloc (3).
70c0cb05
KB
79.SH BUGS
80.I Nmemb
81must be less than the maximum integer, INT_MAX.