libwget-vector(3)
π libwget-vector β Vector functions π
okay bestie, welcome to libwget-vector, straight out of the Library Functions Manual (that's the (3) section, iykyk β library calls only, no shell commands here). This is your β¨vector eraβ¨ and honestly? it's giving growable arrays and main character energy. π¦
β¨ SYNOPSIS β¨
π Functions
here's the whole squad, fr fr β every single one of these is real, no cap:
wget_vector * wget_vector_create (int max, wget_vector_compare_fn *cmp)
void wget_vector_set_resize_factor (wget_vector *v, float factor)
int wget_vector_insert (wget_vector *v, const void *elem, int pos)
int wget_vector_insert_sorted (wget_vector *v, const void *elem)
int wget_vector_add_memdup (wget_vector *v, const void *elem, size_t size)
int wget_vector_add (wget_vector *v, const void *elem)
int wget_vector_add_vprintf (wget_vector *v, const char *fmt, va_list args)
int wget_vector_add_printf (wget_vector *v, const char *fmt,...)
int wget_vector_replace (wget_vector *v, const void *elem, int pos)
int wget_vector_remove (wget_vector *v, int pos)
int wget_vector_remove_nofree (wget_vector *v, int pos)
int wget_vector_move (wget_vector *v, int old_pos, int new_pos)
int wget_vector_swap (wget_vector *v, int pos1, int pos2)
void wget_vector_free (wget_vector **v)
void wget_vector_clear (wget_vector *v)
void wget_vector_clear_nofree (wget_vector *v)
int wget_vector_size (const wget_vector *v)
void * wget_vector_get (const wget_vector *v, int pos)
int wget_vector_browse (const wget_vector *v, wget_vector_browse_fn *browse, void *ctx)
void wget_vector_setcmpfunc (wget_vector *v, wget_vector_compare_fn *cmp)
void wget_vector_set_destructor (wget_vector *v, wget_vector_destructor *destructor)
void wget_vector_sort (wget_vector *v)
int wget_vector_find (const wget_vector *v, const void *elem)
bool wget_vector_contains (const wget_vector *v, const void *elem)
int wget_vector_findext (const wget_vector *v, int start, int direction, wget_vector_find_fn *find)
likeβ¦ look at them. twenty-five functions. every one of them a baddie in their own right. π
π Detailed Description π
Functions to realize vectors (growable arrays).
that's the whole description bestie, and honestly it ate β a vector here is just an array that grows when you need it to, so you're not out here hand-rolling realloc like it's 2009. π«Ά
and we are SO not done β more of this page is coming, so don't go anywhere. π
π¦ wget_vector_create
wget_vector * wget_vector_create (int max, wget_vector_compare_fn * cmp)
Params, bestie:
maxβ the initial number of pre-allocated entries.cmpβ comparison function for sorting / finding / sorted insertion, orNULLif that's not the vibe.
Returns: a brand-new vector instance. β¨
Makes you a new vector instance. You gotta wget_vector_free() it after use β no leaks, that's the rule. π«Ά
πΈ wget_vector_set_resize_factor
void wget_vector_set_resize_factor (wget_vector * v, float factor)
Params:
vβ the vector.factorβ the vector growth factor.
Sets the factor used for resizing the vector when it's full. The new size is factor * oldsize. If the new size is less than or equal to the old size, the insertion function involved will return an error and the vector's internal state will NOT change β so don't try it. π
Default is 2.
π
wget_vector_insert
int wget_vector_insert (wget_vector * v, const void * elem, int pos)
Params:
vβ the vector whereelemis inserted into.elemβ element to insert intov.posβ position to insertelemat.
Returns: index of the inserted element (>= 0) or WGET_E_* on error (< 0).
Inserts elem at index pos. elem is not cloned β the vector takes 'ownership' of the element. π
An error comes back if v is NULL or pos is out of range (< 0 or > # of entries).
π wget_vector_insert_sorted
int wget_vector_insert_sorted (wget_vector * v, const void * elem)
Params:
vβ the vector whereelemis inserted into.elemβ element to insert intov.
Returns: index of the inserted element (>= 0) or WGET_E_* on error (< 0).
Inserts elem at a position that keeps the sort order intact. If the vector has no comparison function, elem gets inserted as the last element. And if the elements already in there aren't sorted? They'll get sorted after this function returns. Periodt. β¨
elem is not cloned β the vector takes 'ownership' of the element.
An error comes back if v is NULL.
π wget_vector_add_memdup
int wget_vector_add_memdup (wget_vector * v, const void * elem, size_t size)
Params:
vβ the vector whereelemis appended to.elemβ element to append tov.sizeβ size ofelem.
Returns: index of the inserted element (>= 0) or WGET_E_* on error (< 0).
Appends elem of the given size to vector v. elem is cloned / copied (shallow). π―ββοΈ
An error comes back if v is NULL.
π§ wget_vector_add
int wget_vector_add (wget_vector * v, const void * elem)
Params:
vβ the vector whereelemis appended to.elemβ element to append tov.
Returns: index of the inserted element (>= 0) or WGET_E_* on error (< 0).
Appends elem to vector v. elem is not cloned β the vector takes 'ownership' of the element. π
An error comes back if v is NULL.
π wget_vector_add_vprintf
int wget_vector_add_vprintf (wget_vector * v, const char * fmt, va_list args)
Params:
vβ the vector wheresis appended to.fmtβ printf-like format string.argsβ arguments for thefmt.
Returns: index of the appended element (>= 0) or WGET_E_* on error (< 0).
Builds a string in a printf-like manner and appends it as an element to vector v. π«
An error comes back if v or fmt is NULL.
β wget_vector_add_printf
int wget_vector_add_printf (wget_vector * v, const char * fmt, ...)
Params:
vβ the vector wheresis appended to.fmtβ printf-like format string....β arguments for thefmt.
Returns: index of the appended element (>= 0) or WGET_E_* on error (< 0).
Builds a string in a printf-like manner and appends it as an element to vector v. π«
An error comes back if v or fmt is NULL.
π wget_vector_replace
int wget_vector_replace (wget_vector * v, const void * elem, int pos)
Params:
vβ the vector whereelemis inserted.elemβ element to insert intov.posβ position to insertelemat.
Returns: index of the inserted element (same as pos) (>= 0) or WGET_E_* on error (< 0).
Replaces the element at position pos with elem. If the vector has an element destructor function, it gets called. The old element is free'd. ποΈ
elem is not cloned β the vector takes 'ownership' of the element.
An error comes back if v is NULL or pos is out of range (< 0 or > # of entries).
π wget_vector_remove
int wget_vector_remove (wget_vector * v, int pos)
Params:
vβ the vector to remove an element from.posβ position of element to remove.
Returns: index of the appended element (>= 0) or WGET_E_* on error (< 0).
Removes the element at position pos. If the vector has an element destructor function, it gets called. The element is free'd. ποΈ
An error comes back if v is NULL or pos is out of range (< 0 or > # of entries).
π¦ wget_vector_remove_nofree
int wget_vector_remove_nofree (wget_vector * v, int pos)
Params:
vβ the vector to remove an element from.posβ position of element to remove.
Returns: index of the removed element (same as pos) (>= 0) or WGET_E_* on error (< 0).
Removes the element at position pos. No element destructor function is called, and the element is NOT free'd β that's on you now. π
An error comes back if v is NULL or pos is out of range (< 0 or > # of entries).
π wget_vector_move
int wget_vector_move (wget_vector * v, int old_pos, int new_pos)
Params:
vβ the vector to act on.old_posβ position to move element from.new_posβ position to move element to.
Returns: index of the new position (same as new_pos) (>= 0) or WGET_E_* on error (< 0).
Moves the element at position old_pos to new_pos. Other elements may change position too β it's giving shuffle. π
An error comes back if v is NULL or either old_pos or new_pos is out of range (< 0 or > # of entries).
β¨ wget_vector_swap
int wget_vector_swap (wget_vector * v, int pos1, int pos2)
Params:
vβ the vector to act on.pos1β position of element one.pos2β position of element two.
Returns: index of the second position (same as pos2) (>= 0) or WGET_E_* on error (< 0).
Swaps the two elements at position pos1 and pos2. Trading places, iconic. π
An error comes back if v is NULL or either pos1 or pos2 is out of range (< 0 or > # of entries).
π§ wget_vector_free
void wget_vector_free (wget_vector ** v)
Params:
vβ the vector to be free'd.
Frees the vector v and its contents. For each element the destructor function gets called and the element free'd after that. Then the vector itself is free'd and set to NULL. Cleanup queen. π§Ήπ
πΈ wget_vector_clear
void wget_vector_clear (wget_vector * v)
Params:
vβ the vector to be cleared.
Frees all elements of the vector v β but not the vector itself. For each element the destructor function gets called and the element free'd after that. The vector is then empty and ready to be reused. β»οΈ
π wget_vector_clear_nofree
void wget_vector_clear_nofree (wget_vector * v)
Params:
vβ the vector to be cleared.
Removes all elements of the vector v without free'ing them. The caller is responsible for taking care of the elements. π The vector is then empty and ready to be reused. β»οΈ
π
wget_vector_size
int wget_vector_size (const wget_vector * v)
Params:
vβ the vector.
Returns: the number of elements in the vector v.
Retrieves the number of elements of the vector v. If v is NULL, 0 is returned. π«Ά
π wget_vector_get
void * wget_vector_get (const wget_vector * v, int pos)
Params:
vβ the vector.posβ position of element to retrieve.
Returns: the element at position pos, or NULL on error.
Retrieves the element at position pos. NULL comes back if v is NULL or pos is out of range (< 0 or > # of entries).
π wget_vector_browse
int wget_vector_browse (const wget_vector * v, wget_vector_browse_fn * browse, void * ctx)
Params:
vβ the vector.browseβ function to be called for each element ofv.ctxβ context variable used as param tobrowse.
Returns: the return value of the last call to browse.
Calls function browse for each element of vector v, or until browse returns a value not equal to zero. browse is called with ctx and the pointer to the current element. The return value of the last call to browse is returned, or 0 if v is NULL. π‘
β wget_vector_setcmpfunc
void wget_vector_setcmpfunc (wget_vector * v, wget_vector_compare_fn * cmp)
Params:
vβ the vector.cmpβ function to compare elements.
Sets the compare function used by wget_vector_sort(). π
π wget_vector_set_destructor
void wget_vector_set_destructor (wget_vector * v, wget_vector_destructor * destructor)
Params:
vβ the vector.destructorβ function to be called for element destruction.
Sets the destructor function that's called for each element to be removed. Heads up: it should NOT free the element (pointer) itself. π«ποΈ
π¦ wget_vector_sort
void wget_vector_sort (wget_vector * v)
Params:
vβ the vector.
Sorts the elements in vector v using the compare function. Does nothing if v is NULL or the compare function isn't set. π’
β¨ wget_vector_find
int wget_vector_find (const wget_vector * v, const void * elem)
Params:
vβ the vector.elemβ element to search for.
Returns: index of the found element, WGET_E_UNKNOWN if not found, or WGET_E_INVALID if v was NULL or there was no comparison function set.
Searches for the given element using the vector's compare function. π
π wget_vector_contains
bool wget_vector_contains (const wget_vector * v, const void * elem)
Params:
vβ the vector.elemβ element to check for.
Returns: true if the element exists, else false.
Checks whether the element elem exists or not. π«Ά
πΈ wget_vector_findext
int wget_vector_findext (const wget_vector * v, int start, int direction, wget_vector_find_fn * find)
Params:
vβ the vector.startβ index to start search from.directionβ direction of search.findβ function to be called for each element.
Returns: index of the found element, WGET_E_UNKNOWN if not found, or WGET_E_INVALID if v was NULL or there was no comparison function set.
Calls find for each element starting at start. If find returns 0, the current index is returned. π§
π AUTHOR
Generated automatically by Doxygen for wget2 from the source code. (Yes, the robots wrote it, and they ate. π€π )
aaaand that's a wrap on part 2 bestie!! π this was libwget-vector(3) from wget2, Version 2.3.0 β go forth and vector responsibly, and remember: whoever you create, you also gotta free. no cap. πβ¨π¦
π¦ where this page comes from
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms