OSDN Git Service

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