-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathteds_internaliterator.h
42 lines (37 loc) · 1.15 KB
/
teds_internaliterator.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
#ifndef TEDS_INTERNALITERATOR_H
#define TEDS_INTERNALITERATOR_H
typedef struct _teds_intrusive_dllist_node {
struct _teds_intrusive_dllist_node *prev;
struct _teds_intrusive_dllist_node *next;
} teds_intrusive_dllist_node;
typedef struct _teds_intrusive_dllist {
struct _teds_intrusive_dllist_node *first;
} teds_intrusive_dllist;
static zend_always_inline void teds_intrusive_dllist_prepend(teds_intrusive_dllist *list, teds_intrusive_dllist_node *node) {
teds_intrusive_dllist_node *first = list->first;
ZEND_ASSERT(node != first);
node->next = first;
node->prev = NULL;
list->first = node;
if (first) {
ZEND_ASSERT(first->prev == NULL);
first->prev = node;
}
}
static zend_always_inline void teds_intrusive_dllist_remove(teds_intrusive_dllist *list, const teds_intrusive_dllist_node *node) {
teds_intrusive_dllist_node *next = node->next;
teds_intrusive_dllist_node *prev = node->prev;
ZEND_ASSERT(node != next);
ZEND_ASSERT(node != prev);
ZEND_ASSERT(next != prev || next == NULL);
if (next) {
next->prev = prev;
}
if (list->first == node) {
list->first = next;
ZEND_ASSERT(prev == NULL);
} else if (prev) {
prev->next = next;
}
}
#endif