1<!--$Id: h_hash.so,v 10.12 2000/07/04 18:28:27 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 Reference Guide: Specifying a database 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<a name="2"><!--meow--></a> 12<table width="100%"><tr valign=top> 13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Access Methods</dl></b></td> 14<td align=right><a href="/am_conf/h_ffactor.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/am_conf/h_nelem.html"><img src="/images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Specifying a database hash</b></p> 17<p>The database hash determines in which bucket a particular key will reside. 18The goal of hashing keys is to distribute keys equally across the database 19pages, therefore it is important that the hash function work well with 20the specified keys so that the resulting bucket usage is relatively 21uniform. A hash function that does not work well can effectively turn 22into a sequential list.</p> 23<p>No hash performs equally well on all possible data sets. It is possible 24that applications may find that the default hash function performs poorly 25with a particular set of keys. The distribution resulting from the hash 26function can be checked using <a href="/utility/db_stat.html">db_stat</a> utility. By comparing the 27number of hash buckets and the number of keys, one can decide if the entries 28are hashing in a well-distributed manner.</p> 29<p>The hash function for the hash table can be specified by calling the 30<a href="/api_c/db_set_h_hash.html">DB->set_h_hash</a> method. If no hash function is specified, a default 31function will be used. Any application-specified hash function must 32take a reference to a <a href="/api_c/db_class.html">DB</a> object, a pointer to a byte string and 33its length, as arguments and return an unsigned, 32-bit hash value.</p> 34<table width="100%"><tr><td><br></td><td align=right><a href="/am_conf/h_ffactor.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/am_conf/h_nelem.html"><img src="/images/next.gif" alt="Next"></a> 35</td></tr></table> 36<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 37</body> 38</html> 39