47 if (pgenlist ==
nullptr) {
66 if (
nullptr != prev) {
72 if (
nullptr != next) {
121 }
else if (pos == -1) {
123 }
else if (pos < -1 || pos >= pgenlist->
nelements) {
127 if (pos < pgenlist->nelements / 2) {
128 for (plink = pgenlist->
head_link; pos != 0; pos--) {
161 if (
nullptr != copy_data_func) {
162 for (plink = pgenlist->
head_link; plink; plink = plink->
next) {
167 for (plink = pgenlist->
head_link; plink; plink = plink->
next) {
203 return (
nullptr != pgenlist ? pgenlist->
tail_link :
nullptr);
251 if (
nullptr != free_data_func) {
253 plink2 = plink->
next;
254 free_data_func(plink->
dataptr);
256 }
while (
nullptr != (plink = plink2));
259 plink2 = plink->
next;
261 }
while (
nullptr != (plink = plink2));
288 if (
nullptr != comp_data_func) {
290 plink2 = plink->
next;
291 if (
nullptr != plink2
292 && comp_data_func(plink->
dataptr, plink2->dataptr)) {
296 }
while ((plink = plink2) !=
nullptr);
299 plink2 = plink->
next;
300 if (
nullptr != plink2 && plink->
dataptr == plink2->dataptr) {
304 }
while ((plink = plink2) !=
nullptr);
323 for (plink = pgenlist->
head_link;
nullptr != plink; plink = plink->
next) {
324 if (plink->
dataptr == punlink) {
346 for (plink = pgenlist->
head_link;
nullptr != plink;) {
347 if (plink->
dataptr == punlink) {
372 if (
nullptr != cond_data_func) {
375 for (;
nullptr != plink; plink = plink->
next) {
376 if (cond_data_func(plink->
dataptr)) {
397 if (
nullptr != cond_data_func) {
401 while (
nullptr != plink) {
402 if (cond_data_func(plink->
dataptr)) {
428 if (
nullptr != plink) {
472 }
else if (0 == pos) {
475 }
else if (-1 >= pos || pos >= pgenlist->
nelements) {
545 for (plink = pgenlist->
head_link; plink; plink = plink->
next) {
563 if (
nullptr != cond_data_func) {
566 for (;
nullptr != plink; plink = plink->
next) {
567 if (cond_data_func(plink->
dataptr)) {
588 int (*compar)(
const void *,
const void *))
599 sortbuf =
new void *[n];
601 for (i = 0; i < n; i++, myiter = myiter->
next) {
605 qsort(sortbuf, n,
sizeof(*sortbuf), compar);
608 for (i = 0; i < n; i++, myiter = myiter->
next) {
622 std::vector<void *> sortbuf;
624 std::vector<int> shuffle;
634 for (i = 0; i < n; i++, myiter = myiter->
next) {
641 std::shuffle(shuffle.begin(), shuffle.end(),
fc_rand_state());
645 for (i = 0; i < n; i++, myiter = myiter->
next) {
646 myiter->
dataptr = sortbuf[shuffle[i]];
662 for (counter = pgenlist->
nelements / 2; 0 < counter; counter--) {
678 pgenlist->
mutex.lock();
686 pgenlist->
mutex.unlock();
bool genlist_remove(struct genlist *pgenlist, const void *punlink)
Remove an element of the genlist with the specified user-data pointer given by 'punlink'.
void genlist_allocate_mutex(struct genlist *pgenlist)
Allocates list mutex.
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'.
void genlist_release_mutex(struct genlist *pgenlist)
Releases list mutex.
void * genlist_get(const struct genlist *pgenlist, int idx)
Returns the user-data pointer stored in the genlist at the position given by 'idx'.
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.
void * genlist_back(const struct genlist *pgenlist)
Returns the user-data pointer stored in the last element of the genlist.
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'.
void genlist_erase(struct genlist *pgenlist, struct genlist_link *plink)
Remove the element pointed to plink.
void genlist_clear(struct genlist *pgenlist)
Frees all the internal data used by the genlist (but doesn't touch the user-data).
void genlist_prepend(struct genlist *pgenlist, void *data)
Insert an item at the start of the list.
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).
void genlist_append(struct genlist *pgenlist, void *data)
Insert an item at the end of the list.
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...
struct genlist_link * genlist_tail(const struct genlist *pgenlist)
Returns the tail link of the genlist.
static void genlist_link_new(struct genlist *pgenlist, void *dataptr, struct genlist_link *prev, struct genlist_link *next)
Create a new link.
struct genlist_link * genlist_link_get(const struct genlist *pgenlist, int idx)
Returns the link in the genlist at the position given by 'idx'.
void genlist_destroy(struct genlist *pgenlist)
Destroys the genlist.
void genlist_pop_front(struct genlist *pgenlist)
Remove the first element of the genlist.
void * genlist_front(const struct genlist *pgenlist)
Returns the user-data pointer stored in the first element of the genlist.
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.
void genlist_insert_before(struct genlist *pgenlist, void *data, struct genlist_link *plink)
Insert an item before the link.
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).
void genlist_unique(struct genlist *pgenlist)
Remove all duplicates of element from every consecutive group of equal elements in the list.
void genlist_insert_after(struct genlist *pgenlist, void *data, struct genlist_link *plink)
Insert an item after the link.
struct genlist * genlist_copy(const struct genlist *pgenlist)
Returns a new genlist that's a copy of the existing one.
void genlist_sort(struct genlist *pgenlist, int(*compar)(const void *, const void *))
Sort the elements of a genlist.
void genlist_reverse(struct genlist *pgenlist)
Reverse the order of the elements in the genlist.
struct genlist_link * genlist_search(const struct genlist *pgenlist, const void *data)
Return the link where data is equal to 'data'.
void genlist_pop_back(struct genlist *pgenlist)
Remove the last element of the genlist.
struct genlist * genlist_new()
Create a new empty genlist.
struct genlist * genlist_new_full(genlist_free_fn_t free_data_func)
Create a new empty genlist with a free data function.
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.
int genlist_size(const struct genlist *pgenlist)
Returns the number of elements stored in the genlist.
void genlist_shuffle(struct genlist *pgenlist)
Randomize the elements of a genlist using the Fisher-Yates shuffle.
static void genlist_link_destroy(struct genlist *pgenlist, struct genlist_link *plink)
Free a link.
static struct genlist_link * genlist_head(const struct genlist *pgenlist)
static void * genlist_link_data(const struct genlist_link *plink)
bool(* genlist_cond_fn_t)(const void *)
bool(* genlist_comp_fn_t)(const void *, const void *)
void(* genlist_free_fn_t)(void *)
void *(* genlist_copy_fn_t)(const void *)
#define fc_assert_ret(condition)
#define fc_assert_ret_val(condition, val)
std::mt19937 & fc_rand_state()
Returns a reference to the current random generator state; eg for save/restore.
struct genlist_link * prev
struct genlist_link * next
struct genlist_link * tail_link
struct genlist_link * head_link
genlist_free_fn_t free_data_func