xref: /minix3/lib/libc/db/man/hash.3 (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1*2fe8fb19SBen Gras.\"	$NetBSD: hash.3,v 1.14 2010/12/16 11:57:20 jruoho Exp $
22639ae9bSBen Gras.\"
32639ae9bSBen Gras.\" Copyright (c) 1990, 1993
42639ae9bSBen Gras.\"	The Regents of the University of California.  All rights reserved.
52639ae9bSBen Gras.\"
62639ae9bSBen Gras.\" Redistribution and use in source and binary forms, with or without
72639ae9bSBen Gras.\" modification, are permitted provided that the following conditions
82639ae9bSBen Gras.\" are met:
92639ae9bSBen Gras.\" 1. Redistributions of source code must retain the above copyright
102639ae9bSBen Gras.\"    notice, this list of conditions and the following disclaimer.
112639ae9bSBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
122639ae9bSBen Gras.\"    notice, this list of conditions and the following disclaimer in the
132639ae9bSBen Gras.\"    documentation and/or other materials provided with the distribution.
142639ae9bSBen Gras.\" 3. Neither the name of the University nor the names of its contributors
152639ae9bSBen Gras.\"    may be used to endorse or promote products derived from this software
162639ae9bSBen Gras.\"    without specific prior written permission.
172639ae9bSBen Gras.\"
182639ae9bSBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
192639ae9bSBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202639ae9bSBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212639ae9bSBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
222639ae9bSBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232639ae9bSBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
242639ae9bSBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
252639ae9bSBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
262639ae9bSBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
272639ae9bSBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
282639ae9bSBen Gras.\" SUCH DAMAGE.
292639ae9bSBen Gras.\"
302639ae9bSBen Gras.\"	@(#)hash.3	8.6 (Berkeley) 8/18/94
312639ae9bSBen Gras.\"
32*2fe8fb19SBen Gras.Dd December 16, 2010
332639ae9bSBen Gras.Dt HASH 3
342639ae9bSBen Gras.Os
352639ae9bSBen Gras.Sh NAME
362639ae9bSBen Gras.Nm hash
372639ae9bSBen Gras.Nd hash database access method
382639ae9bSBen Gras.Sh SYNOPSIS
392639ae9bSBen Gras.In sys/types.h
402639ae9bSBen Gras.In db.h
412639ae9bSBen Gras.Sh DESCRIPTION
422639ae9bSBen GrasThe routine
432639ae9bSBen Gras.Fn dbopen
442639ae9bSBen Grasis the library interface to database files.
452639ae9bSBen GrasOne of the supported file formats is hash files.
462639ae9bSBen GrasThe general description of the database access methods is in
472639ae9bSBen Gras.Xr dbopen 3 ,
482639ae9bSBen Grasthis manual page describes only the hash specific information.
492639ae9bSBen Gras.Pp
502639ae9bSBen GrasThe hash data structure is an extensible, dynamic hashing scheme.
512639ae9bSBen Gras.Pp
522639ae9bSBen GrasThe access method specific data structure provided to
532639ae9bSBen Gras.Fn dbopen
542639ae9bSBen Grasis defined in the
552639ae9bSBen Gras.In db.h
56*2fe8fb19SBen Grasheader as follows:
57*2fe8fb19SBen Gras.Bd -literal -offset indent
582639ae9bSBen Grastypedef struct {
592639ae9bSBen Gras	u_int bsize;
602639ae9bSBen Gras	u_int ffactor;
612639ae9bSBen Gras	u_int nelem;
622639ae9bSBen Gras	u_int cachesize;
632639ae9bSBen Gras	uint32_t (*hash)(const void *, size_t);
642639ae9bSBen Gras	int lorder;
652639ae9bSBen Gras} HASHINFO;
662639ae9bSBen Gras.Ed
672639ae9bSBen Gras.Pp
682639ae9bSBen GrasThe elements of this structure are as follows:
692639ae9bSBen Gras.Bl -tag -width cachesizex
702639ae9bSBen Gras.It Fa bsize
712639ae9bSBen Gras.Fa bsize
722639ae9bSBen Grasdefines the hash table bucket size, and defaults to 4096 for in-memory tables.
732639ae9bSBen GrasIf
742639ae9bSBen Gras.Fa bsize
752639ae9bSBen Grasis 0 (no bucket size is specified) a bucket size is chosen based on the
762639ae9bSBen Grasunderlying file system I/O block size.
772639ae9bSBen GrasIt may be preferable to increase the page size for disk-resident
782639ae9bSBen Grastables and tables with large data items.
792639ae9bSBen Gras.It Fa ffactor
802639ae9bSBen Gras.Fa ffactor
812639ae9bSBen Grasindicates a desired density within the hash table.
822639ae9bSBen GrasIt is an approximation of the number of keys allowed to accumulate in
832639ae9bSBen Grasany one bucket, determining when the hash table grows or shrinks.
842639ae9bSBen GrasThe default value is 8.
852639ae9bSBen Gras.It Fa nelem
862639ae9bSBen Gras.Fa nelem
872639ae9bSBen Grasis an estimate of the final size of the hash table.
882639ae9bSBen GrasIf not set or set too low, hash tables will expand gracefully as keys
892639ae9bSBen Grasare entered, although a slight performance degradation may be
902639ae9bSBen Grasnoticed.
912639ae9bSBen GrasThe default value is 1.
922639ae9bSBen Gras.It Fa cachesize
932639ae9bSBen GrasA suggested maximum size, in bytes, of the memory cache.
942639ae9bSBen GrasThis value is
952639ae9bSBen Gras.Em only
962639ae9bSBen Grasadvisory, and the access method will allocate more memory rather
972639ae9bSBen Grasthan fail.
982639ae9bSBen Gras.It Fa hash
992639ae9bSBen Gras.Fa hash
1002639ae9bSBen Grasis a user defined hash function.
1012639ae9bSBen GrasSince no hash function performs equally well on all possible data, the
1022639ae9bSBen Grasuser may find that the built-in hash function does poorly on a
1032639ae9bSBen Grasparticular data set.
1042639ae9bSBen GrasUser specified hash functions must take two arguments (a pointer to a
1052639ae9bSBen Grasbyte string and a length) and return a 32-bit quantity to be used as
1062639ae9bSBen Grasthe hash value.
1072639ae9bSBen Gras.It Fa lorder
1082639ae9bSBen GrasThe byte order for integers in the stored database metadata.
1092639ae9bSBen GrasThe number should represent the order as an integer; for example,
1102639ae9bSBen Grasbig endian order would be the number 4,321.
1112639ae9bSBen GrasIf
1122639ae9bSBen Gras.Fa lorder
1132639ae9bSBen Grasis 0 (no order is specified) the current host order is used.
1142639ae9bSBen GrasIf the file already exists, the specified value is ignored and the
1152639ae9bSBen Grasvalue specified when the tree was created is used.
1162639ae9bSBen Gras.El
1172639ae9bSBen Gras.Pp
1182639ae9bSBen GrasIf the file already exists (and the
1192639ae9bSBen Gras.Dv O_TRUNC
1202639ae9bSBen Grasflag is not specified), the values specified for the parameters
1212639ae9bSBen Gras.Fa bsize ,
1222639ae9bSBen Gras.Fa ffactor ,
1232639ae9bSBen Gras.Fa lorder ,
1242639ae9bSBen Grasand
1252639ae9bSBen Gras.Fa nelem
1262639ae9bSBen Grasare ignored and the values specified when the tree was created are
1272639ae9bSBen Grasused.
1282639ae9bSBen Gras.Pp
1292639ae9bSBen GrasIf a hash function is specified,
1302639ae9bSBen Gras.Fn hash_open
1312639ae9bSBen Graswill attempt to determine if the hash function specified is the same
1322639ae9bSBen Grasas the one with which the database was created, and will fail if it is
1332639ae9bSBen Grasnot.
1342639ae9bSBen Gras.\".Pp
1352639ae9bSBen Gras.\"Backward compatible interfaces to the routines described in
1362639ae9bSBen Gras.\".Xr dbm 3 ,
1372639ae9bSBen Gras.\"and
1382639ae9bSBen Gras.\".Xr ndbm 3
1392639ae9bSBen Gras.\"are provided, however these interfaces are not compatible with
1402639ae9bSBen Gras.\"previous file formats.
1412639ae9bSBen Gras.Sh ERRORS
1422639ae9bSBen GrasThe
1432639ae9bSBen Gras.Nm
1442639ae9bSBen Grasaccess method routines may fail and set
1452639ae9bSBen Gras.Va errno
1462639ae9bSBen Grasfor any of the errors specified for the library routine
1472639ae9bSBen Gras.Xr dbopen 3 .
1482639ae9bSBen Gras.Sh SEE ALSO
1492639ae9bSBen Gras.Xr btree 3 ,
1502639ae9bSBen Gras.Xr dbopen 3 ,
1512639ae9bSBen Gras.Xr mpool 3 ,
1522639ae9bSBen Gras.Xr recno 3
1532639ae9bSBen Gras.Pp
1542639ae9bSBen Gras.Rs
155*2fe8fb19SBen Gras.%T Dynamic Hash Tables
1562639ae9bSBen Gras.%A Per-Ake Larson
1572639ae9bSBen Gras.%J Communications of the ACM
1582639ae9bSBen Gras.%D April 1988
159*2fe8fb19SBen Gras.%N Issue 4
160*2fe8fb19SBen Gras.%V Volume 31
1612639ae9bSBen Gras.Re
1622639ae9bSBen Gras.Rs
163*2fe8fb19SBen Gras.%T A New Hash Package for UNIX
1642639ae9bSBen Gras.%A Margo Seltzer
165*2fe8fb19SBen Gras.%I USENIX Association
166*2fe8fb19SBen Gras.%B Proceedings of the 1991 Winter USENIX Technical Conference
167*2fe8fb19SBen Gras.%D January 1991
168*2fe8fb19SBen Gras.%P 173-184
169*2fe8fb19SBen Gras.%U http://www.usenix.org/publications/library/proceedings/seltzer2.pdf
1702639ae9bSBen Gras.Re
1712639ae9bSBen Gras.Sh BUGS
1722639ae9bSBen GrasOnly big and little endian byte order is supported.
173