2017-05-29 10:56:00 +00:00
|
|
|
/* list.h - Double link list implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
void init_list_head(struct list_head *head) {
|
|
|
|
head->next = head;
|
|
|
|
head->prev = head;
|
|
|
|
}
|
|
|
|
|
|
|
|
void list_insert(struct list_head *pos, struct list_head *node) {
|
|
|
|
// First construct our new node
|
|
|
|
node->next = pos->next;
|
|
|
|
node->prev = pos;
|
|
|
|
// Maintain the list
|
|
|
|
pos->next->prev = node;
|
|
|
|
pos->next = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void list_insert_end(struct list_head *head, struct list_head *node) {
|
|
|
|
list_insert(head->prev, node);
|
|
|
|
}
|
|
|
|
|
2017-07-02 09:47:07 +00:00
|
|
|
struct list_head *list_pop(struct list_head *pos) {
|
|
|
|
struct list_head *ret;
|
|
|
|
ret = pos->prev;
|
2017-05-29 10:56:00 +00:00
|
|
|
// Maintain the list
|
|
|
|
pos->prev->next = pos->next;
|
|
|
|
pos->next->prev = pos->prev;
|
|
|
|
// Remove references
|
|
|
|
pos->next = pos;
|
|
|
|
pos->prev = pos;
|
2017-07-02 09:47:07 +00:00
|
|
|
// Return the previous node in the list
|
|
|
|
return ret;
|
2017-05-29 10:56:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-02 09:47:07 +00:00
|
|
|
struct list_head *list_pop_end(struct list_head *head) {
|
2017-05-29 10:56:00 +00:00
|
|
|
return list_pop(head->prev);
|
|
|
|
}
|