1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>DB->set_h_hash()</title> 7 <link rel="stylesheet" href="apiReference.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB C API Reference" /> 10 <link rel="up" href="db.html" title="Chapter��2.�� The DB Handle" /> 11 <link rel="prev" href="dbset_h_ffactor.html" title="DB->set_h_ffactor()" /> 12 <link rel="next" href="dbset_h_nelem.html" title="DB->set_h_nelem()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DB->set_h_hash()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbset_h_ffactor.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.�� 23 The DB Handle 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="dbset_h_nelem.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="dbset_h_hash"></a>DB->set_h_hash()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db.h> 39 40int 41DB->set_h_hash(DB *db, 42 u_int32_t (*h_hash_fcn)(DB *dbp, const void *bytes, 43 u_int32_t length)); </pre> 44 <p> 45 Set a user-defined hash function; if no hash function is specified, a 46 default hash function is used. Because no hash function performs 47 equally well on all possible data, the user may find that the built-in 48 hash function performs poorly with a particular data set. 49 </p> 50 <p> 51 The <code class="methodname">DB->set_h_hash()</code> method configures operations performed using the 52 specified <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> handle, not 53 all operations performed on the underlying database. 54 </p> 55 <p> 56 The <code class="methodname">DB->set_h_hash()</code> method may not be called after the 57 <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> method is called. If 58 the database already exists when <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> 59 is called, the information specified to <code class="methodname">DB->set_h_hash()</code> must be the same as that 60 historically used to create the database or corruption can occur. 61 </p> 62 <p> 63 The <code class="methodname">DB->set_h_hash()</code> <span> 64 <span> 65 method returns a non-zero error value on failure and 0 on success. 66 </span> 67 68 </span> 69 </p> 70 <div class="sect2" lang="en" xml:lang="en"> 71 <div class="titlepage"> 72 <div> 73 <div> 74 <h3 class="title"><a id="id1647806"></a>Parameters</h3> 75 </div> 76 </div> 77 </div> 78 <div class="sect3" lang="en" xml:lang="en"> 79 <div class="titlepage"> 80 <div> 81 <div> 82 <h4 class="title"><a id="id1647748"></a>h_hash_fcn</h4> 83 </div> 84 </div> 85 </div> 86 <p> 87 The <span class="bold"><strong>h_hash_fcn</strong></span> parameter is the 88 application-specified hash function. 89 </p> 90 <p> 91 Application-specified hash functions take a pointer to a byte string 92 and a length as parameters, and return a value of type <span class="bold"><strong>u_int32_t</strong></span>. The hash function must handle any 93 key values used by the application (possibly including zero-length 94 keys). 95 </p> 96 </div> 97 </div> 98 <div class="sect2" lang="en" xml:lang="en"> 99 <div class="titlepage"> 100 <div> 101 <div> 102 <h3 class="title"><a id="id1648010"></a>Errors</h3> 103 </div> 104 </div> 105 </div> 106 <p> 107 The <code class="methodname">DB->set_h_hash()</code> <span> 108 <span> 109 method may fail and return one of the following non-zero errors: 110 </span> 111 112 </span> 113 </p> 114 <div class="sect3" lang="en" xml:lang="en"> 115 <div class="titlepage"> 116 <div> 117 <div> 118 <h4 class="title"><a id="id1647923"></a>EINVAL</h4> 119 </div> 120 </div> 121 </div> 122 <p> 123 If the method was called after <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> 124 was called; or if an invalid flag value or parameter was specified. 125 </p> 126 </div> 127 </div> 128 <div class="sect2" lang="en" xml:lang="en"> 129 <div class="titlepage"> 130 <div> 131 <div> 132 <h3 class="title"><a id="id1648002"></a>Class</h3> 133 </div> 134 </div> 135 </div> 136 <p> 137 <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> 138 </p> 139 </div> 140 <div class="sect2" lang="en" xml:lang="en"> 141 <div class="titlepage"> 142 <div> 143 <div> 144 <h3 class="title"><a id="id1647889"></a>See Also</h3> 145 </div> 146 </div> 147 </div> 148 <p> 149 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 150 </p> 151 </div> 152 </div> 153 <div class="navfooter"> 154 <hr /> 155 <table width="100%" summary="Navigation footer"> 156 <tr> 157 <td width="40%" align="left"><a accesskey="p" href="dbset_h_ffactor.html">Prev</a>��</td> 158 <td width="20%" align="center"> 159 <a accesskey="u" href="db.html">Up</a> 160 </td> 161 <td width="40%" align="right">��<a accesskey="n" href="dbset_h_nelem.html">Next</a></td> 162 </tr> 163 <tr> 164 <td width="40%" align="left" valign="top">DB->set_h_ffactor()��</td> 165 <td width="20%" align="center"> 166 <a accesskey="h" href="index.html">Home</a> 167 </td> 168 <td width="40%" align="right" valign="top">��DB->set_h_nelem()</td> 169 </tr> 170 </table> 171 </div> 172 </body> 173</html> 174