158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 658f0484fSRodney W. Grimes.\" are met: 758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 858f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1058f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1158f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 12*fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 1358f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1458f0484fSRodney W. Grimes.\" without specific prior written permission. 1558f0484fSRodney W. Grimes.\" 1658f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1758f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1858f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1958f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2058f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2158f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2258f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2358f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2458f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2558f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2658f0484fSRodney W. Grimes.\" SUCH DAMAGE. 2758f0484fSRodney W. Grimes.\" 28ef5d438eSPaul Traina.\" @(#)hash.3 8.6 (Berkeley) 8/18/94 297f3dea24SPeter Wemm.\" $FreeBSD$ 3058f0484fSRodney W. Grimes.\" 31d74f3e32SRuslan Ermilov.Dd August 18, 1994 32d74f3e32SRuslan Ermilov.Dt HASH 3 33d74f3e32SRuslan Ermilov.Os 34d74f3e32SRuslan Ermilov.Sh NAME 35d74f3e32SRuslan Ermilov.Nm hash 36d74f3e32SRuslan Ermilov.Nd "hash database access method" 37d74f3e32SRuslan Ermilov.Sh SYNOPSIS 3832eef9aeSRuslan Ermilov.In sys/types.h 3932eef9aeSRuslan Ermilov.In db.h 40d74f3e32SRuslan Ermilov.Sh DESCRIPTION 4158f0484fSRodney W. GrimesThe routine 42d74f3e32SRuslan Ermilov.Fn dbopen 4358f0484fSRodney W. Grimesis the library interface to database files. 44d74f3e32SRuslan ErmilovOne of the supported file formats is 45d74f3e32SRuslan Ermilov.Nm 46d74f3e32SRuslan Ermilovfiles. 4758f0484fSRodney W. GrimesThe general description of the database access methods is in 48d74f3e32SRuslan Ermilov.Xr dbopen 3 , 49d74f3e32SRuslan Ermilovthis manual page describes only the 50d74f3e32SRuslan Ermilov.Nm 51d74f3e32SRuslan Ermilovspecific information. 52d74f3e32SRuslan Ermilov.Pp 53d74f3e32SRuslan ErmilovThe 54d74f3e32SRuslan Ermilov.Nm 55d74f3e32SRuslan Ermilovdata structure is an extensible, dynamic hashing scheme. 56d74f3e32SRuslan Ermilov.Pp 5758f0484fSRodney W. GrimesThe access method specific data structure provided to 58d74f3e32SRuslan Ermilov.Fn dbopen 59d74f3e32SRuslan Ermilovis defined in the 60fe08efe6SRuslan Ermilov.In db.h 61d74f3e32SRuslan Ermilovinclude file as follows: 62d74f3e32SRuslan Ermilov.Bd -literal 6358f0484fSRodney W. Grimestypedef struct { 6458f0484fSRodney W. Grimes u_int bsize; 6558f0484fSRodney W. Grimes u_int ffactor; 6658f0484fSRodney W. Grimes u_int nelem; 6758f0484fSRodney W. Grimes u_int cachesize; 686b99842aSEd Schouten uint32_t (*hash)(const void *, size_t); 6958f0484fSRodney W. Grimes int lorder; 7058f0484fSRodney W. Grimes} HASHINFO; 71d74f3e32SRuslan Ermilov.Ed 72d74f3e32SRuslan Ermilov.Pp 7358f0484fSRodney W. GrimesThe elements of this structure are as follows: 74d74f3e32SRuslan Ermilov.Bl -tag -width indent 75d74f3e32SRuslan Ermilov.It Va bsize 762efeeba5SRuslan ErmilovThe 772efeeba5SRuslan Ermilov.Va bsize 782efeeba5SRuslan Ermilovelement 79d74f3e32SRuslan Ermilovdefines the 80d74f3e32SRuslan Ermilov.Nm 81983419feSAndriy Gapontable bucket size, and is, by default, 4096 bytes. 8258f0484fSRodney W. GrimesIt may be preferable to increase the page size for disk-resident tables 8358f0484fSRodney W. Grimesand tables with large data items. 84d74f3e32SRuslan Ermilov.It Va ffactor 852efeeba5SRuslan ErmilovThe 862efeeba5SRuslan Ermilov.Va ffactor 872efeeba5SRuslan Ermilovelement 88d74f3e32SRuslan Ermilovindicates a desired density within the 89d74f3e32SRuslan Ermilov.Nm 90d74f3e32SRuslan Ermilovtable. 9158f0484fSRodney W. GrimesIt is an approximation of the number of keys allowed to accumulate in any 92d74f3e32SRuslan Ermilovone bucket, determining when the 93d74f3e32SRuslan Ermilov.Nm 94d74f3e32SRuslan Ermilovtable grows or shrinks. 9558f0484fSRodney W. GrimesThe default value is 8. 96d74f3e32SRuslan Ermilov.It Va nelem 972efeeba5SRuslan ErmilovThe 982efeeba5SRuslan Ermilov.Va nelem 992efeeba5SRuslan Ermilovelement 100d74f3e32SRuslan Ermilovis an estimate of the final size of the 101d74f3e32SRuslan Ermilov.Nm 102d74f3e32SRuslan Ermilovtable. 103d74f3e32SRuslan ErmilovIf not set or set too low, 104d74f3e32SRuslan Ermilov.Nm 105d74f3e32SRuslan Ermilovtables will expand gracefully as keys 10658f0484fSRodney W. Grimesare entered, although a slight performance degradation may be noticed. 10758f0484fSRodney W. GrimesThe default value is 1. 108d74f3e32SRuslan Ermilov.It Va cachesize 10958f0484fSRodney W. GrimesA suggested maximum size, in bytes, of the memory cache. 11058f0484fSRodney W. GrimesThis value is 111d74f3e32SRuslan Ermilov.Em only 11258f0484fSRodney W. Grimesadvisory, and the access method will allocate more memory rather 11358f0484fSRodney W. Grimesthan fail. 114d74f3e32SRuslan Ermilov.It Va hash 1152efeeba5SRuslan ErmilovThe 1162efeeba5SRuslan Ermilov.Va hash 1172efeeba5SRuslan Ermilovelement 118d74f3e32SRuslan Ermilovis a user defined 119d74f3e32SRuslan Ermilov.Nm 120d74f3e32SRuslan Ermilovfunction. 121d74f3e32SRuslan ErmilovSince no 122d74f3e32SRuslan Ermilov.Nm 123d74f3e32SRuslan Ermilovfunction performs equally well on all possible data, the 124d74f3e32SRuslan Ermilovuser may find that the built-in 125d74f3e32SRuslan Ermilov.Nm 126d74f3e32SRuslan Ermilovfunction does poorly on a particular 12758f0484fSRodney W. Grimesdata set. 128d74f3e32SRuslan ErmilovUser specified 129d74f3e32SRuslan Ermilov.Nm 130d74f3e32SRuslan Ermilovfunctions must take two arguments (a pointer to a byte 131d74f3e32SRuslan Ermilovstring and a length) and return a 32-bit quantity to be used as the 132d74f3e32SRuslan Ermilov.Nm 13358f0484fSRodney W. Grimesvalue. 134d74f3e32SRuslan Ermilov.It Va lorder 13558f0484fSRodney W. GrimesThe byte order for integers in the stored database metadata. 13658f0484fSRodney W. GrimesThe number should represent the order as an integer; for example, 13758f0484fSRodney W. Grimesbig endian order would be the number 4,321. 13858f0484fSRodney W. GrimesIf 139d74f3e32SRuslan Ermilov.Va lorder 14058f0484fSRodney W. Grimesis 0 (no order is specified) the current host order is used. 14158f0484fSRodney W. GrimesIf the file already exists, the specified value is ignored and the 14258f0484fSRodney W. Grimesvalue specified when the tree was created is used. 143d74f3e32SRuslan Ermilov.El 144d74f3e32SRuslan Ermilov.Pp 145d74f3e32SRuslan ErmilovIf the file already exists (and the 146d74f3e32SRuslan Ermilov.Dv O_TRUNC 147d74f3e32SRuslan Ermilovflag is not specified), the 1482efeeba5SRuslan Ermilovvalues specified for the 149d74f3e32SRuslan Ermilov.Va bsize , ffactor , lorder 15058f0484fSRodney W. Grimesand 151d74f3e32SRuslan Ermilov.Va nelem 1522efeeba5SRuslan Ermilovarguments 153d74f3e32SRuslan Ermilovare 154d74f3e32SRuslan Ermilovignored and the values specified when the tree was created are used. 155d74f3e32SRuslan Ermilov.Pp 156d74f3e32SRuslan ErmilovIf a 157d74f3e32SRuslan Ermilov.Nm 158d74f3e32SRuslan Ermilovfunction is specified, 159d74f3e32SRuslan Ermilov.Fn hash_open 160d74f3e32SRuslan Ermilovwill attempt to determine if the 161d74f3e32SRuslan Ermilov.Nm 162d74f3e32SRuslan Ermilovfunction specified is the same as 163d74f3e32SRuslan Ermilovthe one with which the database was created, and will fail if it is not. 164d74f3e32SRuslan Ermilov.Pp 165d74f3e32SRuslan ErmilovBackward compatible interfaces to the older 166d74f3e32SRuslan Ermilov.Em dbm 167d74f3e32SRuslan Ermilovand 168d74f3e32SRuslan Ermilov.Em ndbm 16913032225SJordan K. Hubbardroutines are provided, however these interfaces are not compatible with 17058f0484fSRodney W. Grimesprevious file formats. 171d74f3e32SRuslan Ermilov.Sh ERRORS 172ef5d438eSPaul TrainaThe 173d74f3e32SRuslan Ermilov.Nm 174ef5d438eSPaul Trainaaccess method routines may fail and set 175d74f3e32SRuslan Ermilov.Va errno 176ef5d438eSPaul Trainafor any of the errors specified for the library routine 177d74f3e32SRuslan Ermilov.Xr dbopen 3 . 178d74f3e32SRuslan Ermilov.Sh SEE ALSO 179d74f3e32SRuslan Ermilov.Xr btree 3 , 180d74f3e32SRuslan Ermilov.Xr dbopen 3 , 181d74f3e32SRuslan Ermilov.Xr mpool 3 , 182d74f3e32SRuslan Ermilov.Xr recno 3 183d74f3e32SRuslan Ermilov.Rs 184d74f3e32SRuslan Ermilov.%T "Dynamic Hash Tables" 185d74f3e32SRuslan Ermilov.%A Per-Ake Larson 186d74f3e32SRuslan Ermilov.%R "Communications of the ACM" 187d74f3e32SRuslan Ermilov.%D April 1988 188d74f3e32SRuslan Ermilov.Re 189d74f3e32SRuslan Ermilov.Rs 190d74f3e32SRuslan Ermilov.%T "A New Hash Package for UNIX" 191d74f3e32SRuslan Ermilov.%A Margo Seltzer 192d74f3e32SRuslan Ermilov.%R "USENIX Proceedings" 193d74f3e32SRuslan Ermilov.%D Winter 1991 194d74f3e32SRuslan Ermilov.Re 195d74f3e32SRuslan Ermilov.Sh BUGS 19658f0484fSRodney W. GrimesOnly big and little endian byte order is supported. 197