![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
Include dependency graph for genlist.cpp:Go to the source code of this file.
Functions | |
| struct genlist * | genlist_new () |
| Create a new empty genlist. More... | |
| struct genlist * | genlist_new_full (genlist_free_fn_t free_data_func) |
| Create a new empty genlist with a free data function. More... | |
| void | genlist_destroy (struct genlist *pgenlist) |
| Destroys the genlist. More... | |
| static void | genlist_link_new (struct genlist *pgenlist, void *dataptr, struct genlist_link *prev, struct genlist_link *next) |
| Create a new link. More... | |
| static void | genlist_link_destroy (struct genlist *pgenlist, struct genlist_link *plink) |
| Free a link. More... | |
| static struct genlist_link * | genlist_link_at_pos (const struct genlist *pgenlist, int pos) |
| Returns a pointer to the genlist link structure at the specified position. More... | |
| struct genlist * | genlist_copy (const struct genlist *pgenlist) |
| Returns a new genlist that's a copy of the existing one. More... | |
| struct genlist * | genlist_copy_full (const struct genlist *pgenlist, genlist_copy_fn_t copy_data_func, genlist_free_fn_t free_data_func) |
| Returns a new genlist that's a copy of the existing one. More... | |
| int | genlist_size (const struct genlist *pgenlist) |
| Returns the number of elements stored in the genlist. More... | |
| struct genlist_link * | genlist_link_get (const struct genlist *pgenlist, int idx) |
| Returns the link in the genlist at the position given by 'idx'. More... | |
| struct genlist_link * | genlist_tail (const struct genlist *pgenlist) |
| Returns the tail link of the genlist. More... | |
| void * | genlist_get (const struct genlist *pgenlist, int idx) |
| Returns the user-data pointer stored in the genlist at the position given by 'idx'. More... | |
| void * | genlist_front (const struct genlist *pgenlist) |
| Returns the user-data pointer stored in the first element of the genlist. More... | |
| void * | genlist_back (const struct genlist *pgenlist) |
| Returns the user-data pointer stored in the last element of the genlist. More... | |
| void | genlist_clear (struct genlist *pgenlist) |
| Frees all the internal data used by the genlist (but doesn't touch the user-data). More... | |
| void | genlist_unique (struct genlist *pgenlist) |
| Remove all duplicates of element from every consecutive group of equal elements in the list. More... | |
| void | genlist_unique_full (struct genlist *pgenlist, genlist_comp_fn_t comp_data_func) |
| Remove all duplicates of element from every consecutive group of equal elements in the list (equality is assumed from if the compare function return TRUE). More... | |
| bool | genlist_remove (struct genlist *pgenlist, const void *punlink) |
| Remove an element of the genlist with the specified user-data pointer given by 'punlink'. More... | |
| int | genlist_remove_all (struct genlist *pgenlist, const void *punlink) |
| Remove all elements of the genlist with the specified user-data pointer given by 'punlink'. More... | |
| bool | genlist_remove_if (struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) |
| Remove the first element of the genlist which fit the function (the function return TRUE). More... | |
| int | genlist_remove_all_if (struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) |
| Remove all elements of the genlist which fit the function (the function return TRUE). More... | |
| void | genlist_erase (struct genlist *pgenlist, struct genlist_link *plink) |
| Remove the element pointed to plink. More... | |
| void | genlist_pop_front (struct genlist *pgenlist) |
| Remove the first element of the genlist. More... | |
| void | genlist_pop_back (struct genlist *pgenlist) |
| Remove the last element of the genlist. More... | |
| void | genlist_insert (struct genlist *pgenlist, void *data, int pos) |
| Insert a new element in the list, at position 'pos', with the specified user-data pointer 'data'. More... | |
| void | genlist_insert_after (struct genlist *pgenlist, void *data, struct genlist_link *plink) |
| Insert an item after the link. More... | |
| void | genlist_insert_before (struct genlist *pgenlist, void *data, struct genlist_link *plink) |
| Insert an item before the link. More... | |
| void | genlist_prepend (struct genlist *pgenlist, void *data) |
| Insert an item at the start of the list. More... | |
| void | genlist_append (struct genlist *pgenlist, void *data) |
| Insert an item at the end of the list. More... | |
| struct genlist_link * | genlist_search (const struct genlist *pgenlist, const void *data) |
| Return the link where data is equal to 'data'. More... | |
| struct genlist_link * | genlist_search_if (const struct genlist *pgenlist, genlist_cond_fn_t cond_data_func) |
| Return the link which fit the conditional function. More... | |
| void | genlist_sort (struct genlist *pgenlist, int(*compar)(const void *, const void *)) |
| Sort the elements of a genlist. More... | |
| void | genlist_shuffle (struct genlist *pgenlist) |
| Randomize the elements of a genlist using the Fisher-Yates shuffle. More... | |
| void | genlist_reverse (struct genlist *pgenlist) |
| Reverse the order of the elements in the genlist. More... | |
| void | genlist_allocate_mutex (struct genlist *pgenlist) |
| Allocates list mutex. More... | |
| void | genlist_release_mutex (struct genlist *pgenlist) |
| Releases list mutex. More... | |
| void genlist_allocate_mutex | ( | struct genlist * | pgenlist | ) |
Allocates list mutex.
Definition at line 676 of file genlist.cpp.
Referenced by _list_allocate_mutex().
| void genlist_append | ( | struct genlist * | pgenlist, |
| void * | data | ||
| ) |
Insert an item at the end of the list.
Definition at line 525 of file genlist.cpp.
Referenced by _list_append().
| void* genlist_back | ( | const struct genlist * | pgenlist | ) |
Returns the user-data pointer stored in the last element of the genlist.
Definition at line 228 of file genlist.cpp.
Referenced by _list_back().
| void genlist_clear | ( | struct genlist * | pgenlist | ) |
Frees all the internal data used by the genlist (but doesn't touch the user-data).
At the end the state of the genlist will be the same as when genlist_init() is called on a new genlist.
Definition at line 238 of file genlist.cpp.
Referenced by _list_clear(), and genlist_destroy().
Returns a new genlist that's a copy of the existing one.
Definition at line 144 of file genlist.cpp.
Referenced by _list_copy().
| struct genlist* genlist_copy_full | ( | const struct genlist * | pgenlist, |
| genlist_copy_fn_t | copy_data_func, | ||
| genlist_free_fn_t | free_data_func | ||
| ) |
Returns a new genlist that's a copy of the existing one.
Definition at line 152 of file genlist.cpp.
Referenced by _list_copy_full(), and genlist_copy().
| void genlist_destroy | ( | struct genlist * | pgenlist | ) |
| void genlist_erase | ( | struct genlist * | pgenlist, |
| struct genlist_link * | plink | ||
| ) |
Remove the element pointed to plink.
NB: After calling this function 'plink' is no more usable. You should have saved the next or previous link before.
Definition at line 424 of file genlist.cpp.
Referenced by _list_erase().
| void* genlist_front | ( | const struct genlist * | pgenlist | ) |
Returns the user-data pointer stored in the first element of the genlist.
Definition at line 220 of file genlist.cpp.
Referenced by _list_front().
| void* genlist_get | ( | const struct genlist * | pgenlist, |
| int | idx | ||
| ) |
Returns the user-data pointer stored in the genlist at the position given by 'idx'.
For idx out of range (including an empty list), returns nullptr. Recall 'idx' can be -1 meaning the last element.
Definition at line 212 of file genlist.cpp.
Referenced by _list_get().
| void genlist_insert | ( | struct genlist * | pgenlist, |
| void * | data, | ||
| int | pos | ||
| ) |
Insert a new element in the list, at position 'pos', with the specified user-data pointer 'data'.
Existing elements at >= pos are moved one space to the "right". Recall 'pos' can be -1 meaning add at the end of the list. For an empty list pos has no effect. A bad 'pos' value for a non-empty list is treated as -1 (is this a good idea?)
Definition at line 465 of file genlist.cpp.
Referenced by _list_insert().
| void genlist_insert_after | ( | struct genlist * | pgenlist, |
| void * | data, | ||
| struct genlist_link * | plink | ||
| ) |
Insert an item after the link.
If plink is nullptr, prepend to the list.
Definition at line 490 of file genlist.cpp.
Referenced by _list_insert_after().
| void genlist_insert_before | ( | struct genlist * | pgenlist, |
| void * | data, | ||
| struct genlist_link * | plink | ||
| ) |
Insert an item before the link.
Definition at line 502 of file genlist.cpp.
Referenced by _list_insert_before().
|
static |
Returns a pointer to the genlist link structure at the specified position.
Recall 'pos' -1 refers to the last position. For pos out of range returns nullptr. Traverses list either forwards or backwards for best efficiency.
Definition at line 115 of file genlist.cpp.
Referenced by genlist_insert(), and genlist_link_get().
|
static |
Free a link.
Definition at line 83 of file genlist.cpp.
Referenced by genlist_erase(), genlist_pop_back(), genlist_pop_front(), genlist_remove(), genlist_remove_all(), genlist_remove_all_if(), genlist_remove_if(), and genlist_unique_full().
| struct genlist_link* genlist_link_get | ( | const struct genlist * | pgenlist, |
| int | idx | ||
| ) |
Returns the link in the genlist at the position given by 'idx'.
For idx out of range (including an empty list), returns nullptr. Recall 'idx' can be -1 meaning the last element.
Definition at line 190 of file genlist.cpp.
Referenced by _list_link_get(), and genlist_get().
|
static |
Create a new link.
Definition at line 58 of file genlist.cpp.
Referenced by genlist_append(), genlist_copy_full(), genlist_insert(), genlist_insert_after(), genlist_insert_before(), and genlist_prepend().
| struct genlist* genlist_new | ( | ) |
| struct genlist* genlist_new_full | ( | genlist_free_fn_t | free_data_func | ) |
Create a new empty genlist with a free data function.
Definition at line 30 of file genlist.cpp.
Referenced by _list_new_full(), genlist_copy_full(), and genlist_new().
| void genlist_pop_back | ( | struct genlist * | pgenlist | ) |
Remove the last element of the genlist.
Definition at line 448 of file genlist.cpp.
Referenced by _list_pop_back().
| void genlist_pop_front | ( | struct genlist * | pgenlist | ) |
Remove the first element of the genlist.
Definition at line 436 of file genlist.cpp.
Referenced by _list_pop_front().
| void genlist_prepend | ( | struct genlist * | pgenlist, |
| void * | data | ||
| ) |
Insert an item at the start of the list.
Definition at line 515 of file genlist.cpp.
Referenced by _list_prepend().
| void genlist_release_mutex | ( | struct genlist * | pgenlist | ) |
Releases list mutex.
Definition at line 684 of file genlist.cpp.
Referenced by _list_release_mutex().
| bool genlist_remove | ( | struct genlist * | pgenlist, |
| const void * | punlink | ||
| ) |
Remove an element of the genlist with the specified user-data pointer given by 'punlink'.
If there is no such element, does nothing. If there are multiple such elements, removes the first one. Return TRUE if one element has been removed. See also, genlist_remove_all(), genlist_remove_if() and genlist_remove_all_if().
Definition at line 317 of file genlist.cpp.
Referenced by _list_remove().
| int genlist_remove_all | ( | struct genlist * | pgenlist, |
| const void * | punlink | ||
| ) |
Remove all elements of the genlist with the specified user-data pointer given by 'punlink'.
Return the number of removed elements. See also, genlist_remove(), genlist_remove_if() and genlist_remove_all_if().
Definition at line 339 of file genlist.cpp.
Referenced by _list_remove_all().
| int genlist_remove_all_if | ( | struct genlist * | pgenlist, |
| genlist_cond_fn_t | cond_data_func | ||
| ) |
Remove all elements of the genlist which fit the function (the function return TRUE).
Return the number of removed elements. See also, genlist_remove(), genlist_remove_all(), and genlist_remove_if().
Definition at line 392 of file genlist.cpp.
Referenced by _list_remove_all_if().
| bool genlist_remove_if | ( | struct genlist * | pgenlist, |
| genlist_cond_fn_t | cond_data_func | ||
| ) |
Remove the first element of the genlist which fit the function (the function return TRUE).
Return TRUE if one element has been removed. See also, genlist_remove(), genlist_remove_all(), and genlist_remove_all_if().
Definition at line 367 of file genlist.cpp.
Referenced by _list_remove_if().
| void genlist_reverse | ( | struct genlist * | pgenlist | ) |
Reverse the order of the elements in the genlist.
Definition at line 653 of file genlist.cpp.
Referenced by _list_reverse().
| struct genlist_link* genlist_search | ( | const struct genlist * | pgenlist, |
| const void * | data | ||
| ) |
Return the link where data is equal to 'data'.
Returns nullptr if not found.
This is an O(n) operation. Hence, "search".
Definition at line 538 of file genlist.cpp.
Referenced by _list_search().
| struct genlist_link* genlist_search_if | ( | const struct genlist * | pgenlist, |
| genlist_cond_fn_t | cond_data_func | ||
| ) |
Return the link which fit the conditional function.
Returns nullptr if no match.
Definition at line 558 of file genlist.cpp.
Referenced by _list_search_if().
| void genlist_shuffle | ( | struct genlist * | pgenlist | ) |
Randomize the elements of a genlist using the Fisher-Yates shuffle.
see: genlist_sort() and shared.c:array_shuffle()
Definition at line 619 of file genlist.cpp.
Referenced by _list_shuffle().
| int genlist_size | ( | const struct genlist * | pgenlist | ) |
Returns the number of elements stored in the genlist.
Definition at line 179 of file genlist.cpp.
Referenced by _list_size(), genlist_shuffle(), and genlist_sort().
| void genlist_sort | ( | struct genlist * | pgenlist, |
| int(*)(const void *, const void *) | compar | ||
| ) |
Sort the elements of a genlist.
The comparison function should be a function usable by qsort; note that the const void * arguments to compar should really be "pointers to void*", where the void* being pointed to are the genlist dataptrs. That is, there are two levels of indirection. To do the sort we first construct an array of pointers corresponding to the genlist dataptrs, then sort those and put them back into the genlist.
Definition at line 587 of file genlist.cpp.
Referenced by _list_sort().
| struct genlist_link* genlist_tail | ( | const struct genlist * | pgenlist | ) |
Returns the tail link of the genlist.
Definition at line 201 of file genlist.cpp.
Referenced by _list_tail(), and genlist_back().
| void genlist_unique | ( | struct genlist * | pgenlist | ) |
Remove all duplicates of element from every consecutive group of equal elements in the list.
Definition at line 270 of file genlist.cpp.
Referenced by _list_unique().
| void genlist_unique_full | ( | struct genlist * | pgenlist, |
| genlist_comp_fn_t | comp_data_func | ||
| ) |
Remove all duplicates of element from every consecutive group of equal elements in the list (equality is assumed from if the compare function return TRUE).
Definition at line 280 of file genlist.cpp.
Referenced by _list_unique_full(), and genlist_unique().