2 functions for static list implimentation.
10 #define likely(x) __builtin_expect((x),1)
11 #define unlikely(x) __builtin_expect((x),0)
13 #define LIST_ERROR(...) fprintf(stderr,"ERROR: %s:%s():%d \n",__FILE__,__FUNCTION__,__LINE__);
16 list_base_t
list_pop_front(list_t
*l
) {
17 if ( unlikely( list_empty(l
) ) ) {
22 list_base_t head
= l
->buffer
[ l
->first
];
25 if ( l
->first
>= l
->sz
)
33 list_base_t
list_pop_back(list_t
*l
) {
34 if ( unlikely( list_empty(l
) ) ) {
42 if ( l
->end
>= l
->sz
) // if overflowed
45 list_base_t last
= l
->buffer
[l
->end
];
50 list_error_t
list_push_front(list_t
*l
, list_base_t x
) {
51 if ( unlikely( list_full(l
) ) ){
59 if ( l
->first
>= l
->sz
) // if overflowed
62 l
->buffer
[ l
->first
] = x
;
67 list_error_t
list_push_back(list_t
*l
, list_base_t x
) {
68 if ( unlikely( list_full(l
) ) ){
75 l
->buffer
[ l
->end
] = x
;
78 if ( l
->end
>= l
->sz
)
84 list_error_t
list_push_back_o(list_t
*l
, list_base_t x
) {
85 l
->buffer
[ l
->end
] = x
;
88 if ( l
->end
>= l
->sz
)
97 list_base_t
list_peek_front(list_t
*l
) {
98 if ( unlikely( list_empty(l
) ) ) {
103 return l
->buffer
[l
->first
];
105 list_base_t
list_peek_back(list_t
*l
) {
106 if ( unlikely( list_empty(l
) ) ) {
111 list_index_t last
= l
->end
-1;
116 return l
->buffer
[last
];
121 list_base_t
list_peek(list_t
*l
, list_index_t index
) {
122 if ( unlikely( index
> l
->ct
) ) {
127 uint8_t sum
= l
->first
+ index
;
128 uint8_t diff
= l
->first
- index
;
130 if ( sum
< l
->first
) {
131 //XXX: damn overflow.
134 if ( sum
>= l
->sz
) {
139 void list_flush(list_t
*list
) {
140 list
->first
= list
->end
;
144 bool list_empty(list_t
*list
) {
145 if ( unlikely( list
->ct
== 0 ) ) return true;
149 bool list_full(list_t
*list
) {
150 if ( unlikely( list
->ct
>= list
->sz
) ) return true;