SOLDOUT_ARRAY(3)
β¨ NAME β¨
okay so bestie, welcome to the array girlies support group π this whole page is about the array handling functions for soldout, and the full lineup is: soldout_array, arr_adjust, arr_free, arr_grow, arr_init, arr_insert, arr_item, arr_newitem, arr_remove, arr_sorted_find, arr_sorted_find_i, parr_adjust, parr_free, parr_grow, parr_init, parr_insert, parr_pop, parr_push, parr_remove, parr_sorted_find, parr_sorted_find_i, and parr_top. that's the whole squad, no one left behind π«Ά
π¦ SYNOPSIS π¦
#include <array.h>
int
(*array_cmp_fn)(void *key, void *array_entry);
int
arr_adjust(struct array *arr);
void
arr_free(struct array *arr);
int
arr_grow(struct array *arr, int need);
void
arr_init(struct array *arr, size_t unit);
int
arr_insert(struct array *arr, int nb, int n);
void *
arr_item(struct array *arr, int no);
int
arr_newitem(struct array *arr);
void
arr_remove(struct array *arr, int idx);
void *
arr_sorted_find(struct array *arr, void *key, array_cmp_fn cmp);
int
arr_sorted_find_i(struct array *arr, void *key, array_cmp_fn cmp);
int
parr_adjust(struct parray *arr);
void
parr_free(struct parray *arr);
int
parr_grow(struct parray *arr, int need);
void
parr_init(struct parray *arr);
int
parr_insert(struct parray *parr, int nb, int n);
void *
parr_pop(struct parray *arr);
int
parr_push(struct parray *arr, void *i);
void *
parr_remove(struct parray *arr, int idx);
void *
parr_sorted_find(struct parray *arr, void *key, array_cmp_fn cmp);
int
parr_sorted_find_i(struct parray *arr, void *key, array_cmp_fn cmp);
void *
parr_top(struct parray *arr);
πΈ DESCRIPTION πΈ
π Types π
struct arrayβ the generic linear array, the blueprint, the moment β¨ it's made up of these fields:void * baseβ the actual array data. literally the data bestie πint sizeβ size of the array.int asizeβ allocated size.size_t unitβ reallocation unit size.
struct parrayβ an array of pointers, pointer girlie energy π its fields are:void ** itemβ the actual parray data.int sizeβ size of the parray.int asizeβ allocated size.
array_cmp_fnβ comparison function for sorted arrays. iykyk π
π§ Functions π§
arr_adjust()β shrink the allocated memory so it fits exactly what you need. no extra baggage, we love a minimal queen π¦arr_free()β free the structure contents. BUT NOT the struct itself!! say it with me, NOT the struct itself π«Άarr_grow()β increase the array size so it can fit the given number of elements.arr_init()β initialize the contents of the struct.arr_insert()β insertnbelements before thenone.arr_item()β return a pointer to thenelement.arr_newitem()β return the index of a new element appended to the arrayarr.arr_remove()β remove then-th elements of the array. (yes, plural, that's what it says π)arr_sorted_find()βO(log n)search in a sorted array, returning entry. fast girlie behavior βarr_sorted_find_i()βO(log n)search in a sorted array, returning index of the smallest element larger than the key.
parr_adjust()β shrink the allocated memory to fit exactly the needs.parr_free()β free the structure contents (but NOT the struct itself!!) β same rule as above, don't get caught slippin' πparr_grow()β increase the array size to fit the given number of elements.parr_init()β initialize the contents of the struct.parr_insert()β insertnbelements before thenone.parr_pop()β pop the last item of the array and return it. bye bestie, you're free now π¦parr_push()β push a pointer at the end of the array (= append). no cap, it's literally just append πparr_remove()β remove theidxelement of the array and return it.parr_sorted_find()βO(log n)search in a sorted array, returning entry.parr_sorted_find_i()βO(log n)search in a sorted array, returning index of the smallest element larger than the key.parr_top()β return the top the stack (i.e. the last element of the array). main character of the stack fr fr π
π RETURN VALUES π
okay so here's the vibe check on what each one hands back to you:
- The
arr_adjust(),arr_grow(),arr_insert(),parr_adjust(),parr_grow(),parr_insert()andparr_push()functions return on success1; on error -0. slay or flop, no in-between β¨ - The
arr_free(),arr_init(),arr_remove(),parr_free()andparr_init()functions do not return a value. silent, mysterious, iconic π - The
arr_item(),arr_sorted_find(),parr_pop(),parr_remove(),parr_sorted_find()andparr_top()functions return a pointer to the element on success; on error -NULL. - The
arr_newitem()function returns the index on success; on error-1. - The
arr_sorted_find_i()andparr_sorted_find_i()functions return an index.
π SEE ALSO π
soldout(3)β go read the parent page bestie, it's giving lore π
π AUTHORS π
The soldout library was written by Natasha "Kerensikova" Porte <natacha@instinctive.eu>. Manual page was originally written by Massimo Manghi <mxmanghi@apache.org>, and rewritten to mdoc format by Svyatoslav Mishyn <juef@openmailbox.org>. we stan all three of them, absolute legends π
and that's the whole page babes!! this was the SOLDOUT_ARRAY(3) entry from the Library Functions Manual, courtesy of Debian, dated April 13, 2016. drink water, free your structs' contents (not the structs), and stay iconic πβ¨π
π¦ where this page comes from
- debian bookworm: libsoldout-dev 1.4-5 Β· ISC
- debian trixie: libsoldout-dev 1.4-7+b1 Β· ISC
- ubuntu jammy: libsoldout-dev 1.4-5 Β· ISC
- ubuntu noble: libsoldout-dev 1.4-5build1 Β· ISC
- ubuntu questing: libsoldout-dev 1.4-7
- ubuntu resolute: libsoldout-dev 1.4-7build1 Β· ISC
- ubuntu stonking: libsoldout-dev 1.4-7build1 Β· ISC
- Copyright (c) 2009 - 2016 Natacha PortΓ© <natacha@instinctive.eu>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms