1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\" Copyright 1993 Ulrich Drepper (drepper@karlsruhe.gmd.de)
3 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
4 .\" <mtk.manpages@gmail.com>
6 .\" This is free documentation; you can redistribute it and/or
7 .\" modify it under the terms of the GNU General Public License as
8 .\" published by the Free Software Foundation; either version 2 of
9 .\" the License, or (at your option) any later version.
11 .\" The GNU General Public License's references to "object code"
12 .\" and "executables" are to be interpreted as the output of any
13 .\" document formatting or typesetting system, including
14 .\" intermediate and printed output.
16 .\" This manual is distributed in the hope that it will be useful,
17 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 .\" GNU General Public License for more details.
21 .\" You should have received a copy of the GNU General Public
22 .\" License along with this manual; if not, write to the Free
23 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
26 .\" References consulted:
27 .\" SunOS 4.1.1 man pages
28 .\" Modified Sat Sep 30 21:52:01 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
29 .\" Remarks from dhw@gamgee.acad.emich.edu Fri Jun 19 06:46:31 1998
30 .\" Modified 2001-12-26, 2003-11-28, 2004-05-20, aeb
31 .\" 2008-09-02, mtk: various additions and rewrites
32 .\" 2008-09-03, mtk, restructured somewhat, in part after suggestions from
33 .\" Timothy S. Nelson <wayland@wayland.id.au>
35 .\" Japanese Version Copyright (c) 1998 George Momma,
36 .\" Copyright (c) 2001-2005 Yuichi SATO,
37 .\" and Copyright (c) 2008 Akihiro MOTOKI
38 .\" Translated 1998-05-23, George Momma <momma@wakhok.ac.jp>
39 .\" Updated & Modified 2001-10-15, Yuichi SATO <ysato@h4.dion.ne.jp>
40 .\" Updated & Modified 2002-01-03, Yuichi SATO
41 .\" Updated & Modified 2004-01-17, Yuichi SATO <ysato444@yahoo.co.jp>
42 .\" Updated & Modified 2005-01-10, Yuichi SATO
43 .\" Updated 2008-09-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
45 .\"WORD: hash table ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë
46 .\"WORD: entry ¥¨¥ó¥È¥ê¡¼
47 .\"WORD: allocate ³ä¤êÅö¤Æ
48 .\"WORD: NUL-terminated ¥Ì¥ëʸ»ú \0 ¤Ç½ªÃ¼¤µ¤ì¤¿
49 .\"WORD: pointer ¥Ý¥¤¥ó¥¿
50 .\"WORD: character ʸ»ú·¿
53 .TH HSEARCH 3 2008-10-06 "GNU" "Linux Programmer's Manual"
56 .\"O hcreate, hdestroy, hsearch, hcreate_r, hdestroy_r,
57 .\"O hsearch_r \- hash table management
58 hcreate, hdestroy, hsearch, hcreate_r, hdestroy_r,
59 hsearch_r \- ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Î´ÉÍý
63 .B #include <search.h>
65 .BI "int hcreate(size_t " nel );
67 .BI "ENTRY *hsearch(ENTRY " item ", ACTION " action );
69 .B "void hdestroy(void);"
71 .B #define _GNU_SOURCE
73 .B #include <search.h>
75 .BI "int hcreate_r(size_t " nel ", struct hsearch_data *" htab );
77 .BI "int hsearch_r(ENTRY " item ", ACTION " action ", ENTRY **" retval ,
78 .BI " struct hsearch_data *" htab );
80 .BI "void hdestroy_r(struct hsearch_data *" htab );
84 .\"O The three functions
89 .\"O allow the caller to create and manage a hash search table
90 .\"O containing entries consisting of a key (a string) and associated data.
91 .\"O Using these functions, only one hash table can be used at a time.
95 ¤Î 3 ¤Ä¤Î´Ø¿ô¤òÍøÍѤ¹¤ë¤È¡¢¥¡¼ (ʸ»úÎó) ¤ÈÂбþ¤¹¤ë¥Ç¡¼¥¿¤«¤é¹½À®¤µ¤ì¤ë
96 ¥¨¥ó¥È¥ê¤ò³ÊǼ¤Ç¤¤ë¥Ï¥Ã¥·¥å¸¡º÷¥Æ¡¼¥Ö¥ë¤òºîÀ®¡¢´ÉÍý¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
97 ¤³¤ì¤é¤Î´Ø¿ô¤ò»È¤Ã¤Æ¡¢°ìÅ٤˻ÈÍѤǤ¤ë¤Î¤Ï°ì¤Ä¤Î¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤À¤±¤Ç¤¢¤ë¡£
99 .\"O The three functions
100 .\"O .BR hcreate_r (),
101 .\"O .BR hsearch_r (),
102 .\"O .BR hdestroy_r ()
103 .\"O are reentrant versions that allow a program to use
104 .\"O more than one hash search table at the same time.
105 .\"O The last argument,
107 .\"O points to a structure that describes the table
108 .\"O on which the function is to operate.
109 .\"O The programmer should treat this structure as opaque
110 .\"O (i.e., do not attempt to directly access or modify
111 .\"O the fields in this structure).
115 ¤Î 3 ¤Ä¤Î´Ø¿ô¤Ï¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤǡ¢¤³¤ì¤é¤òÍøÍѤ¹¤ë¤È¡¢
116 °ì¤Ä¤Î¥×¥í¥°¥é¥à¤ÇƱ»þ¤ËÊ£¿ô¤Î¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ò»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
119 ¤Ï´Ø¿ô¤ÎÁàºîÂоݤȤʤë¥Æ¡¼¥Ö¥ë¤ò¼¨¤¹¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
120 ¥×¥í¥°¥é¥Þ¤Ï¤³¤Î¹½Â¤ÂΤò¥Ö¥é¥Ã¥¯¥Ü¥Ã¥¯¥¹¤È¤·¤Æ°·¤¦¤Ù¤¤Ç¤¢¤ë
121 (¤Ä¤Þ¤ê¡¢¤³¤Î¹½Â¤ÂΤΥե£¡¼¥ë¥É¤ËľÀÜ¥¢¥¯¥»¥¹¤·¤¿¤êÊѹ¹¤·¤¿¤ê
124 .\"O First a hash table must be created using
126 .\"O The argument \fInel\fP specifies the maximum number of entries
128 .\"O (This maximum cannot be changed later, so choose it wisely.)
129 .\"O The implementation may adjust this value upward to improve the
130 .\"O performance of the resulting hash table.
133 ´Ø¿ô¤Ë¤è¤Ã¤Æ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤òºîÀ®¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
134 °ú¤¿ô \fInel\fP ¤Ç¥Æ¡¼¥Ö¥ë¤ÎºÇÂ票¥ó¥È¥ê¿ô¤ò»ØÄꤹ¤ë
135 (¤³¤ÎºÇÂçÃͤϸå¤ÇÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¤Î¤Ç¡¢¤è¤¯¹Í¤¨¤ÆÁªÂò¤¹¤ë¤³¤È)¡£
136 ºîÀ®¤µ¤ì¤ë¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ÎÀǽ¤ò¸þ¾å¤µ¤»¤ë¤¿¤á¤Ë¡¢
137 ´Ø¿ôÆâÉô¤Î¼ÂÁõ¤Ë¤è¤ê¤³¤ÎÃͤÏÁý¤ä¤µ¤ì¤ë¾ì¹ç¤â¤¢¤ë¡£
138 .\" e.g., in glibc it is raised to the next higher prime number
141 .\"O .BR hcreate_r ()
142 .\"O function performs the same task as
144 .\"O but for the table described by the structure
146 .\"O The structure pointed to by
148 .\"O must be zeroed before the first call to
149 .\"O .BR hcreate_r ().
153 ¤ÈƱ¤¸Æ°ºî¤ò¤¹¤ë¤¬¡¢¹½Â¤ÂÎ
155 ¤Ç¼¨¤µ¤ì¤ë¥Æ¡¼¥Ö¥ë¤òÂоݤȤ·¤ÆÆ°ºî¤¹¤ë¡£
159 ¤ò½é¤á¤Æ¸Æ¤Ó½Ð¤¹Á°¤Ë 0 ¤ÇËä¤á¤Æ¤ª¤«¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
163 .\"O frees the memory occupied by the hash table that was created by
167 .\"O a new hash table can be created using
170 .\"O .BR hdestroy_r ()
171 .\"O function performs the analogous task for a hash table described by
173 .\"O which was previously created using
174 .\"O .BR hcreate_r ().
178 ¤ÇºîÀ®¤µ¤ì¤¿¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤¬Àêͤ·¤Æ¤¤¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë¡£
179 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Ë¤è¤Ã¤ÆÀêͤµ¤ì¤Æ¤¤¤¿¥á¥â¥ê¤ò²òÊü¤·¡¢
180 ¿·¤·¤¤¥Æ¡¼¥Ö¥ë¤òºîÀ®¤Ç¤¤ë¤è¤¦¤Ë¤¹¤ë¡£
182 ¤ò¸Æ¤Ó½Ð¤¹¤È¡¢¤½¤Î¸å¤Ï
184 ¤ò»È¤Ã¤Æ¿·¤·¤¤¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤òºîÀ®¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
186 ´Ø¿ô¤Ï¡¢Æ±ÍͤνèÍý¤ò¡¢¤½¤ì°ÊÁ°¤Ë
190 ¤Ç¼¨¤µ¤ì¤ë¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ËÂФ·¤Æ¼Â¹Ô¤¹¤ë¡£
194 .\"O function searches the hash table for an
195 .\"O item with the same key as \fIitem\fP (where "the same" is determined using
196 .\"O .BR strcmp (3)),
197 .\"O and if successful returns a pointer to it.
199 ´Ø¿ô¤Ï¡¢\fIitem\fP ¤ÈƱ¤¸¥¡¼¤ò»ý¤Ä¹àÌܤò¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤«¤é
200 ¸¡º÷¤·¡¢¹àÌܤ¬¸«¤Ä¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¤½¤Î¹àÌܤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹
205 .\"O The argument \fIitem\fP is of type \fIENTRY\fP, which is defined in
206 .\"O \fI<search.h>\fP as follows:
207 °ú¤¿ô \fIitem\fP ¤Ï \fBENTRY\fP ·¿¤Ç¤¢¤ê¡¢\fI<search.h>\fP ¤ÎÃæ¤Ç
208 °Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
212 typedef struct entry {
219 .\"O The field \fIkey\fP points to a null-terminated string which is the
221 .\"O The field \fIdata\fP points to data that is associated with that key.
222 ¥Õ¥£¡¼¥ë¥É \fIkey\fP ¤Ï¸¡º÷¥¡¼¤È¤Ê¤ë NULL ½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤ò»Ø¤¹¡£
223 ¥Õ¥£¡¼¥ë¥É \fIdata\fP ¤Ï¡¢¤³¤Î¥¡¼¤ËÂбþ¤¹¤ë¥Ç¡¼¥¿¤ò»Ø¤¹¡£
225 .\"O The argument \fIaction\fP determines what
227 .\"O does after an unsuccessful search.
228 ¸¡º÷¤¬¼ºÇÔ¤·¤¿¸å¤ÎÆ°ºî¤Ï¡¢°ú¤¿ô \fIaction\fP ¤Ë¤è¤ê·è¤Þ¤ë¡£
229 .\"O This argument must either have the value
231 .\"O meaning insert a copy of
233 .\"O (and return a pointer to the new hash table entry as the function result),
236 .\"O meaning that NULL should be returned.
248 ¤Î¤¤¤º¤ì¤«¤ÎÃͤò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
252 ¤Î¥³¥Ô¡¼¤òÁÞÆþ¤¹¤ë¤³¤È¤ò
253 (´Ø¿ô¤Î·ë²Ì¤È¤·¤Æ¿·¤·¤¤¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¥¨¥ó¥È¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹)¡¢
255 ¤Ï NULL ¤òÊÖ¤¹¤³¤È¤ò°ÕÌ£¤¹¤ë
264 .\"O .BR hsearch_r ()
265 .\"O function is like
267 .\"O but operates on the hash table described by
270 .\"O .BR hsearch_r ()
271 .\"O function differs from
273 .\"O in that a pointer to the found item is returned in
275 .\"O rather than as the function result.
281 ¤Ç¼¨¤µ¤ì¤ë¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ËÂФ·¤Æ½èÍý¤ò¹Ô¤¦¡£
285 ¤È°Û¤Ê¤ë¤Î¤Ï¡¢¸«¤Ä¤«¤Ã¤¿¹àÌܤؤΥݥ¤¥ó¥¿¤ò¡¢
286 ´Ø¿ô¤Î·ë²Ì¤È¤·¤Æ¤Ç¤Ï¤Ê¤¯¡¢
288 ¤Ë³ÊǼ¤·¤ÆÊÖ¤¹ÅÀ¤Ç¤¢¤ë¡£
289 .\"O .SH "RETURN VALUE"
293 .\"O .BR hcreate_r ()
294 .\"O return nonzero on success.
295 .\"O They return 0 on error.
299 ¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç 0 °Ê³°¤ÎÃͤòÊÖ¤·¡¢
300 ¥¨¥é¡¼¤Î¾ì¹ç 0 ¤òÊÖ¤¹¡£
304 .\"O returns a pointer to an entry in the hash table.
306 .\"O returns NULL on error, that is,
307 .\"O if \fIaction\fP is \fBENTER\fP and
308 .\"O the hash table is full, or \fIaction\fP is \fBFIND\fP and \fIitem\fP
309 .\"O cannot be found in the hash table.
312 ¤Ï¡¢¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ëÆâ¤Î¥¨¥ó¥È¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
317 \fIaction\fP ¤¬ \fBENTER\fP ¤Ç¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤¬¤¤¤Ã¤Ñ¤¤¤Î¾ì¹ç¤«¡¢
318 \fIaction\fP ¤¬ \fBFIND\fP ¤Ç \fIitem\fP ¤¬¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ëÆâ¤Ë
319 ¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ç¤¢¤ë¡£
320 .\"O .BR hsearch_r ()
321 .\"O returns nonzero on success, and 0 on error.
323 ¤Ï¡¢À®¸ù¤¹¤ë¤È 0 °Ê³°¤òÊÖ¤·¡¢¥¨¥é¡¼¤Î¾ì¹ç 0 ¤òÊÖ¤¹¡£
329 .\"O .BR hcreate_r ()
330 .\"O can fail for the following reasons:
334 ¤Ï°Ê²¼¤ÎÍýͳ¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
337 .\"O .RB ( hcreate_r ())
345 .\"O Table full with \fIaction\fP set to \fBENTER\fP.
346 \fBENTER\fP ¤ËÀßÄꤵ¤ì¤¿ \fIaction\fP ¤Ç¡¢
347 ¥Æ¡¼¥Ö¥ë¤¬¤¤¤Ã¤Ñ¤¤¤Ë¤Ê¤Ã¤¿¡£
350 .\"O The \fIaction\fP argument is \fBFIND\fP and no corresponding element
351 .\"O is found in the table.
352 \fIaction\fP °ú¤¿ô¤¬ \fBFIND\fP ¤Ç¡¢
353 ¤«¤ÄÂбþ¤¹¤ëÍ×ÁǤ¬¥Æ¡¼¥Ö¥ë¤Ë¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¡£
354 .\"O .\" hdestroy_r() can set errno to EINVAL if 'tab' is NULL.
355 .\" hdestroy_r() ¤Ï 'tab' ¤¬ NULL ¤Î¾ì¹ç errno ¤Ë EINVAL ¤òÀßÄꤹ¤ë¾ì¹ç¤¬¤¢¤ë¡£
359 .\"O .BR hsearch_r ()
360 .\"O can fail for the following reasons:
364 ¤Ï°Ê²¼¤ÎÍýͳ¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
371 .\"O was not found in the table,
372 .\"O and there was no room in the table to add a new entry.
378 ¤¬¥Æ¡¼¥Ö¥ëÆâ¤Ë¸«¤Ä¤«¤é¤º¡¢
379 ¥Æ¡¼¥Ö¥ë¤Ë¿·¤·¤¤¥¨¥ó¥È¥ê¤òÄɲ乤ë;ÃϤ¬¤Ê¤«¤Ã¤¿¡£
387 .\"O was not found in the table.
393 ¤¬¥Æ¡¼¥Ö¥ëÆâ¤Ë¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¡£
395 .\"O POSIX.1-2001 only specifies the
398 POSIX.1-2001 ¤¬µ¬Äꤷ¤Æ¤¤¤ë¤Î¤Ï¡¢¥¨¥é¡¼
401 .\"O .SH "CONFORMING TO"
408 .\"O are from SVr4, and are described in POSIX.1-2001.
413 ¤Ï SVr4 ¤«¤éƳÆþ¤µ¤ì¤¿¤â¤Î¤Ç¡¢POSIX.1-2001 ¤Ëµ½Ò¤µ¤ì¤Æ¤¤¤ë¡£
419 .\"O are GNU extensions.
424 ¤Ï GNU ¤Î³ÈÄ¥¤Ç¤¢¤ë¡£
427 .\"O Hash table implementations are usually more efficient when the
428 .\"O table contains enough free space to minimize collisions.
429 .\"O Typically, this means that
431 .\"O should be at least 25% larger than the maximum number of elements
432 .\"O that the caller expects to store in the table.
433 Ä̾¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Î¼ÂÁõ¤Ï¡¢¾×ÆͤòºÇ¾®¸Â¤Ë¤¹¤ë¤¿¤á¤Ë
434 ¥Æ¡¼¥Ö¥ë¤Ë½½Ê¬¤Ê¶õ¤Îΰ褬¤¢¤ë¾ì¹ç¤Ë¸úΨ¤¬¤è¤¯¤Ê¤ë¡£
437 ¤ò¡¢¸Æ¤Ó½Ð¤·Â¦¤¬¥Æ¡¼¥Ö¥ë¤Ë³ÊǼ¤·¤è¤¦¤È»×¤Ã¤Æ¤¤¤ë
438 ¥¨¥ó¥È¥ê¤ÎºÇÂç¿ô¤è¤ê¾¯¤Ê¤¯¤È¤â 25% ¤ÏÂ礤ÊÃͤˤ¹¤Ù¤¤Ç¤¢¤ë¡£
443 .\"O .BR hdestroy _r()
444 .\"O functions do not free the buffers pointed to by the
448 .\"O elements of the hash table entries.
449 .\"O (It can't do this because it doesn't know
450 .\"O whether these buffers were allocated dynamically.)
454 ¤Ï¡¢¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Î¥¨¥ó¥È¥ê¤ÎÍ×ÁǤǤ¢¤ë
458 ¤¬»Ø¤¹¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤·¤Ê¤¤
459 (¤³¤ì¤¬¤Ç¤¤Ê¤¤¤Î¤Ï¡¢¤³¤ì¤é¤Î¥Ð¥Ã¥Õ¥¡¤¬Æ°Åª¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¤Î¤«¤ò
460 ÃΤ뤳¤È¤¬¤Ç¤¤Ê¤¤¤«¤é¤Ç¤¢¤ë)¡£
461 .\"O If these buffers need to be freed (perhaps because the program
462 .\"O is repeatedly creating and destroying hash tables,
463 .\"O rather than creating a single table whose lifetime
464 .\"O matches that of the program),
465 .\"O then the program must maintain bookkeeping data structures that
466 .\"O allow it to free them.
467 ¤³¤ì¤é¤Î¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¡¢
468 ¥×¥í¥°¥é¥à¤Ç¤Ï¡¢¤³¤ì¤é¤Î¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤Ç¤¤ë¤è¤¦¤Ë´ÉÍýÍѤΥǡ¼¥¿¹½Â¤¤ò
469 Àߤ±¤Æ¡¢¤³¤ì¤ò´ÉÍý¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤
470 (²òÊü¤¬É¬ÍפȤʤëÍýͳ¤Ï¡¢¤¿¤¤¤Æ¤¤¤Ï¡¢¥×¥í¥°¥é¥à¼«¿È¤ÈÀ¸Â¸´ü´Ö¤¬Æ±¤¸
471 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ò°ì¤Ä¤À¤±ºîÀ®¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢¤½¤Î¥×¥í¥°¥é¥à¤Ç¤ÏÊ£¿ô¤Î
472 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ò·«¤êÊÖ¤·¤ÆºîÀ®¤·¤¿¤êÇË´þ¤·¤¿¤ê¤¹¤ë¤«¤é¤Ç¤¢¤í¤¦)¡£
475 .\"O SVr4 and POSIX.1-2001 specify that \fIaction\fP
476 .\"O is significant only for unsuccessful searches, so that an \fBENTER\fP
477 .\"O should not do anything for a successful search.
478 .\"O In libc and glibc (before version 2.3), the
479 .\"O implementation violates the specification,
480 .\"O updating the \fIdata\fP for the given \fIkey\fP in this case.
481 SVr4 ¤È POSIX.1-2001 ¤Îµ¬Äê¤Ç¤Ï¡¢
482 \fIaction\fP ¤Ï¸¡º÷¤¬¼ºÇÔ¤·¤¿¤È¤¤Ë¤À¤±°ÕÌ£¤ò»ý¤Ä¤È¤Ê¤Ã¤Æ¤¤¤ë¡£
483 ¤è¤Ã¤Æ¡¢¸¡º÷¤¬À®¸ù¤·¤¿¾ì¹ç¡¢\fIaction\fP ¤ÎÃͤ¬ \fBENTER\fP ¤Ç¤â
485 (¥Ð¡¼¥¸¥ç¥ó 2.3 ¤è¤êÁ°¤Î) libc ¤È glibc ¤Î¼ÂÁõ¤Ï¤³¤Îµ¬³Ê¤Ë°ãÈ¿¤·¤Æ¤ª¤ê¡¢
486 ¤³¤Î¾õ¶·¤Ç¡¢»ØÄꤵ¤ì¤¿ \fIkey\fP ¤ËÂбþ¤¹¤ë \fIdata\fP ¤¬¹¹¿·¤µ¤ì¤ë¡£
488 .\"O Individual hash table entries can be added, but not deleted.
489 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¥¨¥ó¥È¥ê¡¼¤ÎÄɲäϤǤ¤ë¤¬¡¢ºï½ü¤¬¤Ç¤¤Ê¤¤¡£
493 .\"O The following program inserts 24 items into a hash table, then prints
495 ¼¡¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Ë 24 ¸Ä¤Î¹àÌܤòÁÞÆþ¤·¡¢
496 ¤½¤ì¤«¤é¤½¤Î¤¦¤Á¤Î¤¤¤¯¤Ä¤«¤òɽ¼¨¤¹¤ë¡£
503 char *data[] = { "alpha", "bravo", "charlie", "delta",
504 "echo", "foxtrot", "golf", "hotel", "india", "juliet",
505 "kilo", "lima", "mike", "november", "oscar", "papa",
506 "quebec", "romeo", "sierra", "tango", "uniform",
507 "victor", "whisky", "x\-ray", "yankee", "zulu"
517 for (i = 0; i < 24; i++) {
519 .\"O /* data is just an integer, instead of a
520 .\"O pointer to something */
521 /* ¥Ç¡¼¥¿¤Ï¡¢¥Ý¥¤¥ó¥¿¤Ç¤Ï¤Ê¤¯¡¢Ã±¤Ê¤ëÀ°¿ôÃͤǤ¢¤ë¡£ */
523 ep = hsearch(e, ENTER);
524 .\"O /* there should be no failures */
525 /* ¥¨¥é¡¼¤Ïµ¯¤³¤é¤Ê¤¤¤Ï¤º¤Ç¤¢¤ë¡£ */
527 fprintf(stderr, "entry failed\\n");
532 for (i = 22; i < 26; i++) {
533 .\"O /* print two entries from the table, and
534 .\"O show that two are not in the table */
535 /* ¥Æ¡¼¥Ö¥ë¤Ë¤¢¤ë 2 ¤Ä¤Î¥¨¥ó¥È¥ê¤òɽ¼¨¤·¡¢
536 ¤¢¤È¤Î 2 ¤Ä¤¬¥Æ¡¼¥Ö¥ë¤Ë¤Ê¤¤¤³¤È¤ò¼¨¤¹¡£ */
538 ep = hsearch(e, FIND);
539 printf("%9.9s \-> %9.9s:%d\\n", e.key,
540 ep ? ep\->key : "NULL", ep ? (int)(ep\->data) : 0);
552 .BR feature_test_macros (7)