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