1.\" $NetBSD: hash.3,v 1.9 2003/04/17 19:18:01 wiz Exp $ 2.\" 3.\" Copyright (c) 1990, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)hash.3 8.6 (Berkeley) 8/18/94 35.\" 36.Dd April 17, 2003 37.Dt HASH 3 38.Os 39.Sh NAME 40.Nm hash 41.Nd hash database access method 42.Sh SYNOPSIS 43.In sys/types.h 44.In db.h 45.Sh DESCRIPTION 46The routine 47.Fn dbopen 48is the library interface to database files. 49One of the supported file formats is hash files. 50The general description of the database access methods is in 51.Xr dbopen 3 , 52this manual page describes only the hash specific information. 53.Pp 54The hash data structure is an extensible, dynamic hashing scheme. 55.Pp 56The access method specific data structure provided to 57.Fn dbopen 58is defined in the 59.Aq Pa db.h 60include file as follows: 61.Bd -literal 62typedef struct { 63 u_int bsize; 64 u_int ffactor; 65 u_int nelem; 66 u_int cachesize; 67 u_int32_t (*hash)(const void *, size_t); 68 int lorder; 69} HASHINFO; 70.Ed 71.Pp 72The elements of this structure are as follows: 73.Bl -tag -width cachesizex 74.It Fa bsize 75.Fa bsize 76defines the hash table bucket size, and is, by default, 256 bytes. 77It may be preferable to increase the page size for disk-resident 78tables and tables with large data items. 79.It Fa ffactor 80.Fa ffactor 81indicates a desired density within the hash table. 82It is an approximation of the number of keys allowed to accumulate in 83any one bucket, determining when the hash table grows or shrinks. 84The default value is 8. 85.It Fa nelem 86.Fa nelem 87is an estimate of the final size of the hash table. 88If not set or set too low, hash tables will expand gracefully as keys 89are entered, although a slight performance degradation may be 90noticed. 91The default value is 1. 92.It Fa cachesize 93A suggested maximum size, in bytes, of the memory cache. 94This value is 95.Em only 96advisory, and the access method will allocate more memory rather 97than fail. 98.It Fa hash 99.Fa hash 100is a user defined hash function. 101Since no hash function performs equally well on all possible data, the 102user may find that the built-in hash function does poorly on a 103particular data set. 104User specified hash functions must take two arguments (a pointer to a 105byte string and a length) and return a 32-bit quantity to be used as 106the hash value. 107.It Fa lorder 108The byte order for integers in the stored database metadata. 109The number should represent the order as an integer; for example, 110big endian order would be the number 4,321. 111If 112.Fa lorder 113is 0 (no order is specified) the current host order is used. 114If the file already exists, the specified value is ignored and the 115value specified when the tree was created is used. 116.El 117.Pp 118If the file already exists (and the 119.Dv O_TRUNC 120flag is not specified), the values specified for the parameters 121.Fa bsize , 122.Fa ffactor , 123.Fa lorder , 124and 125.Fa nelem 126are ignored and the values specified when the tree was created are 127used. 128.Pp 129If a hash function is specified, 130.Fn hash_open 131will attempt to determine if the hash function specified is the same 132as the one with which the database was created, and will fail if it is 133not. 134.\".Pp 135.\"Backward compatible interfaces to the routines described in 136.\".Xr dbm 3 , 137.\"and 138.\".Xr ndbm 3 139.\"are provided, however these interfaces are not compatible with 140.\"previous file formats. 141.Sh ERRORS 142The 143.Nm 144access method routines may fail and set 145.Va errno 146for any of the errors specified for the library routine 147.Xr dbopen 3 . 148.Sh SEE ALSO 149.Xr btree 3 , 150.Xr dbopen 3 , 151.Xr mpool 3 , 152.Xr recno 3 153.Pp 154.Rs 155.%T "Dynamic Hash Tables" 156.%A Per-Ake Larson 157.%J Communications of the ACM 158.%D April 1988 159.Re 160.Rs 161.%T "A New Hash Package for UNIX" 162.%A Margo Seltzer 163.%J USENIX Proceedings 164.%D Winter 1991 165.Re 166.Sh BUGS 167Only big and little endian byte order is supported. 168