1<!--$Id: db_set_h_hash.so,v 10.40 2004/08/13 03:38:56 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::set_h_hash</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::set_h_hash</b> 14</td> 15<td align=right> 16<a href="/api_cxx/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 <db_cxx.h> 23<p> 24extern "C" { 25 typedef u_int32_t (*h_hash_fcn_type) 26 (DB *, const void *bytes, u_int32_t length); 27}; 28int 29Db::set_h_hash(h_hash_fcn_type h_hash_fcn); 30</pre></b> 31<hr size=1 noshade> 32<b>Description: Db::set_h_hash</b> 33<p>Set a user-defined hash function; if no hash function is specified, a 34default hash function is used. Because no hash function performs 35equally well on all possible data, the user may find that the built-in 36hash function performs poorly with a particular data set.</p> 37<p>The Db::set_h_hash method configures operations performed using the specified 38<a href="/api_cxx/db_class.html">Db</a> handle, not all operations performed on the underlying 39database.</p> 40<p>The Db::set_h_hash method may not be called after the <a href="/api_cxx/db_open.html">Db::open</a> method is called. 41If the database already exists when 42<a href="/api_cxx/db_open.html">Db::open</a> is called, the information specified to Db::set_h_hash must 43be the same as that historically used to create the database or 44corruption can occur.</p> 45<p>The Db::set_h_hash method 46either returns a non-zero error value 47or throws an exception that encapsulates a non-zero error value on 48failure, and returns 0 on success. 49</p> 50<b>Parameters</b> <br> 51 <b>h_hash_fcn</b><ul compact><li>The <b>h_hash_fcn</b> parameter is the application-specified hash function. 52<p>Application-specified hash functions take a pointer to a byte string and 53a length as parameters, and return a value of type <b>u_int32_t</b>. 54The hash function must handle any key values used by the application 55(possibly including zero-length keys).</p></ul> 56<br> 57<br><b>Errors</b> 58<p>The Db::set_h_hash method 59may fail and throw 60<a href="/api_cxx/except_class.html">DbException</a>, 61encapsulating one of the following non-zero errors, or return one of 62the following non-zero errors:</p> 63<br> 64<b>EINVAL</b><ul compact><li>If the method was called after <a href="/api_cxx/db_open.html">Db::open</a> was called; the 65specified hash function differs from the hash function with which the 66database was created; or if an 67invalid flag value or parameter was specified.</ul> 68<br> 69<hr size=1 noshade> 70<br><b>Class</b> 71<a href="/api_cxx/db_class.html">Db</a> 72<br><b>See Also</b> 73<a href="/api_cxx/db_list.html">Databases and Related Methods</a> 74</tt> 75<table width="100%"><tr><td><br></td><td align=right> 76<a href="/api_cxx/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a> 77</td></tr></table> 78<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 79</body> 80</html> 81