.\" Hey Emacs! This file is -*- nroff -*- source. .\" Copyright 1995 Jim Van Zandt .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" Corrected prototype and include, aeb, 990927 .\" .\" Japanese Version Copyright (c) 1998 Ueyama Rui .\" all rights reserved. .\" Translated 1998-05-23, Ueyama Rui .\" Updated 2005-02-26, Akihiro MOTOKI .\" .\"WORD: linear search 線形検索 .\" .TH LSEARCH 3 1999-09-27 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O lfind, lsearch \- linear search of an array lfind, lsearch \- 配列を線形検索する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "void *lfind(const void *" key ", const void *" base ", size_t *" nmemb , .BI " size_t " size ", int(*" compar ")(const void *, const void *));" .sp .BI "void *lsearch(const void *" key ", void *" base ", size_t *" nmemb , .BI " size_t " size ", int(*" compar ")(const void *, const void *));" .fi .\"O .SH DESCRIPTION .SH 説明 .\"O .BR lfind () .\"O and .\"O .BR lsearch () .\"O perform a linear search for .\"O \fIkey\fP in the array \fIbase\fP which has \fI*nmemb\fP elements of .\"O \fIsize\fP bytes each. .\"O The comparison function referenced by .\"O \fIcompar\fP is expected to have two arguments which point to the .\"O \fIkey\fP object and to an array member, in that order, and which .\"O returns zero if the \fIkey\fP object matches the array member, and .\"O nonzero otherwise. .BR lfind () と .BR lsearch () は、 .I size バイトの要素 .I *nmemb 個からなる配列 .I base から、 .I key を線形検索する。比較を行うのは .I compar が参照している関数で、 これは 2つの引き数を持ち、1つめの引き数が .I key を、2つめの引き数は配列メンバーを指す。また .I compar は、 .I key が配列のメンバーとマッチしたなら 0、そうでなければ 0 以外を返すことが期待されている。 .PP .\"O If .\"O .BR lsearch () .\"O does not find a matching element, then the \fIkey\fP .\"O object is inserted at the end of the table, and \fI*nmemb\fP is .\"O incremented. .BR lsearch () は、マッチする要素を見つけられなかったとき、 配列の最後に .I key をつけ加える。そして .I *nmemb を 1 ふやす。 .\"O In particular, one should know that a matching element .\"O exists, or that more room is available. したがって、この関数を使用する際には、マッチする要素が存在するか、 もしくは配列に要素を追加するための領域があるか、を把握しておく必要がある。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O .BR lfind () .\"O returns a pointer to a matching member of the array, or .\"O NULL if no match is found. .\"O .BR lsearch () .\"O returns a pointer to .\"O a matching member of the array, or to the newly added member if no .\"O match is found. .BR lfind () の返り値は、配列のマッチしたメンバーへのポインタである。 もしマッチするメンバーが見つからないと NULL を返す。 .BR lsearch () の返り値も、配列のマッチしたメンバーへのポインタである。 マッチするメンバーが見つからなかったときは、 新たにつけ加えたメンバーへのポインタを返す。 .\"O .SH "CONFORMING TO" .SH 準拠 SVr4, 4.3BSD, POSIX.1-2001. .\"O Present in libc since libc-4.6.27. libc には libc-4.6.27 以降で実装されている。 .\"O .SH BUGS .SH バグ .\"O The naming is unfortunate. 関数の名前の選び方がよくない。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR bsearch (3), .BR hsearch (3), .BR tsearch (3)