summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorray <>2010-07-28 09:00:20 +0000
committerray <>2010-07-28 09:00:20 +0000
commitb3f615278798dc6689163d9c4243572a0011a133 (patch)
tree2c2e68e494fe2d21361d87a2c6b3067682023e45
parenta620d6c92b17bd1b2534090e02846c77d2811834 (diff)
downloadopenbsd-b3f615278798dc6689163d9c4243572a0011a133.tar.gz
openbsd-b3f615278798dc6689163d9c4243572a0011a133.tar.bz2
openbsd-b3f615278798dc6689163d9c4243572a0011a133.zip
Sync hcreate(3) with NetBSD, adding some caveats.
OK jmc
-rw-r--r--src/lib/libc/stdlib/hcreate.379
1 files changed, 67 insertions, 12 deletions
diff --git a/src/lib/libc/stdlib/hcreate.3 b/src/lib/libc/stdlib/hcreate.3
index 4ff17a087d..ea264b57c8 100644
--- a/src/lib/libc/stdlib/hcreate.3
+++ b/src/lib/libc/stdlib/hcreate.3
@@ -1,5 +1,5 @@
1.\" $OpenBSD: hcreate.3,v 1.5 2008/06/26 05:42:05 ray Exp $ 1.\" $OpenBSD: hcreate.3,v 1.6 2010/07/28 09:00:20 ray Exp $
2.\" $NetBSD: hcreate.3,v 1.6 2003/04/16 13:34:46 wiz Exp $ 2.\" $NetBSD: hcreate.3,v 1.8 2010/05/01 06:18:03 jruoho Exp $
3.\" 3.\"
4.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 4.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
5.\" All rights reserved. 5.\" All rights reserved.
@@ -28,7 +28,7 @@
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE. 29.\" POSSIBILITY OF SUCH DAMAGE.
30.\" 30.\"
31.Dd $Mdocdate: June 26 2008 $ 31.Dd $Mdocdate: July 28 2010 $
32.Dt HCREATE 3 32.Dt HCREATE 3
33.Os 33.Os
34.Sh NAME 34.Sh NAME
@@ -84,15 +84,18 @@ hash table indicating the address of an item.
84The 84The
85.Fa item 85.Fa item
86argument is of type 86argument is of type
87.Dv ENTRY , 87.Vt ENTRY ,
88a structural type which contains the following members: 88defined in the
89.In search.h
90header.
91This is a structure type that contains two pointers:
89.Pp 92.Pp
90.Bl -tag -compact -offset indent -width voidX*dataXX 93.Bl -tag -compact -offset indent -width "void *data "
91.It Fa char *key 94.It Fa char *key
92comparison key. 95comparison key
93.It Fa void *data 96.It Fa void *data
94pointer to data associated with 97pointer to data associated with
95.Fa key . 98.Fa key
96.El 99.El
97.Pp 100.Pp
98The key comparison function used by 101The key comparison function used by
@@ -103,7 +106,7 @@ is
103The 106The
104.Fa action 107.Fa action
105argument is of type 108argument is of type
106.Dv ACTION , 109.Vt ACTION ,
107an enumeration type which defines the following values: 110an enumeration type which defines the following values:
108.Bl -tag -offset indent -width ENTERXX 111.Bl -tag -offset indent -width ENTERXX
109.It Dv ENTER 112.It Dv ENTER
@@ -124,6 +127,30 @@ key must not be modified during the lifetime of the hash table.
124Search the hash table without inserting 127Search the hash table without inserting
125.Fa item . 128.Fa item .
126.El 129.El
130.Pp
131Note that the comparison
132.Fa key
133must be allocated using
134.Xr malloc 3
135or
136.Xr calloc 3
137if action is
138.Dv ENTER
139and
140.Fn hdestroy
141will be called.
142This is because
143.Fn hdestroy
144will call
145.Xr free 3
146for each comparison
147.Fa key
148(but not
149.Fa data ) .
150Typically the comparison
151.Fa key
152is allocated by using
153.Xr strdup 3 .
127.Sh RETURN VALUES 154.Sh RETURN VALUES
128If successful, the 155If successful, the
129.Fn hcreate 156.Fn hcreate
@@ -170,8 +197,13 @@ Insufficient memory is available.
170.Xr malloc 3 , 197.Xr malloc 3 ,
171.Xr strcmp 3 198.Xr strcmp 3
172.Sh STANDARDS 199.Sh STANDARDS
173These functions conform to 200The
174.St -p1003.1-2004 . 201.Fn hcreate ,
202.Fn hdestroy
203and
204.Fn hsearch
205functions conform to
206.St -xpg4.2 .
175.Sh HISTORY 207.Sh HISTORY
176The 208The
177.Fn hcreate , 209.Fn hcreate ,
@@ -180,5 +212,28 @@ and
180.Fn hsearch 212.Fn hsearch
181functions first appeared in 213functions first appeared in
182.At V . 214.At V .
183.Sh BUGS 215.Sh CAVEATS
216At least the following limitations can be mentioned:
217.Bl -bullet
218.It
184The interface permits the use of only one hash table at a time. 219The interface permits the use of only one hash table at a time.
220.It
221Individual hash table entries can be added, but not deleted.
222.It
223The standard is indecipherable about the
224internal memory usage of the functions,
225mentioning only that
226.Do
227.Fn hcreate
228and
229.Fn hsearch
230functions may use
231.Fn malloc
232to allocate space
233.Dc .
234This limits the portability of the functions,
235given that other implementations may not
236.Xr free 3
237the buffer pointed by
238.Fa key .
239.El