gecko-dev/db/man/man.html/db_hsearch.html

142 строки
5.7 KiB
HTML

<HTML>
<HEAD>
<TITLE>db_hsearch</TITLE>
</HEAD>
<BODY BGCOLOR=white>
<H1>db_hsearch</H1>
<HR SIZE=1 NOSHADE>
<PRE>
<!-- Manpage converted by man2html 3.0.1 -->
<B>#define</B> <B>DB</B>_<B>DBM</B>_<B>HSEARCH</B> <B>1</B>
<B>#include</B> <B>&lt;db.h&gt;</B>
<B>typedef</B> <B>enum</B> <B>{</B>
<B>FIND,</B> <B>ENTER</B>
<B>}</B> <B>ACTION;</B>
<B>typedef</B> <B>struct</B> <B>entry</B> <B>{</B>
<B>char</B> <B>*key;</B>
<B>void</B> <B>*data;</B>
<B>}</B> <B>ENTRY;</B>
<B>ENTRY</B> <B>*</B>
<B>hsearch(ENTRY</B> <B>item,</B> <B>ACTION</B> <B>action);</B>
<B>int</B>
<B>hcreate(size</B>_<B>t</B> <B>nelem);</B>
<B>void</B>
<B>hdestroy(void);</B>
</PRE>
<H2>DESCRIPTION</H2><PRE>
The hsearch interface to the DB library is intended to
provide source code compatibility for historic
applications. It is not recommended for any other
purpose.
To compile hsearch applications, replace the application's
#include of the hsearch include file (e.g., ``#include
&lt;search.h&gt;'') with the following two lines:
#define DB_DBM_HSEARCH 1
#include &lt;db.h&gt;
and recompile.
The hcreate function creates an in-memory database. The
nelem argument is an estimation of the maximum number of
key/data pairs that will be stored in the database.
The hdestroy function discards the database.
Database elements are structures of type ENTRY, which
contain at least two fields: key and data. The field key
is declared to be of type ``char *'' and is the key used
for storage and retrieval. The field data is declared to
be of type ``void *'' and is its associated data.
The hsearch function retrieves key/data pairs from, and
stores key/data pairs into, the database.
The action argument must be set to one of two values:
ENTER
If the key does not already appear in the database,
insert the key/data pair into the database. If the
key already appears in the database, return a
reference to an ENTRY structure referencing the
existing key and its associated data element.
FIND Retrieve the specified key/data pair from the
database.
</PRE>
<H2>COMPATIBILITY NOTES</H2><PRE>
Historically, hsearch required applications to maintain
the keys and data in the application's memory for as long
as the hsearch database existed. As DB handles key and
data management internally, there is no requirement that
applications maintain local copies of key and data items,
although the only effect of doing so should be the
allocation of additional memory.
</PRE>
<H2>DIAGNOSTICS</H2><PRE>
The hcreate function returns 0 on failure, setting errno,
and non-zero on success.
The hsearch function returns a pointer to an ENTRY
structure on success, and NULL, setting errno, if the
action specified was FIND and the item did not appear in
the database.
</PRE>
<H2>ERRORS</H2><PRE>
The hcreate function may fail and return errno for any of
the errors specified for the following DB and library
functions: <B><A HREF="db_open.html">db_open(3)</A></B>, and <B>memset(3)</B>.
The hsearch function may fail and return errno for any of
the errors specified for the following DB and library
functions: <B><A HREF="db_open.html">DB-&gt;get(3)</A></B>, <B><A HREF="db_open.html">DB-&gt;put(3)</A></B>, <B>memset(3)</B>, and
<B>strlen(3)</B>.
In addition, the hsearch function will fail, setting errno
to 0, if the action specified was FIND and the item did
not appear in the database.
</PRE>
<H2>SEE ALSO</H2><PRE>
The DB library is a family of groups of functions that
provides a modular programming interface to transactions
and record-oriented file access. The library includes
support for transactions, locking, logging and file page
caching, as well as various indexed access methods. Many
of the functional groups (e.g., the file page caching
functions) are useful independent of the other DB
functions, although some functional groups are explicitly
based on other functional groups (e.g., transactions and
logging). For a general description of the DB package,
see <B><A HREF="db_intro.html">db_intro(3)</A></B>.
<B><A HREF="db_archive.html">db_archive(1)</A></B>, <B><A HREF="db_checkpoint.html">db_checkpoint(1)</A></B>, <B><A HREF="db_deadlock.html">db_deadlock(1)</A></B>, <B><A HREF="db_dump.html">db_dump(1)</A></B>,
<B><A HREF="db_load.html">db_load(1)</A></B>, <B><A HREF="db_recover.html">db_recover(1)</A></B>, <B><A HREF="db_stat.html">db_stat(1)</A></B>, <B><A HREF="db_intro.html">db_intro(3)</A></B>,
<B><A HREF="db_appinit.html">db_appinit(3)</A></B>, <B><A HREF="db_cursor.html">db_cursor(3)</A></B>, <B><A HREF="db_dbm.html">db_dbm(3)</A></B>, <B><A HREF="db_internal.html">db_internal(3)</A></B>,
<B><A HREF="db_lock.html">db_lock(3)</A></B>, <B><A HREF="db_log.html">db_log(3)</A></B>, <B><A HREF="db_mpool.html">db_mpool(3)</A></B>, <B><A HREF="db_open.html">db_open(3)</A></B>, <B><A HREF="db_thread.html">db_thread(3)</A></B>,
<B><A HREF="db_txn.html">db_txn(3)</A></B>
</PRE>
<HR SIZE=1 NOSHADE>
<ADDRESS>
Man(1) output converted with
<a href="http://www.oac.uci.edu/indiv/ehood/man2html.html">man2html</a>
</ADDRESS>
</BODY>
</HTML>