source: doc/theses/mike_brooks_MMath/benchmarks/list/fx-lq-list.h@ b28ce93

Last change on this file since b28ce93 was 0b66ef9, checked in by Michael Brooks <mlbrooks@…>, 2 years ago

Add linked list performance experiment

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include <sys/queue.h>
2#include <assert.h>
3#include <stddef.h>
4
5#define HEADNAME_(S) S ## Head
6
7#define BFX_INTRUSION(S) LIST_ENTRY(S) xx;
8#define BFX_EXTRUSION_DECL(S)
9#define BFX_EXTRUSION_FOLLOWUP(S) LIST_HEAD(HEADNAME_(S), S);
10#define BFX_LIST_HEAD_T(S) struct HEADNAME_(S)
11#define BFX_LISTED_ELEM_T(S) S*
12
13#define BFX_INSERT_FIRST(S, lst, item) ({LIST_INSERT_HEAD(&lst, &item, xx); &item;})
14#define BFX_INSERT_LAST(S, lst, item) assert(false&&"unimplemented INSERT_LAST on lq-list")
15#define BFX_INSERT_BEFORE(S, lst, item, refIter) ({LIST_INSERT_BEFORE(refIter, &item, xx); &item;})
16#define BFX_INSERT_AFTER(S, lst, item, refIter) ({LIST_INSERT_AFTER(refIter, &item, xx); &item;})
17#define BFX_REMOVE_FIRST(S, lst) LIST_REMOVE( LIST_FIRST( &lst ), xx )
18#define BFX_REMOVE_LAST(S, lst) assert(false&&"unimplemented REMOVE_LAST on lq-list")
19#define BFX_REMOVE_HERE(S, lst, refIter) LIST_REMOVE( refIter, xx )
20#define BFX_INIT(S, lst) LIST_INIT(&lst);
21
22#define BFX_GET_AFTER(S, lst, iter) LIST_NEXT(iter, xx)
23#define BFX_GET_BEFORE(S, lst, iter) HACK_UNSUPPORTED_PREV(S, lst, iter, xx)
24#define BFX_IS_VALID_POS(S, lst, iter) ((iter)!=NULL)
25#define BFX_DEREF_POS(S, lst, iter) (iter)
26
27#define HACK_UNSUPPORTED_PREV(S, lst, iter, NAME) ({ \
28 S * answer = NULL; \
29 S ** linkAtMe = (iter)->NAME.le_prev; \
30 if ( &(lst) != (BFX_LIST_HEAD_T(S)*)linkAtMe ) { \
31 answer = (S*)( (char*)linkAtMe - offsetof(S, NAME) ); \
32 } \
33 answer; \
34})
35
36#if 0
37void bobs_moveNext() { observedItem = ((observedItem)->xx.le_next); }
38struct { struct B_UserItem *le_next; struct B_UserItem **le_prev; } xx;
39struct { struct B_UserItem *tqe_next; struct B_UserItem * *tqe_prev; } xx;
40
41void bobs_movePrev() {
42 observedItem = (*(((struct B_UserItemHead *)((observedItem)->xx.tqe_prev))->tqh_last)); }
43
44#endif
Note: See TracBrowser for help on using the repository browser.