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 2011-09-10 "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 .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
72 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) »²¾È */"
74 .B #include <search.h>
76 .BI "int hcreate_r(size_t " nel ", struct hsearch_data *" htab );
78 .BI "int hsearch_r(ENTRY " item ", ACTION " action ", ENTRY **" retval ,
79 .BI " struct hsearch_data *" htab );
81 .BI "void hdestroy_r(struct hsearch_data *" htab );
85 .\"O The three functions
90 .\"O allow the caller to create and manage a hash search table
91 .\"O containing entries consisting of a key (a string) and associated data.
92 .\"O Using these functions, only one hash table can be used at a time.
96 ¤Î 3 ¤Ä¤Î´Ø¿ô¤òÍøÍѤ¹¤ë¤È¡¢¥¡¼ (ʸ»úÎó) ¤ÈÂбþ¤¹¤ë¥Ç¡¼¥¿¤«¤é¹½À®¤µ¤ì¤ë
97 ¥¨¥ó¥È¥ê¤ò³ÊǼ¤Ç¤¤ë¥Ï¥Ã¥·¥å¸¡º÷¥Æ¡¼¥Ö¥ë¤òºîÀ®¡¢´ÉÍý¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
98 ¤³¤ì¤é¤Î´Ø¿ô¤ò»È¤Ã¤Æ¡¢°ìÅ٤˻ÈÍѤǤ¤ë¤Î¤Ï°ì¤Ä¤Î¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤À¤±¤Ç¤¢¤ë¡£
100 .\"O The three functions
101 .\"O .BR hcreate_r (),
102 .\"O .BR hsearch_r (),
103 .\"O .BR hdestroy_r ()
104 .\"O are reentrant versions that allow a program to use
105 .\"O more than one hash search table at the same time.
106 .\"O The last argument,
108 .\"O points to a structure that describes the table
109 .\"O on which the function is to operate.
110 .\"O The programmer should treat this structure as opaque
111 .\"O (i.e., do not attempt to directly access or modify
112 .\"O the fields in this structure).
116 ¤Î 3 ¤Ä¤Î´Ø¿ô¤Ï¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤǡ¢¤³¤ì¤é¤òÍøÍѤ¹¤ë¤È¡¢
117 °ì¤Ä¤Î¥×¥í¥°¥é¥à¤ÇƱ»þ¤ËÊ£¿ô¤Î¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ò»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
120 ¤Ï´Ø¿ô¤ÎÁàºîÂоݤȤʤë¥Æ¡¼¥Ö¥ë¤ò¼¨¤¹¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
121 ¥×¥í¥°¥é¥Þ¤Ï¤³¤Î¹½Â¤ÂΤò¥Ö¥é¥Ã¥¯¥Ü¥Ã¥¯¥¹¤È¤·¤Æ°·¤¦¤Ù¤¤Ç¤¢¤ë
122 (¤Ä¤Þ¤ê¡¢¤³¤Î¹½Â¤ÂΤΥե£¡¼¥ë¥É¤ËľÀÜ¥¢¥¯¥»¥¹¤·¤¿¤êÊѹ¹¤·¤¿¤ê
125 .\"O First a hash table must be created using
127 .\"O The argument \fInel\fP specifies the maximum number of entries
129 .\"O (This maximum cannot be changed later, so choose it wisely.)
130 .\"O The implementation may adjust this value upward to improve the
131 .\"O performance of the resulting hash table.
134 ´Ø¿ô¤Ë¤è¤Ã¤Æ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤òºîÀ®¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
135 °ú¤¿ô \fInel\fP ¤Ç¥Æ¡¼¥Ö¥ë¤ÎºÇÂ票¥ó¥È¥ê¿ô¤ò»ØÄꤹ¤ë
136 (¤³¤ÎºÇÂçÃͤϸå¤ÇÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¤Î¤Ç¡¢¤è¤¯¹Í¤¨¤ÆÁªÂò¤¹¤ë¤³¤È)¡£
137 ºîÀ®¤µ¤ì¤ë¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ÎÀǽ¤ò¸þ¾å¤µ¤»¤ë¤¿¤á¤Ë¡¢
138 ´Ø¿ôÆâÉô¤Î¼ÂÁõ¤Ë¤è¤ê¤³¤ÎÃͤÏÁý¤ä¤µ¤ì¤ë¾ì¹ç¤â¤¢¤ë¡£
139 .\" e.g., in glibc it is raised to the next higher prime number
142 .\"O .BR hcreate_r ()
143 .\"O function performs the same task as
145 .\"O but for the table described by the structure
147 .\"O The structure pointed to by
149 .\"O must be zeroed before the first call to
150 .\"O .BR hcreate_r ().
154 ¤ÈƱ¤¸Æ°ºî¤ò¤¹¤ë¤¬¡¢¹½Â¤ÂÎ
156 ¤Ç¼¨¤µ¤ì¤ë¥Æ¡¼¥Ö¥ë¤òÂоݤȤ·¤ÆÆ°ºî¤¹¤ë¡£
160 ¤ò½é¤á¤Æ¸Æ¤Ó½Ð¤¹Á°¤Ë 0 ¤ÇËä¤á¤Æ¤ª¤«¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
164 .\"O frees the memory occupied by the hash table that was created by
168 .\"O a new hash table can be created using
171 .\"O .BR hdestroy_r ()
172 .\"O function performs the analogous task for a hash table described by
174 .\"O which was previously created using
175 .\"O .BR hcreate_r ().
179 ¤ÇºîÀ®¤µ¤ì¤¿¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤¬Àêͤ·¤Æ¤¤¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë¡£
180 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Ë¤è¤Ã¤ÆÀêͤµ¤ì¤Æ¤¤¤¿¥á¥â¥ê¤ò²òÊü¤·¡¢
181 ¿·¤·¤¤¥Æ¡¼¥Ö¥ë¤òºîÀ®¤Ç¤¤ë¤è¤¦¤Ë¤¹¤ë¡£
183 ¤ò¸Æ¤Ó½Ð¤¹¤È¡¢¤½¤Î¸å¤Ï
185 ¤ò»È¤Ã¤Æ¿·¤·¤¤¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤òºîÀ®¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
187 ´Ø¿ô¤Ï¡¢Æ±ÍͤνèÍý¤ò¡¢¤½¤ì°ÊÁ°¤Ë
191 ¤Ç¼¨¤µ¤ì¤ë¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ËÂФ·¤Æ¼Â¹Ô¤¹¤ë¡£
195 .\"O function searches the hash table for an
196 .\"O item with the same key as \fIitem\fP (where "the same" is determined using
197 .\"O .BR strcmp (3)),
198 .\"O and if successful returns a pointer to it.
200 ´Ø¿ô¤Ï¡¢\fIitem\fP ¤ÈƱ¤¸¥¡¼¤ò»ý¤Ä¹àÌܤò¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤«¤é
201 ¸¡º÷¤·¡¢¹àÌܤ¬¸«¤Ä¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¤½¤Î¹àÌܤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹
206 .\"O The argument \fIitem\fP is of type \fIENTRY\fP, which is defined in
207 .\"O \fI<search.h>\fP as follows:
208 °ú¤¿ô \fIitem\fP ¤Ï \fBENTRY\fP ·¿¤Ç¤¢¤ê¡¢\fI<search.h>\fP ¤ÎÃæ¤Ç
209 °Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
213 typedef struct entry {
220 .\"O The field \fIkey\fP points to a null-terminated string which is the
222 .\"O The field \fIdata\fP points to data that is associated with that key.
223 ¥Õ¥£¡¼¥ë¥É \fIkey\fP ¤Ï¸¡º÷¥¡¼¤È¤Ê¤ë NULL ½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤ò»Ø¤¹¡£
224 ¥Õ¥£¡¼¥ë¥É \fIdata\fP ¤Ï¡¢¤³¤Î¥¡¼¤ËÂбþ¤¹¤ë¥Ç¡¼¥¿¤ò»Ø¤¹¡£
226 .\"O The argument \fIaction\fP determines what
228 .\"O does after an unsuccessful search.
229 ¸¡º÷¤¬¼ºÇÔ¤·¤¿¸å¤ÎÆ°ºî¤Ï¡¢°ú¤¿ô \fIaction\fP ¤Ë¤è¤ê·è¤Þ¤ë¡£
230 .\"O This argument must either have the value
232 .\"O meaning insert a copy of
234 .\"O (and return a pointer to the new hash table entry as the function result),
237 .\"O meaning that NULL should be returned.
249 ¤Î¤¤¤º¤ì¤«¤ÎÃͤò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
253 ¤Î¥³¥Ô¡¼¤òÁÞÆþ¤¹¤ë¤³¤È¤ò
254 (´Ø¿ô¤Î·ë²Ì¤È¤·¤Æ¿·¤·¤¤¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¥¨¥ó¥È¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹)¡¢
256 ¤Ï NULL ¤òÊÖ¤¹¤³¤È¤ò°ÕÌ£¤¹¤ë
265 .\"O .BR hsearch_r ()
266 .\"O function is like
268 .\"O but operates on the hash table described by
271 .\"O .BR hsearch_r ()
272 .\"O function differs from
274 .\"O in that a pointer to the found item is returned in
276 .\"O rather than as the function result.
282 ¤Ç¼¨¤µ¤ì¤ë¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ËÂФ·¤Æ½èÍý¤ò¹Ô¤¦¡£
286 ¤È°Û¤Ê¤ë¤Î¤Ï¡¢¸«¤Ä¤«¤Ã¤¿¹àÌܤؤΥݥ¤¥ó¥¿¤ò¡¢
287 ´Ø¿ô¤Î·ë²Ì¤È¤·¤Æ¤Ç¤Ï¤Ê¤¯¡¢
289 ¤Ë³ÊǼ¤·¤ÆÊÖ¤¹ÅÀ¤Ç¤¢¤ë¡£
290 .\"O .SH "RETURN VALUE"
294 .\"O .BR hcreate_r ()
295 .\"O return nonzero on success.
296 .\"O They return 0 on error.
300 ¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç 0 °Ê³°¤ÎÃͤòÊÖ¤·¡¢
301 ¥¨¥é¡¼¤Î¾ì¹ç 0 ¤òÊÖ¤¹¡£
305 .\"O returns a pointer to an entry in the hash table.
307 .\"O returns NULL on error, that is,
308 .\"O if \fIaction\fP is \fBENTER\fP and
309 .\"O the hash table is full, or \fIaction\fP is \fBFIND\fP and \fIitem\fP
310 .\"O cannot be found in the hash table.
313 ¤Ï¡¢¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ëÆâ¤Î¥¨¥ó¥È¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
318 \fIaction\fP ¤¬ \fBENTER\fP ¤Ç¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤¬¤¤¤Ã¤Ñ¤¤¤Î¾ì¹ç¤«¡¢
319 \fIaction\fP ¤¬ \fBFIND\fP ¤Ç \fIitem\fP ¤¬¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ëÆâ¤Ë
320 ¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ç¤¢¤ë¡£
321 .\"O .BR hsearch_r ()
322 .\"O returns nonzero on success, and 0 on error.
324 ¤Ï¡¢À®¸ù¤¹¤ë¤È 0 °Ê³°¤òÊÖ¤·¡¢¥¨¥é¡¼¤Î¾ì¹ç 0 ¤òÊÖ¤¹¡£
328 .\"O .BR hcreate_r ()
330 .\"O .BR hdestroy_r ()
331 .\"O can fail for the following reasons:
335 ¤Ï°Ê²¼¤ÎÍýͳ¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
345 .\"O .BR hsearch_r ()
346 .\"O can fail for the following reasons:
350 ¤Ï°Ê²¼¤ÎÍýͳ¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
357 .\"O was not found in the table,
358 .\"O and there was no room in the table to add a new entry.
364 ¤¬¥Æ¡¼¥Ö¥ëÆâ¤Ë¸«¤Ä¤«¤é¤º¡¢
365 ¥Æ¡¼¥Ö¥ë¤Ë¿·¤·¤¤¥¨¥ó¥È¥ê¤òÄɲ乤ë;ÃϤ¬¤Ê¤«¤Ã¤¿¡£
373 .\"O was not found in the table.
379 ¤¬¥Æ¡¼¥Ö¥ëÆâ¤Ë¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¡£
381 .\"O POSIX.1-2001 only specifies the
384 POSIX.1-2001 ¤¬µ¬Äꤷ¤Æ¤¤¤ë¤Î¤Ï¡¢¥¨¥é¡¼
387 .\"O .SH "CONFORMING TO"
394 .\"O are from SVr4, and are described in POSIX.1-2001.
399 ¤Ï SVr4 ¤«¤éƳÆþ¤µ¤ì¤¿¤â¤Î¤Ç¡¢POSIX.1-2001 ¤Ëµ½Ò¤µ¤ì¤Æ¤¤¤ë¡£
405 .\"O are GNU extensions.
410 ¤Ï GNU ¤Î³ÈÄ¥¤Ç¤¢¤ë¡£
413 .\"O Hash table implementations are usually more efficient when the
414 .\"O table contains enough free space to minimize collisions.
415 .\"O Typically, this means that
417 .\"O should be at least 25% larger than the maximum number of elements
418 .\"O that the caller expects to store in the table.
419 Ä̾¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Î¼ÂÁõ¤Ï¡¢¾×ÆͤòºÇ¾®¸Â¤Ë¤¹¤ë¤¿¤á¤Ë
420 ¥Æ¡¼¥Ö¥ë¤Ë½½Ê¬¤Ê¶õ¤Îΰ褬¤¢¤ë¾ì¹ç¤Ë¸úΨ¤¬¤è¤¯¤Ê¤ë¡£
423 ¤ò¡¢¸Æ¤Ó½Ð¤·Â¦¤¬¥Æ¡¼¥Ö¥ë¤Ë³ÊǼ¤·¤è¤¦¤È»×¤Ã¤Æ¤¤¤ë
424 ¥¨¥ó¥È¥ê¤ÎºÇÂç¿ô¤è¤ê¾¯¤Ê¤¯¤È¤â 25% ¤ÏÂ礤ÊÃͤˤ¹¤Ù¤¤Ç¤¢¤ë¡£
429 .\"O .BR hdestroy_r ()
430 .\"O functions do not free the buffers pointed to by the
434 .\"O elements of the hash table entries.
435 .\"O (It can't do this because it doesn't know
436 .\"O whether these buffers were allocated dynamically.)
440 ¤Ï¡¢¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Î¥¨¥ó¥È¥ê¤ÎÍ×ÁǤǤ¢¤ë
444 ¤¬»Ø¤¹¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤·¤Ê¤¤
445 (¤³¤ì¤¬¤Ç¤¤Ê¤¤¤Î¤Ï¡¢¤³¤ì¤é¤Î¥Ð¥Ã¥Õ¥¡¤¬Æ°Åª¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¤Î¤«¤ò
446 ÃΤ뤳¤È¤¬¤Ç¤¤Ê¤¤¤«¤é¤Ç¤¢¤ë)¡£
447 .\"O If these buffers need to be freed (perhaps because the program
448 .\"O is repeatedly creating and destroying hash tables,
449 .\"O rather than creating a single table whose lifetime
450 .\"O matches that of the program),
451 .\"O then the program must maintain bookkeeping data structures that
452 .\"O allow it to free them.
453 ¤³¤ì¤é¤Î¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¡¢
454 ¥×¥í¥°¥é¥à¤Ç¤Ï¡¢¤³¤ì¤é¤Î¥Ð¥Ã¥Õ¥¡¤ò²òÊü¤Ç¤¤ë¤è¤¦¤Ë´ÉÍýÍѤΥǡ¼¥¿¹½Â¤¤ò
455 Àߤ±¤Æ¡¢¤³¤ì¤ò´ÉÍý¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤
456 (²òÊü¤¬É¬ÍפȤʤëÍýͳ¤Ï¡¢¤¿¤¤¤Æ¤¤¤Ï¡¢¥×¥í¥°¥é¥à¼«¿È¤ÈÀ¸Â¸´ü´Ö¤¬Æ±¤¸
457 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ò°ì¤Ä¤À¤±ºîÀ®¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢¤½¤Î¥×¥í¥°¥é¥à¤Ç¤ÏÊ£¿ô¤Î
458 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤ò·«¤êÊÖ¤·¤ÆºîÀ®¤·¤¿¤êÇË´þ¤·¤¿¤ê¤¹¤ë¤«¤é¤Ç¤¢¤í¤¦)¡£
461 .\"O SVr4 and POSIX.1-2001 specify that \fIaction\fP
462 .\"O is significant only for unsuccessful searches, so that an \fBENTER\fP
463 .\"O should not do anything for a successful search.
464 .\"O In libc and glibc (before version 2.3), the
465 .\"O implementation violates the specification,
466 .\"O updating the \fIdata\fP for the given \fIkey\fP in this case.
467 SVr4 ¤È POSIX.1-2001 ¤Îµ¬Äê¤Ç¤Ï¡¢
468 \fIaction\fP ¤Ï¸¡º÷¤¬¼ºÇÔ¤·¤¿¤È¤¤Ë¤À¤±°ÕÌ£¤ò»ý¤Ä¤È¤Ê¤Ã¤Æ¤¤¤ë¡£
469 ¤è¤Ã¤Æ¡¢¸¡º÷¤¬À®¸ù¤·¤¿¾ì¹ç¡¢\fIaction\fP ¤ÎÃͤ¬ \fBENTER\fP ¤Ç¤â
471 (¥Ð¡¼¥¸¥ç¥ó 2.3 ¤è¤êÁ°¤Î) libc ¤È glibc ¤Î¼ÂÁõ¤Ï¤³¤Îµ¬³Ê¤Ë°ãÈ¿¤·¤Æ¤ª¤ê¡¢
472 ¤³¤Î¾õ¶·¤Ç¡¢»ØÄꤵ¤ì¤¿ \fIkey\fP ¤ËÂбþ¤¹¤ë \fIdata\fP ¤¬¹¹¿·¤µ¤ì¤ë¡£
474 .\"O Individual hash table entries can be added, but not deleted.
475 ¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¥¨¥ó¥È¥ê¡¼¤ÎÄɲäϤǤ¤ë¤¬¡¢ºï½ü¤¬¤Ç¤¤Ê¤¤¡£
479 .\"O The following program inserts 24 items into a hash table, then prints
481 ¼¡¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥Ï¥Ã¥·¥å¥Æ¡¼¥Ö¥ë¤Ë 24 ¸Ä¤Î¹àÌܤòÁÞÆþ¤·¡¢
482 ¤½¤ì¤«¤é¤½¤Î¤¦¤Á¤Î¤¤¤¯¤Ä¤«¤òɽ¼¨¤¹¤ë¡£
489 char *data[] = { "alpha", "bravo", "charlie", "delta",
490 "echo", "foxtrot", "golf", "hotel", "india", "juliet",
491 "kilo", "lima", "mike", "november", "oscar", "papa",
492 "quebec", "romeo", "sierra", "tango", "uniform",
493 "victor", "whisky", "x\-ray", "yankee", "zulu"
503 for (i = 0; i < 24; i++) {
505 .\"O /* data is just an integer, instead of a
506 .\"O pointer to something */
507 /* ¥Ç¡¼¥¿¤Ï¡¢¥Ý¥¤¥ó¥¿¤Ç¤Ï¤Ê¤¯¡¢Ã±¤Ê¤ëÀ°¿ôÃͤǤ¢¤ë¡£ */
509 ep = hsearch(e, ENTER);
510 .\"O /* there should be no failures */
511 /* ¥¨¥é¡¼¤Ïµ¯¤³¤é¤Ê¤¤¤Ï¤º¤Ç¤¢¤ë¡£ */
513 fprintf(stderr, "entry failed\\n");
518 for (i = 22; i < 26; i++) {
519 .\"O /* print two entries from the table, and
520 .\"O show that two are not in the table */
521 /* ¥Æ¡¼¥Ö¥ë¤Ë¤¢¤ë 2 ¤Ä¤Î¥¨¥ó¥È¥ê¤òɽ¼¨¤·¡¢
522 ¤¢¤È¤Î 2 ¤Ä¤¬¥Æ¡¼¥Ö¥ë¤Ë¤Ê¤¤¤³¤È¤ò¼¨¤¹¡£ */
524 ep = hsearch(e, FIND);
525 printf("%9.9s \-> %9.9s:%d\\n", e.key,
526 ep ? ep\->key : "NULL", ep ? (int)(ep\->data) : 0);