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