table of contents
libwget-vector(3) | wget2 | libwget-vector(3) |
NAME¶
libwget-vectorSYNOPSIS¶
Functions¶
wget_vector_t * wget_vector_create (int max, wget_vector_compare_t cmp)
void wget_vector_set_growth_policy (wget_vector_t *v, int off)
int wget_vector_insert (wget_vector_t *v, const void *elem, size_t size, int pos)
int wget_vector_insert_noalloc (wget_vector_t *v, const void *elem, int pos)
int wget_vector_insert_sorted (wget_vector_t *v, const void *elem, size_t size)
int wget_vector_insert_sorted_noalloc (wget_vector_t *v, const void *elem)
int wget_vector_add (wget_vector_t *v, const void *elem, size_t size)
int wget_vector_add_noalloc (wget_vector_t *v, const void *elem)
int wget_vector_add_str (wget_vector_t *v, const char *s)
int wget_vector_add_vprintf (wget_vector_t *v, const char *fmt, va_list args)
int wget_vector_add_printf (wget_vector_t *v, const char *fmt,...)
int wget_vector_replace (wget_vector_t *v, const void *elem, size_t size, int pos)
int wget_vector_replace_noalloc (wget_vector_t *v, const void *elem, int pos)
int wget_vector_remove (wget_vector_t *v, int pos)
int wget_vector_remove_nofree (wget_vector_t *v, int pos)
int wget_vector_move (wget_vector_t *v, int old_pos, int new_pos)
int wget_vector_swap (wget_vector_t *v, int pos1, int pos2)
void wget_vector_free (wget_vector_t **v)
void wget_vector_clear (wget_vector_t *v)
void wget_vector_clear_nofree (wget_vector_t *v)
int wget_vector_size (const wget_vector_t *v)
void * wget_vector_get (const wget_vector_t *v, int pos)
int wget_vector_browse (const wget_vector_t *v, wget_vector_browse_t browse, void *ctx)
void wget_vector_setcmpfunc (wget_vector_t *v, wget_vector_compare_t cmp)
void wget_vector_set_destructor (wget_vector_t *v, wget_vector_destructor_t destructor)
void wget_vector_sort (wget_vector_t *v)
int wget_vector_find (const wget_vector_t *v, const void *elem)
int wget_vector_contains (const wget_vector_t *v, const void *elem)
int wget_vector_findext (const wget_vector_t *v, int start, int direction, wget_vector_find_t find)
Detailed Description¶
Functions to realize vectors (growable arrays).Function Documentation¶
wget_vector_t* wget_vector_create (int max, wget_vector_compare_t cmp)¶
Parameters:cmp Comparison function for sorting/finding/sorted insertion or NULL.
Returns:
Create a new vector instance, to be free'd after use with wget_vector_free().
void wget_vector_set_growth_policy (wget_vector_t * v, int off)¶
Parameters:off Vector growth mode: positive values: increase vector by off entries on each resize negative values: increase vector by multiplying -off, e.g. -2 doubles the size on each resize
Set the growth policy for internal memory.
int wget_vector_insert (wget_vector_t * v, const void * elem, size_t size, int pos)¶
Parameters:elem Element to insert into v
size Size of elem
pos Position to insert elem at
Returns:
Insert elem of given size at index pos.
elem is cloned / copied (shallow).
An error is returned if v is NULL or pos is out of range (< 0 or > # of entries).
int wget_vector_insert_noalloc (wget_vector_t * v, const void * elem, int pos)¶
Parameters:elem Element to insert into v
pos Position to insert elem at
Returns:
Insert elem of at index pos.
elem is not cloned, the vector takes 'ownership' of the element.
An error is returned if v is NULL or pos is out of range (< 0 or > # of entries).
int wget_vector_insert_sorted (wget_vector_t * v, const void * elem, size_t size)¶
Parameters:elem Element to insert into v
size Size of elem
Returns:
Insert elem of given size at a position that keeps the sort order of the elements. If the vector has no comparison function, elem will be inserted as the last element. If the elements in the vector are not sorted, they will be sorted after returning from this function.
elem is cloned / copied (shallow).
An error is returned if v is NULL.
int wget_vector_insert_sorted_noalloc (wget_vector_t * v, const void * elem)¶
Parameters:elem Element to insert into v
Returns:
Insert elem of at a position that keeps the sort order of the elements. If the vector has no comparison function, elem will be inserted as the last element. If the elements in the vector are not sorted, they will be sorted after returning from this function.
elem is not cloned, the vector takes 'ownership' of the element.
An error is returned if v is NULL.
int wget_vector_add (wget_vector_t * v, const void * elem, size_t size)¶
Parameters:elem Element to append to a v
size Size of elem
Returns:
Append elem of given size to vector v.
elem is cloned / copied (shallow).
An error is returned if v is NULL.
int wget_vector_add_noalloc (wget_vector_t * v, const void * elem)¶
Parameters:elem Element to append to a v
Returns:
Append elem to vector v.
elem is not cloned, the vector takes 'ownership' of the element.
An error is returned if v is NULL.
int wget_vector_add_str (wget_vector_t * v, const char * s)¶
Parameters:s String to append to v
Returns:
Append string s as an element to vector v.
s is cloned / copied.
An error is returned if v or s is NULL.
int wget_vector_add_vprintf (wget_vector_t * v, const char * fmt, va_list args)¶
Parameters:fmt Printf-like format string
args Arguments for the fmt
Returns:
Construct string in a printf-like manner and append it as an element to vector v.
An error is returned if v or fmt is NULL.
int wget_vector_add_printf (wget_vector_t * v, const char * fmt, ...)¶
Parameters:fmt Printf-like format string
... Arguments for the fmt
Returns:
Construct string in a printf-like manner and append it as an element to vector v.
An error is returned if v or fmt is NULL.
int wget_vector_replace (wget_vector_t * v, const void * elem, size_t size, int pos)¶
Parameters:elem Element to insert into v
size Size of elem
pos Position to insert elem at
Returns:
Replace the element at position pos with elem of given size. If the vector has an element destructor function, this is called. The old element is free'd.
elem is cloned / copied (shallow).
An error is returned if v is NULL or pos is out of range (< 0 or > # of entries).
int wget_vector_replace_noalloc (wget_vector_t * v, const void * elem, int pos)¶
Parameters:elem Element to insert into v
pos Position to insert elem at
Returns:
Replace the element at position pos with elem. If the vector has an element destructor function, this is called. The old element is free'd.
elem is not cloned, the vector takes 'ownership' of the element.
An error is returned if v is NULL or pos is out of range (< 0 or > # of entries).
int wget_vector_remove (wget_vector_t * v, int pos)¶
Parameters:pos Position of element to remove
Returns:
Remove the element at position pos. If the vector has an element destructor function, this is called. The element is free'd.
An error is returned if v is NULL or pos is out of range (< 0 or > # of entries).
int wget_vector_remove_nofree (wget_vector_t * v, int pos)¶
Parameters:pos Position of element to remove
Returns:
Remove the element at position pos. No element destructor function is called, the element is not free'd.
An error is returned if v is NULL or pos is out of range (< 0 or > # of entries).
int wget_vector_move (wget_vector_t * v, int old_pos, int new_pos)¶
Parameters:old_pos Position to move element from
new_pos Position to move element to
Returns:
Move the element at position old_pos to new_pos.
Other elements may change the position.
An error is returned if v is NULL or either old_pos or new_pos is out of range (< 0 or > # of entries).
int wget_vector_swap (wget_vector_t * v, int pos1, int pos2)¶
Parameters:pos1 Position of element one
pos2 Position of element two
Returns:
Swap the two elements at position pos1 and pos2.
An error is returned if v is NULL or either pos1 or pos2 is out of range (< 0 or > # of entries).
void wget_vector_free (wget_vector_t ** v)¶
Parameters:Free the vector v and it's contents.
For each element the destructor function is called and the element free'd thereafter. Then the vector itself is free'd and set to NULL.
void wget_vector_clear (wget_vector_t * v)¶
Parameters:Free all elements of the vector v but not the vector itself.
For each element the destructor function is called and the element free'd thereafter. The vector is then empty and can be reused.
void wget_vector_clear_nofree (wget_vector_t * v)¶
Parameters:Remove all elements of the vector v without free'ing them. The caller is responsible to care for the elements.
The vector is then empty and can be reused.
int wget_vector_size (const wget_vector_t * v)¶
Parameters:Returns:
Retrieve the number of elements of the vector v. If v is NULL, 0 is returned.
void* wget_vector_get (const wget_vector_t * v, int pos)¶
Parameters:pos Position of element to retrieve
Returns:
Retrieve the element at position pos.
NULL is returned if v is NULL or pos is out of range (< 0 or > # of entries).
int wget_vector_browse (const wget_vector_t * v, wget_vector_browse_t browse, void * ctx)¶
Parameters:browse Function to be called for each element of v
ctx Context variable use as param to browse
Returns:
Call 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.
void wget_vector_setcmpfunc (wget_vector_t * v, wget_vector_compare_t cmp)¶
Parameters:cmp Function to compare elements
Set the compare function used by wget_vector_sort().
void wget_vector_set_destructor (wget_vector_t * v, wget_vector_destructor_t destructor)¶
Parameters:destructor Function to be called for element destruction
Set the destructor function that is called for each element to be removed. It should not free the element (pointer) itself.
void wget_vector_sort (wget_vector_t * v)¶
Parameters:Sort the elements in vector v usign the compare function. Do nothing if v is NULL or the compare function is not set.
int wget_vector_find (const wget_vector_t * v, const void * elem)¶
Parameters:elem Element to search for
Returns:
Searches for the given element using the compare function of the vector.
Returns -1 if v is NULL or if the compare function is not set.
int wget_vector_contains (const wget_vector_t * v, const void * elem)¶
Parameters:elem Element to check for
Returns:
Checks whether the element elem exists or not.
int wget_vector_findext (const wget_vector_t * v, int start, int direction, wget_vector_find_t find)¶
Parameters:start Index to start search from
direction Direction of search
find Function to be called for each element
Returns:
Call find for each element starting at start. If find returns 0 the current index is returned.
Returns -1 if v is NULL or if the find didn't return 0.
Author¶
Generated automatically by Doxygen for wget2 from the source code.Thu May 17 2018 | Version 1.99.1 |