]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/hash.3
ec9449c2664bec4ceb7c3ae80ed94550fd82f644
[thirdparty/man-pages.git] / man3 / hash.3
1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
3 .\"
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
5 .\"
6 .\" @(#)hash.3 8.6 (Berkeley) 8/18/94
7 .\"
8 .TH HASH 3 2017-09-15 "" "Linux Programmer's Manual"
9 .UC 7
10 .SH NAME
11 hash \- hash database access method
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .ft B
18 #include <sys/types.h>
19 #include <db.h>
20 .ft R
21 .fi
22 .SH DESCRIPTION
23 .IR "Note well" :
24 This page documents interfaces provided in glibc up until version 2.1.
25 Since version 2.2, glibc no longer provides these interfaces.
26 Probably, you are looking for the APIs provided by the
27 .I libdb
28 library instead.
29 .PP
30 The routine
31 .BR dbopen (3)
32 is the library interface to database files.
33 One of the supported file formats is hash files.
34 The general description of the database access methods is in
35 .BR dbopen (3),
36 this manual page describes only the hash-specific information.
37 .PP
38 The hash data structure is an extensible, dynamic hashing scheme.
39 .PP
40 The access-method-specific data structure provided to
41 .BR dbopen (3)
42 is defined in the
43 .I <db.h>
44 include file as follows:
45 .PP
46 .in +4n
47 .EX
48 typedef struct {
49 unsigned int bsize;
50 unsigned int ffactor;
51 unsigned int nelem;
52 unsigned int cachesize;
53 uint32_t (*hash)(const void *, size_t);
54 int lorder;
55 } HASHINFO;
56 .EE
57 .in
58 .PP
59 The elements of this structure are as follows:
60 .TP 10
61 .I bsize
62 defines the hash table bucket size, and is, by default, 256 bytes.
63 It may be preferable to increase the page size for disk-resident tables
64 and tables with large data items.
65 .TP
66 .I ffactor
67 indicates a desired density within the hash table.
68 It is an approximation of the number of keys allowed to accumulate in any
69 one bucket, determining when the hash table grows or shrinks.
70 The default value is 8.
71 .TP
72 .I nelem
73 is an estimate of the final size of the hash table.
74 If not set or set too low, hash tables will expand gracefully as keys
75 are entered, although a slight performance degradation may be noticed.
76 The default value is 1.
77 .TP
78 .I cachesize
79 is the suggested maximum size, in bytes, of the memory cache.
80 This value is
81 .IR "only advisory" ,
82 and the access method will allocate more memory rather than fail.
83 .TP
84 .I hash
85 is a user-defined hash function.
86 Since no hash function performs equally well on all possible data, the
87 user may find that the built-in hash function does poorly on a particular
88 data set.
89 A user-specified hash functions must take two arguments (a pointer to a byte
90 string and a length) and return a 32-bit quantity to be used as the hash
91 value.
92 .TP
93 .I lorder
94 is the byte order for integers in the stored database metadata.
95 The number should represent the order as an integer; for example,
96 big endian order would be the number 4,321.
97 If
98 .I lorder
99 is 0 (no order is specified), the current host order is used.
100 If the file already exists, the specified value is ignored and the
101 value specified when the tree was created is used.
102 .PP
103 If the file already exists (and the
104 .B O_TRUNC
105 flag is not specified), the
106 values specified for
107 .IR bsize ,
108 .IR ffactor ,
109 .IR lorder ,
110 and
111 .I nelem
112 are
113 ignored and the values specified when the tree was created are used.
114 .PP
115 If a hash function is specified,
116 .I hash_open
117 attempts to determine if the hash function specified is the same as
118 the one with which the database was created, and fails if it is not.
119 .PP
120 Backward-compatible interfaces to the routines described in
121 .BR dbm (3),
122 and
123 .BR ndbm (3)
124 are provided, however these interfaces are not compatible with
125 previous file formats.
126 .SH ERRORS
127 The
128 .I hash
129 access method routines may fail and set
130 .I errno
131 for any of the errors specified for the library routine
132 .BR dbopen (3).
133 .SH BUGS
134 Only big and little endian byte order are supported.
135 .SH SEE ALSO
136 .BR btree (3),
137 .BR dbopen (3),
138 .BR mpool (3),
139 .BR recno (3)
140 .PP
141 .IR "Dynamic Hash Tables" ,
142 Per-Ake Larson, Communications of the ACM, April 1988.
143 .PP
144 .IR "A New Hash Package for UNIX" ,
145 Margo Seltzer, USENIX Proceedings, Winter 1991.