diff options
Diffstat (limited to 'src/lib/libc/stdlib/hcreate.3')
| -rw-r--r-- | src/lib/libc/stdlib/hcreate.3 | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/hcreate.3 b/src/lib/libc/stdlib/hcreate.3 new file mode 100644 index 0000000000..66b1dd126d --- /dev/null +++ b/src/lib/libc/stdlib/hcreate.3 | |||
| @@ -0,0 +1,191 @@ | |||
| 1 | .\" $OpenBSD: hcreate.3,v 1.3 2006/01/30 19:50:41 jmc Exp $ | ||
| 2 | .\" $NetBSD: hcreate.3,v 1.6 2003/04/16 13:34:46 wiz Exp $ | ||
| 3 | .\" | ||
| 4 | .\" Copyright (c) 1999 The NetBSD Foundation, Inc. | ||
| 5 | .\" All rights reserved. | ||
| 6 | .\" | ||
| 7 | .\" This code is derived from software contributed to The NetBSD Foundation | ||
| 8 | .\" by Klaus Klein. | ||
| 9 | .\" | ||
| 10 | .\" Redistribution and use in source and binary forms, with or without | ||
| 11 | .\" modification, are permitted provided that the following conditions | ||
| 12 | .\" are met: | ||
| 13 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 14 | .\" notice, this list of conditions and the following disclaimer. | ||
| 15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 17 | .\" documentation and/or other materials provided with the distribution. | ||
| 18 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 19 | .\" must display the following acknowledgement: | ||
| 20 | .\" This product includes software developed by the NetBSD | ||
| 21 | .\" Foundation, Inc. and its contributors. | ||
| 22 | .\" 4. Neither the name of The NetBSD Foundation nor the names of its | ||
| 23 | .\" contributors may be used to endorse or promote products derived | ||
| 24 | .\" from this software without specific prior written permission. | ||
| 25 | .\" | ||
| 26 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 27 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 28 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 29 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 30 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 31 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 32 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 33 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 34 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 35 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 36 | .\" POSSIBILITY OF SUCH DAMAGE. | ||
| 37 | .\" | ||
| 38 | .Dd February 13, 2001 | ||
| 39 | .Dt HCREATE 3 | ||
| 40 | .Os | ||
| 41 | .Sh NAME | ||
| 42 | .Nm hcreate , | ||
| 43 | .Nm hdestroy , | ||
| 44 | .Nm hsearch | ||
| 45 | .Nd manage hash search table | ||
| 46 | .Sh SYNOPSIS | ||
| 47 | .In search.h | ||
| 48 | .Ft int | ||
| 49 | .Fn hcreate "size_t nel" | ||
| 50 | .Ft void | ||
| 51 | .Fn hdestroy "void" | ||
| 52 | .Ft ENTRY * | ||
| 53 | .Fn hsearch "ENTRY item" "ACTION action" | ||
| 54 | .Sh DESCRIPTION | ||
| 55 | The | ||
| 56 | .Fn hcreate , | ||
| 57 | .Fn hdestroy , | ||
| 58 | and | ||
| 59 | .Fn hsearch | ||
| 60 | functions manage hash search tables. | ||
| 61 | .Pp | ||
| 62 | The | ||
| 63 | .Fn hcreate | ||
| 64 | function allocates and initializes the table. | ||
| 65 | The | ||
| 66 | .Fa nel | ||
| 67 | argument specifies an estimate of the maximum number of entries to be held | ||
| 68 | by the table. | ||
| 69 | Unless further memory allocation fails, supplying an insufficient | ||
| 70 | .Fa nel | ||
| 71 | value will not result in functional harm, although a performance degradation | ||
| 72 | may occur. | ||
| 73 | Initialization using the | ||
| 74 | .Fn hcreate | ||
| 75 | function is mandatory prior to any access operations using | ||
| 76 | .Fn hsearch . | ||
| 77 | .Pp | ||
| 78 | The | ||
| 79 | .Fn hdestroy | ||
| 80 | function destroys a table previously created using | ||
| 81 | .Fn hcreate . | ||
| 82 | After a call to | ||
| 83 | .Fn hdestroy , | ||
| 84 | the data can no longer be accessed. | ||
| 85 | .Pp | ||
| 86 | The | ||
| 87 | .Fn hsearch | ||
| 88 | function is used to search to the hash table. | ||
| 89 | It returns a pointer into the | ||
| 90 | hash table indicating the address of an item. | ||
| 91 | The | ||
| 92 | .Fa item | ||
| 93 | argument is of type | ||
| 94 | .Dv ENTRY , | ||
| 95 | a structural type which contains the following members: | ||
| 96 | .Pp | ||
| 97 | .Bl -tag -compact -offset indent -width voidX*dataXX | ||
| 98 | .It Fa char *key | ||
| 99 | comparison key. | ||
| 100 | .It Fa void *data | ||
| 101 | pointer to data associated with | ||
| 102 | .Fa key . | ||
| 103 | .El | ||
| 104 | .Pp | ||
| 105 | The key comparison function used by | ||
| 106 | .Fn hsearch | ||
| 107 | is | ||
| 108 | .Xr strcmp 3 . | ||
| 109 | .Pp | ||
| 110 | The | ||
| 111 | .Fa action | ||
| 112 | argument is of type | ||
| 113 | .Dv ACTION , | ||
| 114 | an enumeration type which defines the following values: | ||
| 115 | .Bl -tag -offset indent -width ENTERXX | ||
| 116 | .It Dv ENTER | ||
| 117 | Insert | ||
| 118 | .Fa item | ||
| 119 | into the hash table. | ||
| 120 | If an existing item with the same key is found, it is not replaced. | ||
| 121 | Note that the | ||
| 122 | .Fa key | ||
| 123 | and | ||
| 124 | .Fa data | ||
| 125 | elements of | ||
| 126 | .Fa item | ||
| 127 | are used directly by the new table entry. | ||
| 128 | The storage for the | ||
| 129 | key must not be modified during the lifetime of the hash table. | ||
| 130 | .It Dv FIND | ||
| 131 | Search the hash table without inserting | ||
| 132 | .Fa item . | ||
| 133 | .El | ||
| 134 | .Sh RETURN VALUES | ||
| 135 | If successful, the | ||
| 136 | .Fn hcreate | ||
| 137 | function returns a non-zero value. | ||
| 138 | Otherwise, a value of 0 is returned and | ||
| 139 | .Va errno | ||
| 140 | is set to indicate the error. | ||
| 141 | .Pp | ||
| 142 | The | ||
| 143 | .Fn hdestroy | ||
| 144 | functions | ||
| 145 | returns no value. | ||
| 146 | .Pp | ||
| 147 | If successful, the | ||
| 148 | .Fn hsearch | ||
| 149 | function returns a pointer to a hash table entry matching | ||
| 150 | the provided key. | ||
| 151 | If the action is | ||
| 152 | .Dv FIND | ||
| 153 | and the item was not found, or if the action is | ||
| 154 | .Dv ENTER | ||
| 155 | and the insertion failed, | ||
| 156 | .Dv NULL | ||
| 157 | is returned and | ||
| 158 | .Va errno | ||
| 159 | is set to indicate the error. | ||
| 160 | If the action is | ||
| 161 | .Dv ENTER | ||
| 162 | and an entry already existed in the table matching the given | ||
| 163 | key, the existing entry is returned and is not replaced. | ||
| 164 | .Sh ERRORS | ||
| 165 | The | ||
| 166 | .Fn hcreate | ||
| 167 | and | ||
| 168 | .Fn hsearch | ||
| 169 | functions will fail if: | ||
| 170 | .Bl -tag -width Er | ||
| 171 | .It Bq Er ENOMEM | ||
| 172 | Insufficient memory is available. | ||
| 173 | .El | ||
| 174 | .Sh SEE ALSO | ||
| 175 | .Xr bsearch 3 , | ||
| 176 | .Xr lsearch 3 , | ||
| 177 | .Xr malloc 3 , | ||
| 178 | .Xr strcmp 3 | ||
| 179 | .Sh STANDARDS | ||
| 180 | These functions conform to | ||
| 181 | .St -p1003.1-2004 . | ||
| 182 | .Sh HISTORY | ||
| 183 | The | ||
| 184 | .Fn hcreate , | ||
| 185 | .Fn hdestroy | ||
| 186 | and | ||
| 187 | .Fn hsearch | ||
| 188 | functions first appeared in | ||
| 189 | .At V . | ||
| 190 | .Sh BUGS | ||
| 191 | The interface permits the use of only one hash table at a time. | ||
