- Uniformly use .In for header file references.
[dragonfly.git] / lib / libc / db / man / hash.3
CommitLineData
984263bc
MD
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.
cbebfd39 12.\" 3. Neither the name of the University nor the names of its contributors
984263bc
MD
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.\" $FreeBSD: src/lib/libc/db/man/hash.3,v 1.4.2.3 2003/02/23 19:45:52 trhodes Exp $
44cb301e 30.\" $DragonFly: src/lib/libc/db/man/hash.3,v 1.4 2006/05/26 19:39:36 swildner Exp $
984263bc
MD
31.\"
32.Dd August 18, 1994
33.Dt HASH 3
34.Os
35.Sh NAME
36.Nm hash
37.Nd "hash database access method"
38.Sh SYNOPSIS
39.In sys/types.h
40.In db.h
41.Sh DESCRIPTION
42The routine
43.Fn dbopen
44is the library interface to database files.
45One of the supported file formats is
46.Nm
47files.
48The general description of the database access methods is in
49.Xr dbopen 3 ,
50this manual page describes only the
51.Nm
52specific information.
53.Pp
54The
55.Nm
56data structure is an extensible, dynamic hashing scheme.
57.Pp
58The access method specific data structure provided to
59.Fn dbopen
60is defined in the
44cb301e 61.In db.h
984263bc
MD
62include file as follows:
63.Bd -literal
64typedef struct {
65 u_int bsize;
66 u_int ffactor;
67 u_int nelem;
68 u_int cachesize;
69 u_int32_t (*hash)(const void *, size_t);
70 int lorder;
71} HASHINFO;
72.Ed
73.Pp
74The elements of this structure are as follows:
75.Bl -tag -width indent
76.It Va bsize
77The
78.Va bsize
79element
80defines the
81.Nm
82table bucket size, and is, by default, 256 bytes.
83It may be preferable to increase the page size for disk-resident tables
84and tables with large data items.
85.It Va ffactor
86The
87.Va ffactor
88element
89indicates a desired density within the
90.Nm
91table.
92It is an approximation of the number of keys allowed to accumulate in any
93one bucket, determining when the
94.Nm
95table grows or shrinks.
96The default value is 8.
97.It Va nelem
98The
99.Va nelem
100element
101is an estimate of the final size of the
102.Nm
103table.
104If not set or set too low,
105.Nm
106tables will expand gracefully as keys
107are entered, although a slight performance degradation may be noticed.
108The default value is 1.
109.It Va cachesize
110A suggested maximum size, in bytes, of the memory cache.
111This value is
112.Em only
113advisory, and the access method will allocate more memory rather
114than fail.
115.It Va hash
116The
117.Va hash
118element
119is a user defined
120.Nm
121function.
122Since no
123.Nm
124function performs equally well on all possible data, the
125user may find that the built-in
126.Nm
127function does poorly on a particular
128data set.
129User specified
130.Nm
131functions must take two arguments (a pointer to a byte
132string and a length) and return a 32-bit quantity to be used as the
133.Nm
134value.
135.It Va lorder
136The byte order for integers in the stored database metadata.
137The number should represent the order as an integer; for example,
138big endian order would be the number 4,321.
139If
140.Va lorder
141is 0 (no order is specified) the current host order is used.
142If the file already exists, the specified value is ignored and the
143value specified when the tree was created is used.
144.El
145.Pp
146If the file already exists (and the
147.Dv O_TRUNC
148flag is not specified), the
149values specified for the
150.Va bsize , ffactor , lorder
151and
152.Va nelem
153arguments
154are
155ignored and the values specified when the tree was created are used.
156.Pp
157If a
158.Nm
159function is specified,
160.Fn hash_open
161will attempt to determine if the
162.Nm
163function specified is the same as
164the one with which the database was created, and will fail if it is not.
165.Pp
166Backward compatible interfaces to the older
167.Em dbm
168and
169.Em ndbm
170routines are provided, however these interfaces are not compatible with
171previous file formats.
172.Sh ERRORS
173The
174.Nm
175access method routines may fail and set
176.Va errno
177for any of the errors specified for the library routine
178.Xr dbopen 3 .
179.Sh SEE ALSO
180.Xr btree 3 ,
181.Xr dbopen 3 ,
182.Xr mpool 3 ,
183.Xr recno 3
184.Rs
185.%T "Dynamic Hash Tables"
186.%A Per-Ake Larson
187.%R "Communications of the ACM"
188.%D April 1988
189.Re
190.Rs
191.%T "A New Hash Package for UNIX"
192.%A Margo Seltzer
193.%R "USENIX Proceedings"
194.%D Winter 1991
195.Re
196.Sh BUGS
197Only big and little endian byte order is supported.