1<!--$Id: db_set_h_compare.so,v 1.1 2006/10/27 00:28:44 bostic Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB: DB-&gt;set_h_compare</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<table width="100%"><tr valign=top>
12<td>
13<b>DB-&gt;set_h_compare</b>
14</td>
15<td align=right>
16<a href="/api_c/api_core.html"><img src="/images/api.gif" alt="API"></a>
17<a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a></td>
18</tr></table>
19<hr size=1 noshade>
20<tt>
21<b><pre>
22#include &lt;db.h&gt;
23<p>
24int
25DB-&gt;set_h_compare(DB *db,
26    int (*compare_fcn)(DB *db, const DBT *dbt1, const DBT *dbt2));
27</pre></b>
28<hr size=1 noshade>
29<b>Description: DB-&gt;set_h_compare</b>
30<p>Set the Hash key comparison function.  The comparison function is called
31whenever it is necessary to compare a key specified by the application
32with a key currently stored in the database.</p>
33<p>If no comparison function is specified, a byte-by-byte comparison is
34performed.</p>
35<p>The DB-&gt;set_h_compare method configures operations performed using the specified
36<a href="/api_c/db_class.html">DB</a> handle, not all operations performed on the underlying
37database.</p>
38<p>The DB-&gt;set_h_compare method may not be called after the <a href="/api_c/db_open.html">DB-&gt;open</a> method is called.
39If the database already exists when
40<a href="/api_c/db_open.html">DB-&gt;open</a> is called, the information specified to DB-&gt;set_h_compare must
41be the same as that historically used to create the database or
42corruption can occur.</p>
43<p>The DB-&gt;set_h_compare method
44returns a non-zero error value on failure
45and 0 on success.
46</p>
47<b>Parameters</b> <br>
48 <b>compare_fcn</b><ul compact><li>The <b>compare_fcn</b> function is the application-specified Hash
49comparison function.  The comparison function takes three parameters:
50<br>
51<b><b>db</b></b><ul compact><li>The <b>db</b> parameter is the enclosing database handle.</ul>
52<b><b>dbt1</b></b><ul compact><li>The <b>dbt1</b> parameter is the <a href="/api_c/dbt_class.html">DBT</a> representing the
53application supplied key.</ul>
54<b><b>dbt2</b></b><ul compact><li>The <b>dbt2</b> parameter is the <a href="/api_c/dbt_class.html">DBT</a> representing the
55current database's key.</ul>
56<br></ul>
57<p>The <b>compare_fcn</b> function must return an integer value less
58than, equal to, or greater than zero if the first key parameter is
59considered to be respectively less than, equal to, or greater than the
60second key parameter.  The comparison function must correctly handle any
61key values used by the application (possibly including zero-length
62keys).  The <b>data</b> and <b>size</b> fields of the <a href="/api_c/dbt_class.html">DBT</a> are
63the only fields that may be used for the purposes of this comparison,
64and no particular alignment of the memory to which by the <b>data</b>
65field refers may be assumed.</p>
66<br>
67<br><b>Errors</b>
68<p>The DB-&gt;set_h_compare method
69may fail and return one of the following non-zero errors:</p>
70<br>
71<b>EINVAL</b><ul compact><li>If the method was called after <a href="/api_c/db_open.html">DB-&gt;open</a> was called; or if an
72invalid flag value or parameter was specified.</ul>
73<br>
74<hr size=1 noshade>
75<br><b>Class</b>
76<a href="/api_c/db_class.html">DB</a>
77<br><b>See Also</b>
78<a href="/api_c/db_list.html">Databases and Related Methods</a>
79</tt>
80<table width="100%"><tr><td><br></td><td align=right>
81<a href="/api_c/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a>
82</td></tr></table>
83<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
84</body>
85</html>
86