1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
.\"
.\" Copyright (c) 2009 - 2016 Natacha Porté <natacha@instinctive.eu>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd April 13, 2016
.Dt SOLDOUT_ARRAY 3
.Os
.Sh NAME
.Nm soldout_array ,
.Nm arr_adjust ,
.Nm arr_free ,
.Nm arr_grow ,
.Nm arr_init ,
.Nm arr_insert ,
.Nm arr_item ,
.Nm arr_newitem ,
.Nm arr_remove ,
.Nm arr_sorted_find ,
.Nm arr_sorted_find_i ,
.Nm parr_adjust ,
.Nm parr_free ,
.Nm parr_grow ,
.Nm parr_init ,
.Nm parr_insert ,
.Nm parr_pop ,
.Nm parr_push ,
.Nm parr_remove ,
.Nm parr_sorted_find ,
.Nm parr_sorted_find_i ,
.Nm parr_top
.Nd array handling functions for soldout
.Sh SYNOPSIS
.In array.h
.Ft int
.Fo (*array_cmp_fn)
.Fa "void *key"
.Fa "void *array_entry"
.Fc
.Ft int
.Fo arr_adjust
.Fa "struct array *arr"
.Fc
.Ft void
.Fo arr_free
.Fa "struct array *arr"
.Fc
.Ft int
.Fo arr_grow
.Fa "struct array *arr"
.Fa "int need"
.Fc
.Ft void
.Fo arr_init
.Fa "struct array *arr"
.Fa "size_t unit"
.Fc
.Ft int
.Fo arr_insert
.Fa "struct array *arr"
.Fa "int nb"
.Fa "int n"
.Fc
.Ft "void *"
.Fo arr_item
.Fa "struct array *arr"
.Fa "int no"
.Fc
.Ft int
.Fo arr_newitem
.Fa "struct array *arr"
.Fc
.Ft void
.Fo arr_remove
.Fa "struct array *arr"
.Fa "int idx"
.Fc
.Ft "void *"
.Fo arr_sorted_find
.Fa "struct array *arr"
.Fa "void *key"
.Fa "array_cmp_fn cmp"
.Fc
.Ft int
.Fo arr_sorted_find_i
.Fa "struct array *arr"
.Fa "void *key"
.Fa "array_cmp_fn cmp"
.Fc
.Ft int
.Fo parr_adjust
.Fa "struct parray *arr"
.Fc
.Ft void
.Fo parr_free
.Fa "struct parray *arr"
.Fc
.Ft int
.Fo parr_grow
.Fa "struct parray *arr"
.Fa "int need"
.Fc
.Ft void
.Fo parr_init
.Fa "struct parray *arr"
.Fc
.Ft int
.Fo parr_insert
.Fa "struct parray *parr"
.Fa "int nb"
.Fa "int n"
.Fc
.Ft "void *"
.Fo parr_pop
.Fa "struct parray *arr"
.Fc
.Ft int
.Fo parr_push
.Fa "struct parray *arr"
.Fa "void *i"
.Fc
.Ft "void *"
.Fo parr_remove
.Fa "struct parray *arr"
.Fa "int idx"
.Fc
.Ft "void *"
.Fo parr_sorted_find
.Fa "struct parray *arr"
.Fa "void *key"
.Fa "array_cmp_fn cmp"
.Fc
.Ft int
.Fo parr_sorted_find_i
.Fa "struct parray *arr"
.Fa "void *key"
.Fa "array_cmp_fn cmp"
.Fc
.Ft "void *"
.Fo parr_top
.Fa "struct parray *arr"
.Fc
.Sh DESCRIPTION
.Ss Types
.Bl -ohang
.It Vt "struct array"
generic linear array.
Consists of the following fields:
.Bl -tag -width Ds
.It Vt "void *" Va base
actual array data.
.It Vt int Va size
size of the array.
.It Vt int Va asize
allocated size.
.It Vt size_t Va unit
reallocation unit size.
.El
.It Vt "struct parray"
array of pointers.
Consists of the following fields:
.Bl -tag -width Ds
.It Vt "void **" Va item
actual parray data.
.It Vt int Va size
size of the parray.
.It Vt int Va asize
allocated size.
.El
.It Vt array_cmp_fn
comparison function for sorted arrays.
.El
.Ss Functions
.Bl -ohang
.It Fn arr_adjust
shrink the allocated memory to fit exactly the needs.
.It Fn arr_free
free the structure contents
.Pq but NOT the struct itself .
.It Fn arr_grow
increase the array size to fit the given number of elements.
.It Fn arr_init
initialize the contents of the struct.
.It Fn arr_insert
insert
.Fa nb
elements before the
.Fa n
one.
.It Fn arr_item
return a pointer to the
.Fa n
element.
.It Fn arr_newitem
return the index of a new element appended to the array
.Fa arr .
.It Fn arr_remove
remove the n-th elements of the array.
.It Fn arr_sorted_find
O(log n) search in a sorted array, returning entry.
.It Fn arr_sorted_find_i
O(log n) search in a sorted array,
returning index of the smallest element larger than the key.
.It Fn parr_adjust
shrink the allocated memory to fit exactly the needs.
.It Fn parr_free
free the structure contents
.Pq but NOT the struct itself .
.It Fn parr_grow
increase the array size to fit the given number of elements.
.It Fn parr_init
initialize the contents of the struct.
.It Fn parr_insert
insert
.Fa nb
elements before the
.Fa n
one.
.It Fn parr_pop
pop the last item of the array and return it.
.It Fn parr_push
push a pointer at the end of the array
.Pq = append .
.It Fn parr_remove
remove the
.Fa idx
element of the array and return it.
.It Fn parr_sorted_find
O(log n) search in a sorted array, returning entry.
.It Fn parr_sorted_find_i
O(log n) search in a sorted array,
returning index of the smallest element larger than the key.
.It Fn parr_top
return the top the stack
.Pq i.e. the last element of the array .
.El
.Sh RETURN VALUES
The
.Fn arr_adjust ,
.Fn arr_grow ,
.Fn arr_insert ,
.Fn parr_adjust ,
.Fn parr_grow ,
.Fn parr_insert
and
.Fn parr_push
functions return on success 1; on error - 0.
.Pp
The
.Fn arr_free ,
.Fn arr_init ,
.Fn arr_remove ,
.Fn parr_free
and
.Fn parr_init
functions do not return a value.
.Pp
The
.Fn arr_item ,
.Fn arr_sorted_find ,
.Fn parr_pop ,
.Fn parr_remove ,
.Fn parr_sorted_find
and
.Fn parr_top
functions return a pointer to the element on success; on error -
.Dv NULL .
.Pp
The
.Fn arr_newitem
function returns the index on success; on error -1.
.Pp
The
.Fn arr_sorted_find_i
and
.Fn parr_sorted_find_i
functions return an index.
.Sh SEE ALSO
.Xr soldout 3
.Sh AUTHORS
.An -nosplit
The
.Nm soldout
library
was written by
.An Natasha Qo Kerensikova Qc Porte Aq Mt natacha@instinctive.eu .
Manual page was originally written by
.An Massimo Manghi Aq Mt mxmanghi@apache.org ,
and rewritten to mdoc format by
.An Svyatoslav Mishyn Aq Mt juef@openmailbox.org .
|