1 --- psort.3.orig 2010-10-07 21:34:52.000000000 -0700
2 +++ psort.3 2010-10-07 21:45:11.000000000 -0700
4 .\" @(#)qsort.3 8.1 (Berkeley) 6/4/93
5 .\" $FreeBSD: src/lib/libc/stdlib/qsort.3,v 1.17 2007/01/09 00:28:10 imp Exp $
7 -.Dd September 30, 2003
21 -#ifdef UNIFDEF_BLOCKS
25 -#ifdef UNIFDEF_BLOCKS
31 +.Nd parallel sort functions
39 -.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
41 -#ifdef UNIFDEF_BLOCKS
47 -.Fa "int \*[lp]^compar\*[rp]\*[lp]const void *, const void *\*[rp]"
55 -.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
57 -#ifdef UNIFDEF_BLOCKS
63 -.Fa "int \*[lp]^compar\*[rp]\*[lp]const void *, const void *\*[rp]"
95 -function is a modified partition-exchange sort, or quicksort.
98 -function is a modified selection sort.
101 -function is a modified merge sort with exponential search,
102 -intended for sorting data with pre-existing order.
108 -functions sort an array of
110 -objects, the initial member of which is pointed to by
112 -The size of each object is specified by
117 -behaves similarly, but
121 -be greater than or equal to
122 -.Dq "sizeof(void *) / 2" .
124 -The contents of the array
126 -are sorted in ascending order according to
127 -a comparison function pointed to by
129 -which requires two arguments pointing to the objects being
132 -The comparison function must return an integer less than, equal to, or
133 -greater than zero if the first argument is considered to be respectively
134 -less than, equal to, or greater than the second.
138 -function behaves identically to
140 -except that it takes an additional argument,
142 -which is passed unchanged as the first argument to function pointed to
144 -This allows the comparison function to access additional
145 -data without using global variables, and thus
147 -is suitable for use in functions which must be reentrant.
149 -The algorithms implemented by
156 -stable; that is, if two members compare as equal, their order in
157 -the sorted array is undefined.
160 -algorithm is stable.
166 -functions are an implementation of C.A.R.
170 -a variant of partition-exchange sorting; in particular, see
171 -.An D.E. Knuth Ns 's
174 -takes O N lg N average time.
175 -This implementation uses median selection to avoid its
176 -O N**2 worst-case behavior.
180 -function is an implementation of
181 -.An "J.W.J. William" Ns 's
184 -a variant of selection sorting; in particular, see
185 -.An "D.E. Knuth" Ns 's
188 -takes O N lg N worst-case time.
193 -is that it uses almost no additional memory; while
195 -does not allocate memory, it is implemented using recursion.
199 -requires additional memory of size
202 -bytes; it should be used only when space is not at a premium.
206 -is optimized for data with pre-existing order; its worst case
207 -time is O N lg N; its best case is O N.
213 -which is faster than
215 -Memory availability and pre-existing order in the data can make this
217 #ifdef UNIFDEF_BLOCKS
224 -routines are like the corresponding routines without the _b suffix, expect
227 -callback is a block pointer instead of a function pointer.
235 +functions are parallel sort routines that are drop-in compatible with the
240 +for a description of the arguments).
241 +On multiprocessor machines, multiple threads may be created to simultaneously
242 +perform the sort calculations, resulting in an overall faster sort result.
243 +Overhead in managing the threads limits the maximum speed improvement to
244 +somewhat less that the number of processors available.
245 +For example, on a 4-processor machine, a typical sort on a large array might
246 +result in 3.2 times faster sorting than a regular
249 +Because of the multi-threaded nature of the sort, the comparison function
250 +is expected to perform its own synchronization that might be required for
253 +the two objects passed to the comparison function.
254 +However, no synchronization is required for the two
255 +object themselves, unless some third party is also accessing those objects.
257 +Additional memory is temporary allocated to deal with the parallel nature
260 +Because of the overhead of maintaining multiple threads, the
262 +family of routines may choose to just call
264 +when there is no advantage to parallelizing (for example, when the number of
265 +objects in the array is too small, or only one processor is available).
269 +the sort is not stable.
272 #ifdef UNIFDEF_BLOCKS
287 -#ifdef UNIFDEF_BLOCKS
288 -.ds HEAPSORT_B heapsort_b
289 -.ds MERGESORT_B mergesort_b
291 -.Rv -std heapsort \*[HEAPSORT_B] mergesort \*[MERGESORT_B]
293 -Previous versions of
295 -did not permit the comparison routine itself to call
297 -This is no longer true.
300 -#ifdef UNIFDEF_BLOCKS
311 -functions succeed unless:
316 -argument is zero, or,
321 -#ifdef UNIFDEF_BLOCKS
326 -.Dq "sizeof(void *) / 2" .
329 -#ifdef UNIFDEF_BLOCKS
341 -were unable to allocate memory.