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