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