-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
44 lines (35 loc) · 978 Bytes
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* 리스트 노드를 데이터가 포함하는 방식으로 구현한
* 간단한 리스트
*/
#ifndef __LIST_H__
#define __LIST_H__
#include <stddef.h>
struct list_node {
struct list_node *prev;
struct list_node *next;
};
static inline void list_init(struct list_node *head)
{
head->prev = head;
head->next = head;
}
static inline void list_insert(struct list_node *new, struct list_node *prev)
{
struct list_node *next = prev->next;
prev->next = new;
new->prev = prev;
new->next = next;
next->prev = new;
}
static inline void list_delete(struct list_node *target)
{
target->prev->next = target->next;
target->next->prev = target->prev;
}
#define container_of(ptr, type, member)\
(type *)((char *)ptr - offsetof(type, member))
#define for_each_list_node(head)\
for (struct list_node *node = head.next;\
node != &head; node = node->next)
#endif