/********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ***********************************************************************/ #ifndef FC__SORTLIST_H #define FC__SORTLIST_H /********************************************************************** MODULE: sortlist Meant to be an improvement over a generic doubly-linked list because DLL's are very inefficient for many things. ***********************************************************************/ struct sortlist { int capacity; int num_links; void **data; }; /* Mirrors the genlist interface for relatively seamless integration. */ int sortlist_size(struct sortlist *slist); void* sortlist_get(struct sortlist *slist, int idx); void sortlist_init(struct sortlist *slist); void sortlist_unlink(struct sortlist *slist, void *olddata); void sortlist_unlink_all(struct sortlist *slist); void sortlist_insert(struct sortlist *slist, void *newdata); /* Some useful macros */ #define SORTED_LIST_ITERATE(atype, sorted_list, var) { \ atype *var; \ int _sitr; \ for(_sitr = 0;_sitr < sorted_list.num_links;_sitr++)\ { var = (atype *)(sorted_list.data[_sitr]); #define SORTED_LIST_ITERATE_END }} /* Now backwards ... */ #define SORTED_LIST_REV_ITERATE(atype, sorted_list, var) { \ atype *var; \ int _sitr; \ for(_sitr = (sorted_list.num_links-1);s_itr >= 0;_sitr--) \ { var = (atype *)(sorted_list.data[_sitr].dataptr); #define SORTED_LIST_REV_ITERATE_END }} /* What's the initial size of this list? */ #define INIT_SORT_SIZE 8 #endif /* FC__SORTLIST_H */