import
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#ifndef INCLUDED_OS_LIST_H
|
||||
#define INCLUDED_OS_LIST_H
|
||||
|
||||
#ifndef INCLUDED_OS_TYPES_H
|
||||
#include <os_types.h>
|
||||
#endif /*INCLUDED_OS_TYPES_H*/
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct os_list_node_t{
|
||||
struct os_list_node_t* prev;
|
||||
struct os_list_node_t* next;
|
||||
}os_list_node_t;
|
||||
|
||||
typedef os_list_node_t os_list_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define os_list_prev(L) (L)->prev
|
||||
#define os_list_next(L) (L)->next
|
||||
#define os_list_prev_next(L) os_list_next(os_list_prev(L))
|
||||
#define os_list_next_prev(L) os_list_prev(os_list_next(L))
|
||||
#define os_list_next_next(L) os_list_next(os_list_next(L))
|
||||
|
||||
#define os_list_init(L) (os_list_prev(L)=os_list_next(L)=(os_list_node_t*)(L))
|
||||
#define os_list_is_empty(L) ((os_list_prev(L)==(L))?OS_TRUE:OS_FALSE)
|
||||
#define os_list_is_one(L) (os_list_next_next(L)==(L))
|
||||
|
||||
// Lp -- N -- L
|
||||
#define os_list_insert_before(L, N) \
|
||||
do{ \
|
||||
os_list_prev_next(L) = (os_list_node_t*)(N); \
|
||||
os_list_prev(N) = os_list_prev(L); \
|
||||
os_list_prev(L) = (os_list_node_t*)(N); \
|
||||
os_list_next(N) = (os_list_node_t*)(L); \
|
||||
}while(0)
|
||||
|
||||
// L -- N -- Ln
|
||||
#define os_list_insert_after(L, N) \
|
||||
do{ \
|
||||
os_list_next_prev(L) = (os_list_node_t*)(N); \
|
||||
os_list_next(N) = os_list_next(L); \
|
||||
os_list_next(L) = (os_list_node_t*)(N); \
|
||||
os_list_prev(N) = (os_list_node_t*)(L); \
|
||||
}while(0)
|
||||
|
||||
#define os_list_remove(N) \
|
||||
do{ \
|
||||
os_list_prev_next(N) = os_list_next(N); \
|
||||
os_list_next_prev(N) = os_list_prev(N); \
|
||||
os_list_init(N); \
|
||||
}while(0)
|
||||
|
||||
|
||||
// Lp -- L -- Ln -- Lp
|
||||
// Np -- N -- Nn -- Np
|
||||
// 1. Lp.next = Nn : L --> Ln --> Lp -next-> Nn -next-> Np --> N --> Nn
|
||||
// 2. N.head.prev = L.tail: Lp <-prev- Nn
|
||||
// 3. N.tail.next = L Np -next-> L
|
||||
// 4. L.prev = N.prev Np <-prev- L
|
||||
#define os_list_join(L, N) \
|
||||
do{ \
|
||||
if(os_list_is_empty(N)){ \
|
||||
break; \
|
||||
} \
|
||||
os_list_prev_next(L) = os_list_next(N); \
|
||||
os_list_next_prev(N) = os_list_prev(L); \
|
||||
os_list_prev_next(N) = (L); \
|
||||
os_list_prev(L) = os_list_prev(N); \
|
||||
os_list_init(N); \
|
||||
}while(0)
|
||||
|
||||
|
||||
#define os_list_member_of(ptr, type, member) \
|
||||
((type *)( (char *)ptr - ((os_size_t)&((type *)0)->member) ))
|
||||
|
||||
#endif /*INCLUDED_OS_LIST_H*/
|
||||
Reference in New Issue
Block a user