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_cxx.h> 39 40extern "C" { 41 typedef u_int32_t (*h_hash_fcn_type) 42 (DB *, const void *bytes, u_int32_t length); 43}; 44int 45Db::set_h_hash(h_hash_fcn_type h_hash_fcn);</pre> 46 <p> 47 Set a user-defined hash function; if no hash function is specified, a 48 default hash function is used. Because no hash function performs 49 equally well on all possible data, the user may find that the built-in 50 hash function performs poorly with a particular data set. 51 </p> 52 <p> 53 The <code class="methodname">Db::set_h_hash()</code> method configures operations performed using the 54 specified <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> handle, not 55 all operations performed on the underlying database. 56 </p> 57 <p> 58 The <code class="methodname">Db::set_h_hash()</code> method may not be called after the 59 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> method is called. If 60 the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> 61 is called, the information specified to <code class="methodname">Db::set_h_hash()</code> must be the same as that 62 historically used to create the database or corruption can occur. 63 </p> 64 <p> 65 The <code class="methodname">Db::set_h_hash()</code> <span> 66 67 <span> 68 method either returns a non-zero error value or throws an 69 exception that encapsulates a non-zero error value on 70 failure, and returns 0 on success. 71 </span> 72 </span> 73 </p> 74 <div class="sect2" lang="en" xml:lang="en"> 75 <div class="titlepage"> 76 <div> 77 <div> 78 <h3 class="title"><a id="id1648557"></a>Parameters</h3> 79 </div> 80 </div> 81 </div> 82 <div class="sect3" lang="en" xml:lang="en"> 83 <div class="titlepage"> 84 <div> 85 <div> 86 <h4 class="title"><a id="id1648531"></a>h_hash_fcn</h4> 87 </div> 88 </div> 89 </div> 90 <p> 91 The <span class="bold"><strong>h_hash_fcn</strong></span> parameter is the 92 application-specified hash function. 93 </p> 94 <p> 95 Application-specified hash functions take a pointer to a byte string 96 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 97 key values used by the application (possibly including zero-length 98 keys). 99 </p> 100 </div> 101 </div> 102 <div class="sect2" lang="en" xml:lang="en"> 103 <div class="titlepage"> 104 <div> 105 <div> 106 <h3 class="title"><a id="id1648726"></a>Errors</h3> 107 </div> 108 </div> 109 </div> 110 <p> 111 The <code class="methodname">Db::set_h_hash()</code> <span> 112 113 <span> 114 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 115 exception, encapsulating one of the following non-zero errors, or return one 116 of the following non-zero errors: 117 </span> 118 </span> 119 </p> 120 <div class="sect3" lang="en" xml:lang="en"> 121 <div class="titlepage"> 122 <div> 123 <div> 124 <h4 class="title"><a id="id1648326"></a>EINVAL</h4> 125 </div> 126 </div> 127 </div> 128 <p> 129 If the method was called after <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> 130 was called; or if an invalid flag value or parameter was specified. 131 </p> 132 </div> 133 </div> 134 <div class="sect2" lang="en" xml:lang="en"> 135 <div class="titlepage"> 136 <div> 137 <div> 138 <h3 class="title"><a id="id1646841"></a>Class</h3> 139 </div> 140 </div> 141 </div> 142 <p> 143 <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> 144 </p> 145 </div> 146 <div class="sect2" lang="en" xml:lang="en"> 147 <div class="titlepage"> 148 <div> 149 <div> 150 <h3 class="title"><a id="id1648501"></a>See Also</h3> 151 </div> 152 </div> 153 </div> 154 <p> 155 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 156 </p> 157 </div> 158 </div> 159 <div class="navfooter"> 160 <hr /> 161 <table width="100%" summary="Navigation footer"> 162 <tr> 163 <td width="40%" align="left"><a accesskey="p" href="dbset_h_ffactor.html">Prev</a> </td> 164 <td width="20%" align="center"> 165 <a accesskey="u" href="db.html">Up</a> 166 </td> 167 <td width="40%" align="right"> <a accesskey="n" href="dbset_h_nelem.html">Next</a></td> 168 </tr> 169 <tr> 170 <td width="40%" align="left" valign="top">Db::set_h_ffactor() </td> 171 <td width="20%" align="center"> 172 <a accesskey="h" href="index.html">Home</a> 173 </td> 174 <td width="40%" align="right" valign="top"> Db::set_h_nelem()</td> 175 </tr> 176 </table> 177 </div> 178 </body> 179</html> 180