1radixsort(3bsd)                      LOCAL                     radixsort(3bsd)
2

NAME

4     radixsort, sradixsort — radix sort
5

LIBRARY

7     Utility functions from BSD systems (libbsd, -lbsd)
8

SYNOPSIS

10     #include <limits.h>
11     #include <stdlib.h>
12     (See libbsd(7) for include usage.)
13
14     int
15     radixsort(const unsigned char **base, int nmemb,
16         const unsigned char *table, unsigned endbyte);
17
18     int
19     sradixsort(const unsigned char **base, int nmemb,
20         const unsigned char *table, unsigned endbyte);
21

DESCRIPTION

23     The radixsort() and sradixsort() functions are implementations of radix
24     sort.
25
26     These functions sort an nmemb element array of pointers to byte strings,
27     with the initial member of which is referenced by base.  The byte strings
28     may contain any values.  End of strings is denoted by character which has
29     same weight as user specified value endbyte.  endbyte has to be between 0
30     and 255.
31
32     Applications may specify a sort order by providing the table argument.
33     If non-NULL, table must reference an array of UCHAR_MAX + 1 bytes which
34     contains the sort weight of each possible byte value.  The end-of-string
35     byte must have a sort weight of 0 or 255 (for sorting in reverse order).
36     More than one byte may have the same sort weight.  The table argument is
37     useful for applications which wish to sort different characters equally,
38     for example, providing a table with the same weights for A-Z as for a-z
39     will result in a case-insensitive sort.  If table is NULL, the contents
40     of the array are sorted in ascending order according to the ASCII order
41     of the byte strings they reference and endbyte has a sorting weight of 0.
42
43     The sradixsort() function is stable, that is, if two elements compare as
44     equal, their order in the sorted array is unchanged.  The sradixsort()
45     function uses additional memory sufficient to hold nmemb pointers.
46
47     The radixsort() function is not stable, but uses no additional memory.
48
49     These functions are variants of most-significant-byte radix sorting; in
50     particular, see D.E. Knuth's Algorithm R and section 5.2.5, exercise 10.
51     They take linear time relative to the number of bytes in the strings.
52

RETURN VALUES

54     The radixsort() function returns the value 0 if successful; otherwise the
55     value -1 is returned and the global variable errno is set to indicate the
56     error.
57

ERRORS

59     [EINVAL]           The value of the endbyte element of table is not 0 or
60                        255.
61
62     Additionally, the sradixsort() function may fail and set errno for any of
63     the errors specified for the library routine malloc(3).
64

SEE ALSO

66     sort(1), qsort(3)
67
68     Knuth, D.E., “Sorting and Searching”, The Art of Computer Programming,
69     Vol. 3, pp. 170-178, 1968.
70
71     Paige, R., “Three Partition Refinement Algorithms”, SIAM J. Comput., No.
72     6, Vol. 16, 1987.
73
74     McIlroy, P., “Computing Systems”, Engineering Radix Sort, Vol. 6:1, pp.
75     5-27, 1993.
76

HISTORY

78     The radixsort() function first appeared in 4.4BSD.
79
80BSD                            January 27, 1994                            BSD
Impressum