Solutions of common problems
This C module implements a function that sorts the elements of an array in
place.
It uses the O(n log n) Heapsort algorithm.
The module is instantiated by
$/Tech/Sort.gnrc +instance=TYPE +referto=HDR :inst
where TYPE is the name of the array element type and HDR.h
is a file that defines the array element type, e.g.
$/Adt/Sort.gnrc+instance=DefTableKey +referto=deftbl :inst
If the element type is predefined in C the referto parameter
is omitted, e.g.
$/Adt/Sort.gnrc+instance=int :inst
All entities exported by this module can be used in specifications
of type .lido , .init , .finl , and .con .
They can also be used in .pdl specifications or in C modules
if the interface file SortTYPE.h is imported there.
The module exports the following function:
void SortTYPE (TYPE *arr, size_t n, TYPECmpFctType cmp)
arr points to the array to be sorted, which contains n
elements.
cmp is the function that defines the collating sequence for the
elements.
It's signature is TYPE, TYPE -> int ; it yields
-1 if the left argument should precede the right in the sorted array,
+1 if the left argument should follow the right in the sorted array,
and 0 if the order of the elements in the sorted array is immaterial.
|