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