lsearchのヘルプ・マニュアル
日本語 英語
lsearch --help
man lsearch
LSEARCH(3) Linux Programmer’s Manual LSEARCH(3)
名前
lfind, lsearch - 配列を線形検索する
書式
#include
void *lfind(const void *key, const void *base, size_t *nmemb,
size_t size, int(*compar)(const void *, const void *));
void *lsearch(const void *key, void *base, size_t *nmemb,
size_t size, int(*compar)(const void *, const void *));
説明
lfind() と lsearch() は、 size バイトの要素 *nmemb 個からなる配列 base
から、 key を線形検索する。比較を行うのは compar が参照している関数で、
これは 2つの引き数を持ち、1つめの引き数が key を、2つめの引き数は配列メ
ンバーを指す。また compar は、 key が配列のメンバーとマッチしたなら 0、
そうでなければ 0 以外を返すことが期待されている。
lsearch() は、マッチする要素を見つけられなかったとき、配列の最後に key
をつけ加える。そして *nmemb を 1 ふやす。したがって、この関数を使用する
際 には、マッチする要素が存在するか、もしくは配列に要素を追加するための
領域があるか、を把握しておく必要がある。
返り値
lfind() の返り値は、配列のマッチしたメンバーへのポインタである。もし マ
ッチするメンバーが見つからないと NULL を返す。 lsearch() の返り値も、配
列のマッチしたメンバーへのポインタである。マッチするメンバーが見つか ら
なかったときは、新たにつけ加えたメンバーへのポインタを返す。
準拠
SVr4, 4.3BSD, POSIX.1-2001. libc には libc-4.6.27 以降で実装されている
。
バグ
関数の名前の選び方がよくない。
関連項目
bsearch(3), hsearch(3), tsearch(3)
GNU 1999-09-27 LSEARCH(3)
LSEARCH(3) Linux Programmer’s Manual LSEARCH(3)
NAME
lfind, lsearch - linear search of an array
SYNOPSIS
#include
void *lfind(const void *key, const void *base, size_t *nmemb,
size_t size, int(*compar)(const void *, const void *));
void *lsearch(const void *key, void *base, size_t *nmemb,
size_t size, int(*compar)(const void *, const void *));
DESCRIPTION
lfind() and lsearch() perform a linear search for key in the array base
which has *nmemb elements of size bytes each. The comparison function
referenced by compar is expected to have two arguments which point to
the key object and to an array member, in that order, and which returns
zero if the key object matches the array member, and non-zero other-
wise.
If lsearch() does not find a matching element, then the key object is
inserted at the end of the table, and *nmemb is incremented. In par-
ticular, one should know that a matching element exists, or that more
room is available.
RETURN VALUE
lfind() returns a pointer to a matching member of the array, or NULL if
no match is found. lsearch() returns a pointer to a matching member of
the array, or to the newly added member if no match is found.
CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001. Present in libc since libc-4.6.27.
BUGS
The naming is unfortunate.
SEE ALSO
bsearch(3), hsearch(3), tsearch(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 1999-09-27 LSEARCH(3)