1 --- psort.3.orig 2009-05-20 15:59:00.000000000 -0700
2 +++ psort.3 2009-05-20 16:08:34.000000000 -0700
4 .\" @(#)qsort.3 8.1 (Berkeley) 6/4/93
5 .\" $FreeBSD: src/lib/libc/stdlib/qsort.3,v 1.15 2004/07/02 23:52:12 ru 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.
231 #ifdef UNIFDEF_BLOCKS
245 -#ifdef UNIFDEF_BLOCKS
246 -.ds HEAPSORT_B heapsort_b
247 -.ds MERGESORT_B mergesort_b
249 -.Rv -std heapsort \*[HEAPSORT_B] mergesort \*[MERGESORT_B]
252 +functions are parallel sort routines that are drop-in compatible with the
257 +for a description of the arguments).
258 +On multiprocessor machines, multiple threads may be created to simultaneously
259 +perform the sort calculations, resulting in an overall faster sort result.
260 +Overhead in managing the threads limits the maximum speed improvement to
261 +somewhat less that the number of processors available.
262 +For example, on a 4-processor machine, a typical sort on a large array might
263 +result in 3.2 times faster sorting than a regular
266 +Because of the multi-threaded nature of the sort, the comparison function
267 +is expected to perform its own synchronization that might be required for
270 +the two objects passed to the comparison function.
271 +However, no synchronization is required for the two
272 +object themselves, unless some third party is also accessing those objects.
274 +Additional memory is temporary allocated to deal with the parallel nature
277 +Because of the overhead of maintaining multiple threads, the
279 +family of routines may choose to just call
281 +when there is no advantage to parallelizing (for example, when the number of
282 +objects in the array is too small, or only one processor is available).
286 +the sort is not stable.
289 #ifdef UNIFDEF_BLOCKS
302 -functions succeed unless:
307 -argument is zero, or,
312 -#ifdef UNIFDEF_BLOCKS
318 -.Dq "sizeof(void *) / 2" .
321 -#ifdef UNIFDEF_BLOCKS
334 -were unable to allocate memory.
337 -Previous versions of
339 -did not permit the comparison routine itself to call
341 -This is no longer true.
350 -.%J "The Computer Journal"
358 -.%J "Communications of the ACM"
365 -.%B "The Art of Computer Programming"
367 -.%T "Sorting and Searching"
368 -.%P pp. 114-123, 145-149
372 -.%T "Optimistic Sorting and Information Theoretic Complexity"
373 -.%J "Fourth Annual ACM-SIAM Symposium on Discrete Algorithms"
379 -.%T "Engineering a Sort Function"
380 -.%J "Software--Practice and Experience"