sradixsort()

perform stable radix sort 

Function


SYNOPSIS

#include <limits.h>

#include <stdlib.h>

int sradixsort(unsigned char **base, int nmemb, unsigned char *table, unsigned int endbyte);


DESCRIPTION

The sradixsort() function is an implementation of radix sort. This function sorts an array of pointers to byte strings, the initial member of which is referenced by base. The byte strings may contain any values; the end of each string is denoted by the user-specified value endbyte.

Applications may specify a sort order by providing the table argument. If non-null, table must reference an array of UCHAR_MAX + 1 bytes which contain the sort weight of each possible byte value. The end-of-string byte must have a sort weight of 0 or 255 (for sorting in reverse order). More than one byte may have the same sort weight. The table argument is useful for applications which wish to sort different characters equally, for example, providing a table with the same weights for A-Z as for a-z results in a case-insensitive sort. If table is NULL, the contents of the array are sorted in ascending order according to the ASCII order of the byte strings they reference, and endbyte has a sorting weight of 0.

The sradixsort() function is stable, but requires additional memory sufficient to hold nmemb pointers. The implementation is a variant of most-significant-byte radix sorting. The algorithm is taken from Algorithm R and Section 5.2.5, Exercise 10 of D.E. Knuth's Sorting and Searching. It takes linear time relative to the number of bytes in the strings.


PARAMETERS

base 

Is the table of byte strings to be sorted.

nmemb 

Is the number of strings in the table.

table 

Is the table of weights for each possibly byte value, or NULL to use a default table.

endbyte 

Is the termination byte for each string in the table.


RETURN VALUES

On success, sradixsort() returns 0. On failure, it returns -1 and sets errno to one of the following values:

EINVAL 

The value of the endbyte element of table is not 0 or 255.

ENOMEM 

Insufficient memory is available to create the table needed to implement the stable sort algorithm.


CONFORMANCE

4.4BSD.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
heapsort(), mergesort(), qsort(), radixsort()


PTC MKS Toolkit 10.4 Documentation Build 39.