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