diff options
Diffstat (limited to 'src/lib/libc/stdlib/radixsort.3')
-rw-r--r-- | src/lib/libc/stdlib/radixsort.3 | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/radixsort.3 b/src/lib/libc/stdlib/radixsort.3 new file mode 100644 index 0000000000..8b0ea89a0f --- /dev/null +++ b/src/lib/libc/stdlib/radixsort.3 | |||
@@ -0,0 +1,161 @@ | |||
1 | .\" Copyright (c) 1990, 1991, 1993 | ||
2 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | ||
4 | .\" Redistribution and use in source and binary forms, with or without | ||
5 | .\" modification, are permitted provided that the following conditions | ||
6 | .\" are met: | ||
7 | .\" 1. Redistributions of source code must retain the above copyright | ||
8 | .\" notice, this list of conditions and the following disclaimer. | ||
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer in the | ||
11 | .\" documentation and/or other materials provided with the distribution. | ||
12 | .\" 3. All advertising materials mentioning features or use of this software | ||
13 | .\" must display the following acknowledgement: | ||
14 | .\" This product includes software developed by the University of | ||
15 | .\" California, Berkeley and its contributors. | ||
16 | .\" 4. Neither the name of the University nor the names of its contributors | ||
17 | .\" may be used to endorse or promote products derived from this software | ||
18 | .\" without specific prior written permission. | ||
19 | .\" | ||
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | .\" SUCH DAMAGE. | ||
31 | .\" | ||
32 | .\" $OpenBSD: radixsort.3,v 1.4 1998/06/15 17:55:08 mickey Exp $ | ||
33 | .\" | ||
34 | .Dd January 27, 1994 | ||
35 | .Dt RADIXSORT 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm radixsort | ||
39 | .Nd radix sort | ||
40 | .Sh SYNOPSIS | ||
41 | .Fd #include <limits.h> | ||
42 | .Fd #include <stdlib.h> | ||
43 | .Ft int | ||
44 | .Fn radixsort "const u_char **base" "int nmemb" "const u_char *table" "u_int endbyte" | ||
45 | .Ft int | ||
46 | .Fn sradixsort "const u_char **base" "int nmemb" "const u_char *table" "u_int endbyte" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn radixsort | ||
50 | and | ||
51 | .Fn sradixsort | ||
52 | functions | ||
53 | are implementations of radix sort. | ||
54 | .Pp | ||
55 | These functions sort an array of pointers to byte strings, the initial | ||
56 | member of which is referenced by | ||
57 | .Fa base . | ||
58 | The byte strings may contain any values; the end of each string | ||
59 | is denoted by the user-specified value | ||
60 | .Fa endbyte . | ||
61 | .Pp | ||
62 | Applications may specify a sort order by providing the | ||
63 | .Fa table | ||
64 | argument. | ||
65 | If | ||
66 | .Pf non- Dv NULL , | ||
67 | .Fa table | ||
68 | must reference an array of | ||
69 | .Dv UCHAR_MAX | ||
70 | + 1 bytes which contains the sort | ||
71 | weight of each possible byte value. | ||
72 | The end-of-string byte must have a sort weight of 0 or 255 | ||
73 | (for sorting in reverse order). | ||
74 | More than one byte may have the same sort weight. | ||
75 | The | ||
76 | .Fa table | ||
77 | argument | ||
78 | is useful for applications which wish to sort different characters | ||
79 | equally, for example, providing a table with the same weights | ||
80 | for A-Z as for a-z will result in a case-insensitive sort. | ||
81 | If | ||
82 | .Fa table | ||
83 | is NULL, the contents of the array are sorted in ascending order | ||
84 | according to the | ||
85 | .Tn ASCII | ||
86 | order of the byte strings they reference and | ||
87 | .Fa endbyte | ||
88 | has a sorting weight of 0. | ||
89 | .Pp | ||
90 | The | ||
91 | .Fn sradixsort | ||
92 | function is stable, that is, if two elements compare as equal, their | ||
93 | order in the sorted array is unchanged. | ||
94 | The | ||
95 | .Fn sradixsort | ||
96 | function uses additional memory sufficient to hold | ||
97 | .Fa nmemb | ||
98 | pointers. | ||
99 | .Pp | ||
100 | The | ||
101 | .Fn radixsort | ||
102 | function is not stable, but uses no additional memory. | ||
103 | .Pp | ||
104 | These functions are variants of most-significant-byte radix sorting; in | ||
105 | particular, see D.E. Knuth's Algorithm R and section 5.2.5, exercise 10. | ||
106 | They take linear time relative to the number of bytes in the strings. | ||
107 | .Sh RETURN VALUES | ||
108 | Upon successful completion 0 is returned. | ||
109 | Otherwise, \-1 is returned and the global variable | ||
110 | .Va errno | ||
111 | is set to indicate the error. | ||
112 | .Sh ERRORS | ||
113 | .Bl -tag -width Er | ||
114 | .It Bq Er EINVAL | ||
115 | The value of the | ||
116 | .Fa endbyte | ||
117 | element of | ||
118 | .Fa table | ||
119 | is not 0 or 255. | ||
120 | .El | ||
121 | .Pp | ||
122 | Additionally, the | ||
123 | .Fn sradixsort | ||
124 | function | ||
125 | may fail and set | ||
126 | .Va errno | ||
127 | for any of the errors specified for the library routine | ||
128 | .Xr malloc 3 . | ||
129 | .Sh SEE ALSO | ||
130 | .Xr sort 1 , | ||
131 | .Xr qsort 3 | ||
132 | .Pp | ||
133 | .Rs | ||
134 | .%A Knuth, D.E. | ||
135 | .%D 1968 | ||
136 | .%B "The Art of Computer Programming" | ||
137 | .%T "Sorting and Searching" | ||
138 | .%V Vol. 3 | ||
139 | .%P pp. 170-178 | ||
140 | .Re | ||
141 | .Rs | ||
142 | .%A Paige, R. | ||
143 | .%D 1987 | ||
144 | .%T "Three Partition Refinement Algorithms" | ||
145 | .%J "SIAM J. Comput." | ||
146 | .%V Vol. 16 | ||
147 | .%N No. 6 | ||
148 | .Re | ||
149 | .Rs | ||
150 | .%A McIlroy, P. | ||
151 | .%D 1993 | ||
152 | .%B "Engineering Radix Sort" | ||
153 | .%T "Computing Systems" | ||
154 | .%V Vol. 6:1 | ||
155 | .%P pp. 5-27 | ||
156 | .Re | ||
157 | .Sh HISTORY | ||
158 | The | ||
159 | .Fn radixsort | ||
160 | function first appeared in | ||
161 | .Bx 4.4 . | ||