.\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)radixsort.3 8.2 (Berkeley) 1/27/94 .\" .Dd January 27, 1994 .Dt RADIXSORT 3 .Os .Sh 名称 .Nm radixsort .Nd 基数ソート .Sh 書式 .Fd #include .Fd #include .Ft int .Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" .Ft int .Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" .Sh 解説 .Fn radixsort 関数と .Fn sradixsort 関数は、基数ソートのシステムです。 .Pp この関数は、 .Fa base が参照する初期メンバである、バイトストリングのポインタの配列をソートし ます。バイトストリングには任意の値を含められます。各ストリングの最後に は、ユーザが定義した値 .Fa endbyte が付きます。 .Pp アプリケーションでは、 .Fa table 引数を指定することでソート順序を指定できます。 .Dv NULL ではない .Fa table は、各バイト値のソートウェイトを含む、 .Dv UCHAR_MAX + 1 バイトの配列を参照する必要があります。最終ストリングバイトのソート ウェイトは、0か 255(逆順ソート)でなければなりません。複数のバイトのソー トウェイトが等しいこともあります。 .Fa table 引数は、異なるキャラクタを等しくソートするアプリケーションで便利です。 たとえば A から Z のウェイトと a から z のウェイトを等しくすると、大文 字と小文字の区別をしないソートができます。 .Fa table が NULL である場合、配列の内容は、参照するバイトストリングの .Tn ASCII 順序に従って昇順にソートされます。 .Fa endbyte のソートウェイトは 0です。 .Pp .Fn sradixsort 関数は安定しています。つまり、2つのエレメントが等しい場合、このエレメ ントの順序はソート済み配列で変化しません。 .Fn sradixsort 関数は、 .Fa nmemb ポインタを収容するに十分なメモリを余分に使用します。 .Pp .Fn radixsort 関数は不安定ですが、メモリを余分に使用しません。 .Pp この関数は、最上位バイト基数ソートのバリエーションです。D.E. Knuth の アルゴリズム R とセクション 5.2.5、エクササイズ 10を参照してください。 この関数には、ストリングのバイト数に比例した時間がかかります。 .Sh 戻り値 問題がない場合は 0が戻されます。問題がある場合は \-1が戻され、グローバ ル変数 .Va errno が、そのエラーを示す値に設定されます。 .Sh エラー .Bl -tag -width Er .It Bq Er EINVAL .Fa table の .Fa endbyte エレメントの値が 0か 255になっていません。 .El .Pp .Fn sradixsort 関数は、エラーが発生すると、ライブラリルーチン .Xr malloc 3 のエラーに .Va errno を設定することがあります。 .Sh 関連項目 .Xr sort 1 , .Xr qsort 3 .Pp .Rs .%A Knuth, D.E. .%D 1968 .%B "The Art of Computer Programming" .%T "Sorting and Searching" .%V Vol. 3 .%P pp. 170-178 .Re .Rs .%A Paige, R. .%D 1987 .%T "Three Partition Refinement Algorithms" .%J "SIAM J. Comput." .%V Vol. 16 .%N No. 6 .Re .Rs .%A McIlroy, P. .%D 1993 .%B "Engineering Radix Sort" .%T "Computing Systems" .%V Vol. 6:1 .%P pp. 5-27 .Re .Sh 歴史 .Fn radixsort 関数は、 .Bx 4.4 に初めて登場しました。