Freeciv-3.3
|
#include <stdlib.h>
#include "fcthread.h"
#include "log.h"
#include "mem.h"
#include "shared.h"
#include "genlist.h"
Go to the source code of this file.
Allocates list mutex
Definition at line 647 of file genlist.c.
Referenced by _list_allocate_mutex().
Insert an item at the end of the list.
Definition at line 508 of file genlist.c.
Referenced by _list_append().
Returns the user-data pointer stored in the last element of the genlist.
Definition at line 237 of file genlist.c.
Referenced by _list_back().
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 247 of file genlist.c.
Referenced by _list_clear(), and genlist_destroy().
Returns a new genlist that's a copy of the existing one.
Definition at line 157 of file genlist.c.
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 165 of file genlist.c.
Referenced by _list_copy_full(), and genlist_copy().
Destroys the genlist.
Definition at line 57 of file genlist.c.
Referenced by _list_destroy(), and luaconsole_dialog_done().
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 421 of file genlist.c.
Referenced by _list_erase().
Returns the user-data pointer stored in the first element of the genlist.
Definition at line 229 of file genlist.c.
Referenced by _list_front().
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 221 of file genlist.c.
Referenced by _list_get(), inputline_handler(), inputline_handler(), inputline_return(), luaconsole_input_handler(), luaconsole_input_handler(), and luaconsole_input_return().
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 456 of file genlist.c.
Referenced by _list_insert().
Insert an item after the link. If plink is nullptr, prepend to the list.
Definition at line 480 of file genlist.c.
Referenced by _list_insert_after().
Insert an item before the link.
Definition at line 490 of file genlist.c.
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 128 of file genlist.c.
Referenced by genlist_insert(), and genlist_link_get().
Free a link.
Definition at line 96 of file genlist.c.
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().
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 202 of file genlist.c.
Referenced by _list_link_get(), and genlist_get().
|
static |
Create a new link.
Definition at line 71 of file genlist.c.
Referenced by genlist_append(), genlist_copy_full(), genlist_insert(), genlist_insert_after(), genlist_insert_before(), and genlist_prepend().
Create a new empty genlist.
Definition at line 31 of file genlist.c.
Referenced by _list_new(), chatline_init(), and luaconsole_dialog_init().
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 39 of file genlist.c.
Referenced by _list_new_full(), genlist_copy_full(), and genlist_new().
Remove the last element of the genlist.
Definition at line 441 of file genlist.c.
Referenced by _list_pop_back().
Remove the first element of the genlist.
Definition at line 431 of file genlist.c.
Referenced by _list_pop_front().
Insert an item at the start of the list.
Definition at line 500 of file genlist.c.
Referenced by _list_prepend(), inputline_return(), and luaconsole_input_return().
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 322 of file genlist.c.
Referenced by _list_remove(), inputline_return(), and luaconsole_input_return().
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 342 of file genlist.c.
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 391 of file genlist.c.
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 368 of file genlist.c.
Referenced by _list_remove_if().
Reverse the order of the elements in the genlist.
Definition at line 625 of file genlist.c.
Referenced by _list_reverse().
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 518 of file genlist.c.
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 536 of file genlist.c.
Referenced by _list_search_if().
Randomize the elements of a genlist using the Fisher-Yates shuffle.
see: genlist_sort() and shared.c:array_shuffle()
Definition at line 595 of file genlist.c.
Referenced by _list_shuffle().
Returns the number of elements stored in the genlist.
Definition at line 192 of file genlist.c.
Referenced by _list_size(), genlist_shuffle(), genlist_sort(), inputline_handler(), inputline_handler(), inputline_return(), luaconsole_input_handler(), luaconsole_input_handler(), and luaconsole_input_return().
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 563 of file genlist.c.
Referenced by _list_sort().
struct genlist_link * genlist_tail | ( | const struct genlist * | pgenlist | ) |
Returns the tail link of the genlist.
Definition at line 210 of file genlist.c.
Referenced by _list_tail(), and genlist_back().
Remove all duplicates of element from every consecutive group of equal elements in the list.
Definition at line 277 of file genlist.c.
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 287 of file genlist.c.
Referenced by _list_unique_full(), and genlist_unique().