2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
12 #include <gclib/gclib.h>
16 __dlist_entry_t
* one
;
17 __dlist_entry_t
* d_del
;
18 if (! head
|| dont_free
)
31 char * DList::init (__dlist_entry_t
* one
)
38 char * DList::add_head (char * one
)
40 __dlist_entry_t
*entry
;
45 entry
= new_one (one
);
53 char * DList::add_tail (char * one
)
55 __dlist_entry_t
* entry
;
59 entry
= new_one (one
);
67 void DList::rm (__dlist_entry_t
* one
)
73 if (one
== tail
&& one
== head
) {
94 one
->prev
->next
= one
->next
;
95 one
->next
->prev
= one
->prev
;
99 void DList::detach (__dlist_entry_t
* one
)
104 if (one
== tail
&& one
== head
) {
122 one
->prev
->next
= one
->next
;
123 one
->next
->prev
= one
->prev
;
127 char * DList::add_after (__dlist_entry_t
*two
, char * one
)
129 __dlist_entry_t
* entry
;
135 return add_tail (one
);
137 entry
= new_one (one
);
140 entry
->next
= two
->next
;
141 two
->next
->prev
= entry
;
149 char * DList::add_before (__dlist_entry_t
*two
, char * one
)
151 __dlist_entry_t
* entry
;
157 return add_head (one
);
159 entry
= new_one (one
);
162 entry
->prev
= two
->prev
;
163 two
->prev
->next
= entry
;
171 void DList::foreach (Dfunc_t f
)
173 __dlist_entry_t
* entry
;
176 f((void *) entry
->data
);
181 char * DList::add_entry_head (__dlist_entry_t
* one
)
192 char * DList::add_entry_tail (__dlist_entry_t
* one
)
203 __dlist_entry_t
* DList::get_entry_at (int N
)
205 __dlist_entry_t
* one
;
209 while ((one
= one
->next
) && one
&& --N
);
213 char * DList::get_at (int N
)
215 __dlist_entry_t
* one
;
216 one
= get_entry_at (N
);