Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | --- _SB/Libc/stdlib/FreeBSD/qsort.3 2004-11-25 11:38:42.000000000 -0800 +++ _SB/Libc/stdlib/FreeBSD/qsort.3.edit 2006-06-28 16:55:53.000000000 -0700 @@ -40,41 +40,44 @@ .Dt QSORT 3 .Os .Sh NAME -.Nm qsort , qsort_r , heapsort , mergesort +.Nm heapsort , +.Nm mergesort , +.Nm qsort , +.Nm qsort_r .Nd sort functions .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdlib.h +.Ft int +.Fo heapsort +.Fa "void *base" +.Fa "size_t nel" +.Fa "size_t width" +.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" +.Fc +.Ft int +.Fo mergesort +.Fa "void *base" +.Fa "size_t nel" +.Fa "size_t width" +.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" +.Fc .Ft void .Fo qsort .Fa "void *base" -.Fa "size_t nmemb" -.Fa "size_t size" +.Fa "size_t nel" +.Fa "size_t width" .Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" .Fc .Ft void .Fo qsort_r .Fa "void *base" -.Fa "size_t nmemb" -.Fa "size_t size" +.Fa "size_t nel" +.Fa "size_t width" .Fa "void *thunk" .Fa "int \*[lp]*compar\*[rp]\*[lp]void *, const void *, const void *\*[rp]" .Fc -.Ft int -.Fo heapsort -.Fa "void *base" -.Fa "size_t nmemb" -.Fa "size_t size" -.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" -.Fc -.Ft int -.Fo mergesort -.Fa "void *base" -.Fa "size_t nmemb" -.Fa "size_t size" -.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" -.Fc .Sh DESCRIPTION The .Fn qsort @@ -84,7 +87,7 @@ function is a modified selection sort. The .Fn mergesort -function is a modified merge sort with exponential search +function is a modified merge sort with exponential search, intended for sorting data with pre-existing order. .Pp The @@ -92,18 +95,18 @@ and .Fn heapsort functions sort an array of -.Fa nmemb +.Fa nel objects, the initial member of which is pointed to by .Fa base . The size of each object is specified by -.Fa size . +.Fa width . The .Fn mergesort function behaves similarly, but .Em requires that -.Fa size +.Fa width be greater than .Dq "sizeof(void *) / 2" . .Pp @@ -139,7 +142,7 @@ .Fn heapsort are .Em not -stable, that is, if two members compare as equal, their order in +stable; that is, if two members compare as equal, their order in the sorted array is undefined. The .Fn mergesort @@ -183,8 +186,8 @@ The function .Fn mergesort requires additional memory of size -.Fa nmemb * -.Fa size +.Fa nel * +.Fa width bytes; it should be used only when space is not at a premium. The .Fn mergesort @@ -195,8 +198,8 @@ Normally, .Fn qsort is faster than -.Fn mergesort -is faster than +.Fn mergesort , +which is faster than .Fn heapsort . Memory availability and pre-existing order in the data can make this untrue. @@ -218,10 +221,10 @@ .Bl -tag -width Er .It Bq Er EINVAL The -.Fa size +.Fa width argument is zero, or, the -.Fa size +.Fa width argument to .Fn mergesort is less than |