1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_gsacust.h - generic sorted arrays
6 (C) Copyright 2001 by Pavel Pisa - Originator
8 The uLan utilities library can be used, copied and modified under
10 - GPL - GNU General Public License
11 - LGPL - GNU Lesser General Public License
12 - MPL - Mozilla Public License
13 - and other licenses added by project originators
14 Code can be modified and re-distributed under any combination
15 of the above listed licenses. If contributor does not agree with
16 some of the licenses, he/she can delete appropriate line.
17 Warning, if you delete all lines, you are not allowed to
18 distribute source code and/or binaries utilizing code.
20 See files COPYING and README for details.
22 *******************************************************************/
33 /* Static version of custom GSA arrays. It does not support runtime modifications. */
34 #define GSA_STATIC_CUST_IMP(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
35 cust_array_field, cust_item_key, cust_cmp_fnc, cust_ins_fl) \
38 cust_prefix##_bsearch_indx(const cust_array_t *array, const cust_key_t *key, \
39 int mode, unsigned *indx) \
43 if(!array->cust_array_field.items || !array->cust_array_field.count){\
48 b=array->cust_array_field.count;\
51 r=cust_cmp_fnc(cust_prefix##_indx2key(array, c), key);\
52 if(!r) if(!(mode&GSA_FAFTER)) break;\
59 return mode&GSA_FAFTER;\
63 /* equal items can be in range a to b-1 */\
64 /* routine looks for first one */\
68 r=cust_cmp_fnc(cust_prefix##_indx2key(array, c), key);\
81 /* Dynamic version with full support of insert and delete functions. */
82 #define GSA_CUST_IMP(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
83 cust_array_field, cust_item_key, cust_cmp_fnc, cust_ins_fl) \
85 GSA_STATIC_CUST_IMP(cust_prefix, cust_array_t, cust_item_t, cust_key_t,\
86 cust_array_field, cust_item_key, cust_cmp_fnc, cust_ins_fl) \
89 cust_prefix##_insert(cust_array_t *array, cust_item_t *item)\
92 if(cust_prefix##_bsearch_indx(array, &item->cust_item_key, cust_ins_fl, &indx))\
93 if(!cust_ins_fl) return -1;\
94 return cust_prefix##_insert_at(array,item,indx);\
98 cust_prefix##_delete(cust_array_t *array, const cust_item_t *item)\
101 if(!cust_prefix##_bsearch_indx(array, &item->cust_item_key, GSA_FFIRST,&indx))\
103 while(cust_prefix##_indx2item(array, indx)!=item){\
104 if(++indx>=array->cust_array_field.count) return -1;\
105 if(cust_cmp_fnc(cust_prefix##_indx2key(array, indx),\
106 &item->cust_item_key)) return -1;\
108 return cust_prefix##_delete_at(array,indx);\
116 #endif /* _UL_GSACUST_H */