1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)hash.3 8.6 (Berkeley) 8/18/94
34 .\" Japanese Version Copyright (c) 1999 Shouichi Saito
35 .\" all rights reserved.
36 .\" Translated Mon Jul 26 14:22:49 JST 1999
37 .\" by Shouichi Saito <ss236rx@ymg.urban.ne.jp>
38 .\" Proofed Tue Aug 17 1999 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
39 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
41 .\"WORD: access method ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É
42 .\"WORD: bucket ¥Ð¥±¥Ã¥È
44 .TH HASH 3 1994-08-18 "" "Linux Programmer's Manual"
47 .\"O hash \- hash database access method
48 hash \- hash ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ø¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥É
52 #include <sys/types.h>
59 .\"O is the library interface to database files.
60 .\"O One of the supported file formats is hash files.
63 ¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë¥é¥¤¥Ö¥é¥ê¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ç¤¢¤ë¡£
64 ¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¤Ò¤È¤Ä¤Ë hash ¥Õ¥¡¥¤¥ë¤¬¤¢¤ë¡£
65 .\"O The general description of the database access methods is in
67 .\"O this manual page describes only the hash specific information.
68 ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ø¤Î¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ë´Ø¤¹¤ë°ìÈÌŪ¤Êµ½Ò¤Ï
71 ¤³¤Î¥Þ¥Ë¥å¥¢¥ë¥Ú¡¼¥¸¤Ç¤Ï hash ÆÃͤξðÊó¤Ë¤Ä¤¤¤Æ¤Î¤ßµ½Ò¤¹¤ë¡£
73 .\"O The hash data structure is an extensible, dynamic hashing scheme.
74 hash ¥Ç¡¼¥¿¹½Â¤¤Ï¡¢³ÈÄ¥²Äǽ¤ÊưŪ¥Ï¥Ã¥·¥å¥¹¥¡¼¥à¤Ç¤¢¤ë¡£
76 .\"O The access method specific data structure provided to
78 .\"O is defined in the
80 .\"O include file as follows:
82 ¤ËÅϤµ¤ì¤ë hash ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤ËÆÃͤΥǡ¼¥¿¹½Â¤ÂΤϡ¢
84 ¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
92 unsigned int cachesize;
93 uint32_t (*hash)(const void *, size_t);
99 .\"O The elements of this structure are as follows:
100 ¤³¤Î¹½Â¤ÂΤÎÍ×ÁǤò°Ê²¼¤Ë¼¨¤¹¡£
103 .\"O defines the hash table bucket size, and is, by default, 256 bytes.
104 .\"O It may be preferable to increase the page size for disk-resident tables
105 .\"O and tables with large data items.
106 hash ¥Æ¡¼¥Ö¥ë¥Ð¥±¥Ã¥È (table bucket) ¤Î¥µ¥¤¥º¤òÄêµÁ¤¹¤ë¡£
107 ¥Ç¥Õ¥©¥ë¥È¤Ï 256 ¥Ð¥¤¥È¤Ç¤¢¤ë¡£
108 ¥Ç¥£¥¹¥¯¤ËÃÖ¤«¤ì¤ë¥Æ¡¼¥Ö¥ë¤ä¥Ç¡¼¥¿¥¢¥¤¥Æ¥à¤¬Â礤¤¥Æ¡¼¥Ö¥ë¤Ç¤Ï
109 ¥Ú¡¼¥¸¥µ¥¤¥º¤òÂ礤¯¤¹¤ë¤Û¤¦¤¬Îɤ¤¤À¤í¤¦¡£
112 .\"O indicates a desired density within the hash table.
113 .\"O It is an approximation of the number of keys allowed to accumulate in any
114 .\"O one bucket, determining when the hash table grows or shrinks.
115 .\"O The default value is 8.
116 ¥æ¡¼¥¶¤¬Ë¾¤à hash ¥Æ¡¼¥Ö¥ëÃæ¤ÎÌ©Å٤Ǥ¢¤ë¡£
117 ¤³¤ì¤Ï¤½¤ì¤¾¤ì¤Î¥Ð¥±¥Ã¥È¤Ë³ÊǼ¤Ç¤¤ë¥¡¼¤Î³µ¿ô¤Ç¤¢¤ê¡¢
118 hash ¥Æ¡¼¥Ö¥ë¤ò³ÈÂ硦½Ì¾®¤òºîÍѤ¹¤ë¡£
119 ¥Ç¥Õ¥©¥ë¥È¤Ï 8 ¤Ç¤¢¤ë¡£
122 .\"O is an estimate of the final size of the hash table.
123 .\"O If not set or set too low, hash tables will expand gracefully as keys
124 .\"O are entered, although a slight performance degradation may be noticed.
125 .\"O The default value is 1.
126 hash ¥Æ¡¼¥Ö¥ë¤ÎºÇ½ª¥µ¥¤¥º¤òÂç¤Þ¤«¤Ë¸«ÀѤâ¤Ã¤¿ÃͤǤ¢¤ë¡£
127 ¤³¤ÎÃͤ¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¤ê¡¢¤¢¤Þ¤ê¤ËÄ㤯¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤È¡¢
128 hash ¥Æ¡¼¥Ö¥ë¤Ï¥¡¼¤¬Æþ¤Ã¤Æ¤¯¤ë¤Ë±þ¤¸¤Æ³ÈÄ¥¤µ¤ì¤ë¡£
129 ¤·¤«¤·¾¯¤·¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤¬ (¤ª¤½¤é¤¯µ¤ÉÕ¤¯ÄøÅÙ¤Ë) Íî¤Á¤ë¡£
130 ¥Ç¥Õ¥©¥ë¥ÈÃÍ¤Ï 1 ¤Ç¤¢¤ë¡£
133 .\"O is the suggested maximum size, in bytes, of the memory cache.
135 .\"O .IR "only advisory" ,
136 .\"O and the access method will allocate more memory rather than fail.
137 ¥á¥â¥ê¥¥ã¥Ã¥·¥å¤ÎºÇÂçÃÍ (¥Ð¥¤¥Èñ°Ì) ¤Î»²¹ÍÃÍ¡£
139 .BR ¤¢¤¯¤Þ¤Ç»²¹Í¤Ç¤¢¤ê ¡¢
140 ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¤Ï¤³¤ÎÃͤò±Û¤¨¤¿¥á¥â¥ê¤Î³ä¤êÅö¤Æ¤ËÀ®¸ù¤¹¤ë¤³¤È¤â¤¢¤ë¡£
143 .\"O is a user-defined hash function.
144 .\"O Since no hash function performs equally well on all possible data, the
145 .\"O user may find that the built-in hash function does poorly on a particular
147 ¤Ï¥æ¡¼¥¶¡¼ÄêµÁ¤Î hash ´Ø¿ô¤Ç¤¢¤ë¡£
148 Á´¤Æ¤Î¥Ç¡¼¥¿¤ËÂФ·¤Æ¤¦¤Þ¤¯ºîÍѤ¹¤ë hash ´Ø¿ô¤È¸À¤¦¤Î¤Ï¤Ê¤¤¤«¤é¡¢
149 ÆÃÄê¤Î¥Ç¡¼¥¿¥»¥Ã¥È¤ËÂФ·¤Æ¤ÏÁȤ߹þ¤ß¤Î hash ´Ø¿ô¤Ç¤Ï
150 ¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤¬Ä㤤¤³¤È¤â¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
151 .\"O A user-specified hash functions must take two arguments (a pointer to a byte
152 .\"O string and a length) and return a 32-bit quantity to be used as the hash
154 ¥æ¡¼¥¶¡¼ÄêµÁ¤Î hash ´Ø¿ô¤ÏÆó¤Ä¤Î°ú¿ô¤ò¤È¤é¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤ (¥Ð¥¤¥Èʸ»ú
155 Îó¤Ø¤Î¥Ý¥¤¥ó¥¿¤È¡¢Ä¹¤µ)¡£
156 ¤½¤·¤Æ hash ÃͤȤ·¤Æ»È¤ï¤ì¤ë 32¥Ó¥Ã¥È¤ÎÃͤòÊÖ¤µ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
159 .\"O is the byte order for integers in the stored database metadata.
160 .\"O The number should represent the order as an integer; for example,
161 .\"O big endian order would be the number 4,321.
162 ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë¥á¥¿¥Ç¡¼¥¿¤ÎÀ°¿ôÃͤΥХ¤¥È¥ª¡¼¥À¡¼¡£
163 ¤³¤Î¿ô»ú¤Ï¡¢½ç½ø¤òÀ°¿ô¤Çɽ¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
164 Î㤨¤Ð¥Ó¥Ã¥°¥¨¥ó¥Ç¥£¥¢¥ó¤Ê¤é¡¢¤³¤Î¿ôÃÍ¤Ï 4,321 ¤È¤Ê¤ë¡£
167 .\"O is 0 (no order is specified) the current host order is used.
168 .\"O If the file already exists, the specified value is ignored and the
169 .\"O value specified when the tree was created is used.
170 ¤¬ 0 (»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤)¾ì¹ç¡¢¸½ºß¤Î¥Û¥¹¥È
171 ¤Ç»È¤ï¤ì¤Æ¤¤¤ëʤӽ礬»È¤ï¤ì¤ë¡£
172 ¥Õ¥¡¥¤¥ë¤¬´û¤Ë¸ºß¤¹¤ë¾ì¹ç¡¢»ØÄꤷ¤¿ÃͤÏ̵»ë¤µ¤ì¥Ä¥ê¡¼¤¬ºî¤é¤ì
173 ¤¿»þ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤¿Ãͤ¬»È¤ï¤ì¤ë¡£
175 .\"O If the file already exists (and the
177 .\"O flag is not specified), the
178 .\"O values specified for
185 .\"O ignored and the values specified when the tree was created are used.
186 .\"NAKANO the tree ¢ª the hash, ¤Ç¤·¤ç¤¦.
187 ¥Õ¥¡¥¤¥ë¤¬´û¤Ë¸ºß¤·¤Æ¤¤¤ë (¤Þ¤¿¤Ï
189 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤) ¤È¡¢
194 ¤Ë»ØÄꤵ¤ì¤¿ÃͤÏ̵»ë¤µ¤ì¡¢
195 ¥Ï¥Ã¥·¥å¤¬ºî¤é¤ì¤¿»þ¤Ë»È¤Ã¤¿Ãͤ¬»È¤ï¤ì¤ë¡£
197 .\"O If a hash function is specified,
198 hash ´Ø¿ô¤¬»ØÄꤵ¤ì¤ë¤È¡¢
200 .\"O will attempt to determine if the hash function specified is the same as
201 .\"O the one with which the database was created, and will fail if it is not.
202 ¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬ºî¤é¤ì¤¿»þ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤¿
203 hash ´Ø¿ô¤Èº£²ó»ØÄꤵ¤ì¤¿ hash ´Ø¿ô¤¬Æ±¤¸¤«¤É¤¦¤«¤òÄ´¤Ù¡¢
204 Ʊ¤¸¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¼ºÇÔ¤¹¤ë¡£
206 .\"O Backward-compatible interfaces to the routines described in
211 ¤Ëµ½Ò¤µ¤ì¤Æ¤¤¤ë¥ë¡¼¥Á¥ó¤Ø¤Î²áµî¸ß´¹¤ò¼è¤ë¤¿¤á¤Î¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤¬
212 ¸ºß¤¹¤ë¡£¤·¤«¤·¤³¤ì¤é¤Î¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤Ï°ÊÁ°¤Î¥Õ¥¡¥¤¥ë¥Õ¥©¡¼
213 ¥Þ¥Ã¥È¤È¤Ï¸ß´¹À¤¬¤Ê¤¤¡£
214 .\"O are provided, however these interfaces are not compatible with
215 .\"O previous file formats.
219 .\"O access method routines may fail and set
221 .\"O for any of the errors specified for the library routine
224 ¥¢¥¯¥»¥¹¥á¥½¥Ã¥É¥ë¡¼¥Á¥ó¤Ï¡¢¼ºÇÔ¤¹¤ë¤È¥é¥¤¥Ö¥é¥ê¥ë¡¼¥Á¥ó
226 ¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ë±þ¤¸¤¿
230 .\"O Only big and little endian byte order are supported.
231 ¥Ð¥¤¥È¥ª¡¼¥À¡¼¤È¤·¤Æ¤Ï¥Ó¥Ã¥°¥¨¥ó¥Ç¥£¥¢¥ó¤È¥ê¥È¥ë¥¨¥ó¥Ç¥£¥¢¥ó¤Î¤ß¤¬
239 .IR "Dynamic Hash Tables" ,
240 Per-Ake Larson, Communications of the ACM, April 1988.
242 .IR "A New Hash Package for UNIX" ,
243 Margo Seltzer, USENIX Proceedings, Winter 1991.