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. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)hash.3 8.6 (Berkeley) 8/18/94 29.\" 30.Dd August 18, 1994 31.Dt HASH 3 32.Os 33.Sh NAME 34.Nm hash 35.Nd "hash database access method" 36.Sh SYNOPSIS 37.In sys/types.h 38.In db.h 39.Sh DESCRIPTION 40The routine 41.Fn dbopen 42is the library interface to database files. 43One of the supported file formats is 44.Nm 45files. 46The general description of the database access methods is in 47.Xr dbopen 3 , 48this manual page describes only the 49.Nm 50specific information. 51.Pp 52The 53.Nm 54data 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.In 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 uint32_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 indent 74.It Va bsize 75The 76.Va bsize 77element 78defines the 79.Nm 80table bucket size, and is, by default, 4096 bytes. 81It may be preferable to increase the page size for disk-resident tables 82and tables with large data items. 83.It Va ffactor 84The 85.Va ffactor 86element 87indicates a desired density within the 88.Nm 89table. 90It is an approximation of the number of keys allowed to accumulate in any 91one bucket, determining when the 92.Nm 93table grows or shrinks. 94The default value is 8. 95.It Va nelem 96The 97.Va nelem 98element 99is an estimate of the final size of the 100.Nm 101table. 102If not set or set too low, 103.Nm 104tables will expand gracefully as keys 105are entered, although a slight performance degradation may be noticed. 106The default value is 1. 107.It Va cachesize 108A suggested maximum size, in bytes, of the memory cache. 109This value is 110.Em only 111advisory, and the access method will allocate more memory rather 112than fail. 113.It Va hash 114The 115.Va hash 116element 117is a user defined 118.Nm 119function. 120Since no 121.Nm 122function performs equally well on all possible data, the 123user may find that the built-in 124.Nm 125function does poorly on a particular 126data set. 127User specified 128.Nm 129functions must take two arguments (a pointer to a byte 130string and a length) and return a 32-bit quantity to be used as the 131.Nm 132value. 133.It Va lorder 134The byte order for integers in the stored database metadata. 135The number should represent the order as an integer; for example, 136big endian order would be the number 4,321. 137If 138.Va lorder 139is 0 (no order is specified) the current host order is used. 140If the file already exists, the specified value is ignored and the 141value specified when the tree was created is used. 142.El 143.Pp 144If the file already exists (and the 145.Dv O_TRUNC 146flag is not specified), the 147values specified for the 148.Va bsize , ffactor , lorder 149and 150.Va nelem 151arguments 152are 153ignored and the values specified when the tree was created are used. 154.Pp 155If a 156.Nm 157function is specified, 158.Fn hash_open 159will attempt to determine if the 160.Nm 161function specified is the same as 162the one with which the database was created, and will fail if it is not. 163.Pp 164Backward compatible interfaces to the older 165.Em dbm 166and 167.Em ndbm 168routines are provided, however these interfaces are not compatible with 169previous file formats. 170.Sh ERRORS 171The 172.Nm 173access method routines may fail and set 174.Va errno 175for any of the errors specified for the library routine 176.Xr dbopen 3 . 177.Sh SEE ALSO 178.Xr btree 3 , 179.Xr dbopen 3 , 180.Xr mpool 3 , 181.Xr recno 3 182.Rs 183.%T "Dynamic Hash Tables" 184.%A Per-Ake Larson 185.%R "Communications of the ACM" 186.%D April 1988 187.Re 188.Rs 189.%T "A New Hash Package for UNIX" 190.%A Margo Seltzer 191.%R "USENIX Proceedings" 192.%D Winter 1991 193.Re 194.Sh BUGS 195Only big and little endian byte order is supported. 196