blob: 6e3ba209411bac7675291db5a6205f44701c0020 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* This file is part of libdom.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
*
* This file contains the list structure used to compose lists.
*
* Note: This is a implementation of a doubld-linked cyclar list.
*/
#ifndef dom_utils_list_h_
#define dom_utils_list_h_
#include <stddef.h>
struct list_entry {
struct list_entry *prev;
struct list_entry *next;
};
/**
* Initialise a list_entry structure
*
* \param ent The entry to initialise
*/
static inline void list_init(struct list_entry *ent)
{
ent->prev = ent;
ent->next = ent;
}
/**
* Append a new list_entry after the list
*
* \param head The list header
* \param new The new entry
*/
static inline void list_append(struct list_entry *head, struct list_entry *new)
{
new->next = head;
new->prev = head->prev;
head->prev->next = new;
head->prev = new;
}
/**
* Delete a list_entry from the list
*
* \param entry The entry need to be deleted from the list
*/
static inline void list_del(struct list_entry *ent)
{
ent->prev->next = ent->next;
ent->next->prev = ent->prev;
ent->prev = ent;
ent->next = ent;
}
#endif
|