diff options
Diffstat (limited to 'src/lib/libc/stdlib')
| -rw-r--r-- | src/lib/libc/stdlib/hcreate.3 | 79 |
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. | |||
| 84 | The | 84 | The |
| 85 | .Fa item | 85 | .Fa item |
| 86 | argument is of type | 86 | argument is of type |
| 87 | .Dv ENTRY , | 87 | .Vt ENTRY , |
| 88 | a structural type which contains the following members: | 88 | defined in the |
| 89 | .In search.h | ||
| 90 | header. | ||
| 91 | This 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 |
| 92 | comparison key. | 95 | comparison key |
| 93 | .It Fa void *data | 96 | .It Fa void *data |
| 94 | pointer to data associated with | 97 | pointer to data associated with |
| 95 | .Fa key . | 98 | .Fa key |
| 96 | .El | 99 | .El |
| 97 | .Pp | 100 | .Pp |
| 98 | The key comparison function used by | 101 | The key comparison function used by |
| @@ -103,7 +106,7 @@ is | |||
| 103 | The | 106 | The |
| 104 | .Fa action | 107 | .Fa action |
| 105 | argument is of type | 108 | argument is of type |
| 106 | .Dv ACTION , | 109 | .Vt ACTION , |
| 107 | an enumeration type which defines the following values: | 110 | an 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. | |||
| 124 | Search the hash table without inserting | 127 | Search the hash table without inserting |
| 125 | .Fa item . | 128 | .Fa item . |
| 126 | .El | 129 | .El |
| 130 | .Pp | ||
| 131 | Note that the comparison | ||
| 132 | .Fa key | ||
| 133 | must be allocated using | ||
| 134 | .Xr malloc 3 | ||
| 135 | or | ||
| 136 | .Xr calloc 3 | ||
| 137 | if action is | ||
| 138 | .Dv ENTER | ||
| 139 | and | ||
| 140 | .Fn hdestroy | ||
| 141 | will be called. | ||
| 142 | This is because | ||
| 143 | .Fn hdestroy | ||
| 144 | will call | ||
| 145 | .Xr free 3 | ||
| 146 | for each comparison | ||
| 147 | .Fa key | ||
| 148 | (but not | ||
| 149 | .Fa data ) . | ||
| 150 | Typically the comparison | ||
| 151 | .Fa key | ||
| 152 | is allocated by using | ||
| 153 | .Xr strdup 3 . | ||
| 127 | .Sh RETURN VALUES | 154 | .Sh RETURN VALUES |
| 128 | If successful, the | 155 | If 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 |
| 173 | These functions conform to | 200 | The |
| 174 | .St -p1003.1-2004 . | 201 | .Fn hcreate , |
| 202 | .Fn hdestroy | ||
| 203 | and | ||
| 204 | .Fn hsearch | ||
| 205 | functions conform to | ||
| 206 | .St -xpg4.2 . | ||
| 175 | .Sh HISTORY | 207 | .Sh HISTORY |
| 176 | The | 208 | The |
| 177 | .Fn hcreate , | 209 | .Fn hcreate , |
| @@ -180,5 +212,28 @@ and | |||
| 180 | .Fn hsearch | 212 | .Fn hsearch |
| 181 | functions first appeared in | 213 | functions first appeared in |
| 182 | .At V . | 214 | .At V . |
| 183 | .Sh BUGS | 215 | .Sh CAVEATS |
| 216 | At least the following limitations can be mentioned: | ||
| 217 | .Bl -bullet | ||
| 218 | .It | ||
| 184 | The interface permits the use of only one hash table at a time. | 219 | The interface permits the use of only one hash table at a time. |
| 220 | .It | ||
| 221 | Individual hash table entries can be added, but not deleted. | ||
| 222 | .It | ||
| 223 | The standard is indecipherable about the | ||
| 224 | internal memory usage of the functions, | ||
| 225 | mentioning only that | ||
| 226 | .Do | ||
| 227 | .Fn hcreate | ||
| 228 | and | ||
| 229 | .Fn hsearch | ||
| 230 | functions may use | ||
| 231 | .Fn malloc | ||
| 232 | to allocate space | ||
| 233 | .Dc . | ||
| 234 | This limits the portability of the functions, | ||
| 235 | given that other implementations may not | ||
| 236 | .Xr free 3 | ||
| 237 | the buffer pointed by | ||
| 238 | .Fa key . | ||
| 239 | .El | ||
