9 #ifndef __ZEDA_LIST_H__ 10 #define __ZEDA_LIST_H__ 36 #define zListClass(list_t,cell_t,data_t) \ 40 cell_t(){ prev = next = this; };\ 45 list_t(){ size = 0; };\ 48 #define zListClass(list_t,cell_t,data_t) \ 49 typedef struct __##cell_t{\ 50 struct __##cell_t *prev, *next;\ 53 typedef struct __##list_t{\ 63 #define zListCellPrev(c) (c)->prev 65 #define zListCellNext(c) (c)->next 67 #define zListCellSetPrev(c,p) ( zListCellPrev(c) = (p) ) 69 #define zListCellSetNext(c,n) ( zListCellNext(c) = (n) ) 72 #define zListCellInit(c) do{\ 73 zListCellSetNext( c, c ); \ 74 zListCellSetPrev( c, c ); \ 79 #define zListCellBind(l,f) do{\ 80 zListCellSetPrev( f, l ); \ 81 zListCellSetNext( l, f ); \ 85 #define zListCellInsertNext(c,n) do{\ 86 zListCellBind( n, zListCellNext(c) ); \ 87 zListCellBind( c, n ); \ 91 #define zListCellInsertPrev(c,p) do{\ 92 zListCellBind( zListCellPrev(c), p ); \ 93 zListCellBind( p, c ); \ 97 #define zListCellPurge(c) do{\ 98 zListCellBind( zListCellPrev((c)), zListCellNext((c)) ); \ 99 zListCellInit( (c) ); \ 104 #define zListCellDeleteNext(c,n) do{\ 105 if( zListCellNext(c) != (c) ){ \ 106 *(n) = zListCellNext( c ); \ 107 zListCellPurge( *(n) );\ 114 #define zListCellDeletePrev(c,p) do{\ 115 if( zListCellPrev(c) != (c) ){ \ 116 *(p) = zListCellPrev( c ); \ 117 zListCellPurge( *(p) );\ 124 #define zListCellSwap(cell_t,c1,c2) do{\ 125 cell_t *__zlist_cell_swap_tmp; \ 127 __zlist_cell_swap_tmp = zListCellPrev( c1 ); \ 128 zListCellBind( zListCellPrev(c2), c1 ); \ 129 zListCellBind( __zlist_cell_swap_tmp, c2 ); \ 130 __zlist_cell_swap_tmp = zListCellNext( c1 ); \ 131 zListCellBind( c1, zListCellNext(c2) ); \ 132 zListCellBind( c2, __zlist_cell_swap_tmp ); \ 138 #define zListCellFPrint(f,c) do{\ 139 fprintf( f, "cell [%p] ", c ); \ 140 fprintf( f, "%p <- prev | next-> %p\n", \ 141 zListCellPrev(c), zListCellNext(c) ); \ 145 #define zListCellPrint(c) zListCellFPrint( stdout, c ) 147 #define zListCellPrint(c) do{\ 148 printk( "cell [%p] ", c ); \ 149 printk( "%p <- prev | next-> %p\n", \ 150 zListCellPrev(c), zListCellNext(c) ); \ 159 #define zListSize(l) (l)->size 161 #define zListRoot(l) ( &(l)->root ) 163 #define zListHead(l) zListCellPrev( zListRoot( l ) ) 165 #define zListTail(l) zListCellNext( zListRoot( l ) ) 168 #define zListSetSize(l,n) ( zListSize(l) = (n) ) 170 #define zListIncSize(l) ( zListSize(l)++ ) 172 #define zListDecSize(l) ( zListSize(l)-- ) 175 #define zListIsEmpty(l) ( zListSize(l) == 0 ) 178 #define zListInit(l) do{\ 179 zListSetSize( l, 0 ); \ 180 zListCellInit( zListRoot( l ) ); \ 184 #define zListDestroy(t,l) do{\ 185 t *__zlist_destroy_cell = NULL; \ 187 while( !zListIsEmpty( l ) ){ \ 188 zListDeleteHead( l, &__zlist_destroy_cell ); \ 189 zFree( __zlist_destroy_cell ); \ 194 #define zListInsertNext(l,c,n) do{\ 195 zListCellInsertNext( c, n ); \ 200 #define zListInsertPrev(l,c,p) do{\ 201 zListCellInsertPrev( c, p ); \ 206 #define zListInsertHead(l,c) zListInsertPrev( l, zListRoot(l), c ) 208 #define zListInsertTail(l,c) zListInsertNext( l, zListRoot(l), c ) 212 #define zListDeleteNext(l,c,n) do{\ 213 zListCellDeleteNext( c, n ); \ 219 #define zListDeletePrev(l,c,p) do{\ 220 zListCellDeletePrev( c, p ); \ 226 #define zListDeleteHead(l,c) zListDeletePrev( l, zListRoot(l), c ) 229 #define zListDeleteTail(l,c) zListDeleteNext( l, zListRoot(l), c ) 232 #define zListPurge(l,c) do{\ 233 zListCellPurge( c );\ 239 #define zListAppendA(a,p) do{\ 240 if( !zListIsEmpty(p) ){\ 241 zListCellBind( zListHead(a), zListTail(p) );\ 242 zListCellBind( zListHead(p), zListRoot(a) );\ 243 zListSize(a) += zListSize(p);\ 250 #define zListAppendZ(a,p) do{\ 251 if( !zListIsEmpty(p) ){\ 252 zListCellBind( zListHead(p), zListTail(a) );\ 253 zListCellBind( zListRoot(a), zListTail(p) );\ 254 zListSize(a) += zListSize(p);\ 259 #define zListAppend(a,p) zListAppendZ(a,p) 262 #define zListMove(src,dst) do{\ 263 zListCellBind( zListRoot(dst), zListTail(src) );\ 264 zListCellBind( zListHead(src), zListRoot(dst) );\ 265 zListSetSize( dst, zListSize(src) );\ 271 #define zListSwap(cell_t,l1,l2) do{\ 273 zListCellSwap( cell_t, zListRoot(l1), zListRoot(l2) );\ 274 __tmpsize = zListSize(l1);\ 275 zListSetSize( l1, zListSize(l2) );\ 276 zListSetSize( l2, __tmpsize );\ 281 #define zListToHead(l,c) \ 282 for( ; (c)!=zListRoot(l); (c)=zListCellNext(c) ) 285 #define zListToTail(l,c) \ 286 for( ; (c)!=zListRoot(l); (c)=zListCellPrev(c) ) 289 #define zListForEach(l,c) \ 290 for( (c)=zListTail(l); (c)!=zListRoot(l); (c)=zListCellNext(c) ) 293 #define zListForEachRew(l,c) \ 294 for( (c)=zListHead(l); (c)!=zListRoot(l); (c)=zListCellPrev(c) ) 299 #define zListItem(list,i,cp) do{\ 300 int __z_list_item_tmp;\ 302 if( (i) >= 0 && (i) < zListSize(list) ){\ 303 if( (i) <= zListSize(list) - (i) ){\ 304 __z_list_item_tmp = 0;\ 305 zListForEach( list, *(cp) )\ 306 if( __z_list_item_tmp++ == (i) ) break;\ 308 __z_list_item_tmp = zListSize( list );\ 309 zListForEachRew( list, *(cp) )\ 310 if( --__z_list_item_tmp == (i) ) break;\ 333 #define zListQuickSortDef(list_t, cell_t) \ 334 static void _##list_t##InnerQuickSort(cell_t *head, cell_t *tail, int (*cmp)(void*,void*,void*), void *priv);\ 335 void _##list_t##InnerQuickSort(cell_t *head, cell_t *tail, int (*cmp)(void*,void*,void*), void *priv)\ 337 cell_t *hp, *tp, *pivot, *p;\ 339 for( pivot=hp=head, tp=tail; ; ){\ 341 while( cmp( (void *)hp, (void *)pivot, priv ) > 0 && hp != tail )\ 342 hp = zListCellPrev( hp );\ 343 while( cmp( (void *)tp, (void *)pivot, priv ) < 0 && tp != head )\ 344 tp = zListCellNext( tp );\ 345 if( hp == tp || hp == zListCellPrev( tp ) )\ 347 zListCellSwap( cell_t, hp, tp );\ 349 if( hp == head ) head = tp;\ 350 if( tail == tp ) tail = hp;\ 351 p = zListCellNext( hp );\ 352 hp = zListCellPrev( tp );\ 356 _##list_t##InnerQuickSort( head, zListCellNext(hp), cmp, priv );\ 358 _##list_t##InnerQuickSort( zListCellPrev(tp), tail, cmp, priv );\ 361 list_t *list_t##QuickSort(list_t *list, int (* cmp)(void*,void*,void*), void *priv)\ 363 _##list_t##InnerQuickSort( zListHead(list), zListTail(list), cmp, priv );\ 392 #define zListFPrint(f,l) _zListFPrint( f, (zList *)(l) ) 393 #define zListPrint(l) zListFPrint( stdout, l ) 401 #define zStackPush(s,v) zListInsertHead(s,v) 403 #define zStackPop(s,c) zListDeleteHead(s,c) 406 #define zQueueEnqueue(q,v) zListInsertTail(q,v) 408 #define zQueueDequeue(q,c) zListDeleteHead(q,c) Definition: zeda_list.h:60
Definition: zeda_list.h:413
a list of integer numbers
Definition: zeda_list.h:413
#define __END_DECLS
Definition: zeda_defs.h:30
bool zIntListAdd(zIntList *list, int i)
a list of integer numbers
#define zListPrint(l)
Definition: zeda_list.h:393
#define __BEGIN_DECLS
Definition: zeda_defs.h:26
#define zListClass(list_t, cell_t, data_t)
generate bidirectional ring list class.
Definition: zeda_list.h:48
#define __EXPORT
Definition: zeda_compat.h:32
Definition: zeda_list.h:60
void _zListFPrint(FILE *fp, zList *list)
print connection information of a list.