9 struct _listpool
*const pool
;
12 struct _element
*next
;
13 struct _element
*prev
;
19 struct _listpool
*const pool
;
20 struct _element
*head
;
21 struct _element
*tail
;
30 listpool
listpool_create (size_t numelms
, size_t numlsts
)
32 listpool result
= (listpool
) xmalloc (sizeof (struct _listpool
));
33 result
->elmpool
= fixedpool_create (sizeof (struct _element
), numelms
, 0);
34 result
->lstpool
= fixedpool_create (sizeof (struct _list
), numlsts
, 0);
38 void listpool_destroy (listpool pool
)
40 fixedpool_destroy (pool
->lstpool
, NULL
, NULL
);
41 fixedpool_destroy (pool
->elmpool
, NULL
, NULL
);
46 list
list_alloc (listpool pool
)
50 l
= fixedpool_alloc (pool
->lstpool
);
52 ptr
= (listpool
*) &l
->pool
;
54 l
->head
= l
->tail
= NULL
;
59 void list_free (list l
)
64 fixedpool_free (pool
->lstpool
, l
);
67 void list_reset (list l
)
70 for (el
= l
->head
; el
; el
= ne
) {
74 l
->head
= l
->tail
= NULL
;
78 int list_size (list l
)
83 element
list_head (list l
)
88 void *list_headvalue (list l
)
91 return element_getvalue (list_head (l
));
95 element
list_tail (list l
)
100 void *list_tailvalue (list l
)
103 return element_getvalue (list_tail (l
));
107 element
list_inserthead (list l
, void *val
)
109 element el
= element_alloc (l
->pool
, val
);
113 l
->head
= l
->tail
= el
;
115 element_insertbefore (l
->head
, el
);
120 element
list_inserttail (list l
, void *val
)
122 element el
= element_alloc (l
->pool
, val
);
126 l
->head
= l
->tail
= el
;
128 element_insertafter (l
->tail
, el
);
133 void *list_removehead (list l
)
137 if (!el
) return NULL
;
138 return element_free (el
);
141 void *list_removetail (list l
)
145 if (!el
) return NULL
;
146 return element_free (el
);
151 element
element_alloc (listpool pool
, void *val
)
155 el
= fixedpool_alloc (pool
->elmpool
);
157 ptr
= (listpool
*) &el
->pool
;
167 void element_remove (element el
)
173 if (l
) l
->tail
= el
->prev
;
175 el
->next
->prev
= el
->prev
;
179 if (l
) l
->head
= el
->next
;
181 el
->prev
->next
= el
->next
;
183 el
->next
= el
->prev
= NULL
;
187 void *element_free (element el
)
191 val
= element_getvalue (el
);
194 fixedpool_free (pool
->elmpool
, el
);
198 void *element_getvalue (element el
)
203 void element_setvalue (element el
, void *val
)
208 element
element_next (element el
)
213 element
element_previous (element el
)
219 void element_insertbefore (element el
, element inserted
)
221 inserted
->lst
= el
->lst
;
222 inserted
->prev
= el
->prev
;
224 if (el
->prev
) el
->prev
->next
= inserted
;
228 inserted
->lst
->size
++;
229 if (!inserted
->prev
) inserted
->lst
->head
= inserted
;
233 void element_insertafter (element el
, element inserted
)
235 inserted
->lst
= el
->lst
;
236 inserted
->next
= el
->next
;
238 if (el
->next
) el
->next
->prev
= inserted
;
242 inserted
->lst
->size
++;
243 if (!inserted
->next
) inserted
->lst
->tail
= inserted
;