#ifndef lib_list_h #define lib_list_h /* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file lib/list.h * \brief Double linked lists. * \ingroup lib */ /** Double linked list node. */ struct list_node_t { /** Pointer to next node. */ struct list_node_t *next; /** Pointer to previous node. */ struct list_node_t *prev; }; typedef struct list_node_t list_node_t; /** Double linked list. */ struct list_t { /** List NIL element. */ list_node_t nil; }; typedef struct list_t list_t; BEGIN_DECLS /** * Initialise a double linked list. * \param list the list to initialise */ void list_init (list_t *list); /** * Initialise a list node. * \param node the node to initialise */ void list_init_node (list_node_t *node); /** * Return the first node. * \param list the list * \return the first node */ list_node_t * list_begin (list_t *list); /** * Return past the last node. * \param list the list * \return the node after the last */ list_node_t * list_end (list_t *list); /** * Return last node to backward iteration. * \param list the list * \return the last node */ list_node_t * list_rbegin (list_t *list); /** * Return before the first node. * \param list the list * \return the node before the first */ list_node_t * list_rend (list_t *list); /** * Return the next node. * \param node the current node * \return the node after the current one */ list_node_t * list_next (list_node_t *node); /** * Return the previous node. * \param node the current node * \return the node before the current one */ list_node_t * list_prev (list_node_t *node); /** * Is the list empty? * \param list the list * \return true if empty */ bool list_empty (list_t *list); /** * Push a node to the back (end) of a list. * \param list the list * \param node the node to push */ void list_push_back (list_t *list, list_node_t *node); /** * Push a node to the front of a list. * \param list the list * \param node the node to push */ void list_push_front (list_t *list, list_node_t *node); /** * Pop a node from the back (end) of a list. * \param list the list * \return the popped node */ list_node_t * list_pop_back (list_t *list); /** * Pop a node from the front of a list. * \param list the list * \return the popped node */ list_node_t * list_pop_front (list_t *list); /** * Remove a node from a list. * \param list the list * \param node the node to remove */ void list_remove (list_t *list, list_node_t *node); /** * Insert a node into a list. * \param list the list * \param before node before which to insert * \param node node to insert */ void list_insert (list_t *list, list_node_t *before, list_node_t *node); /** * Push a range [first, last) to the back (end) of a list. * \param to list to push to * \param from list to remove from * \param first first node to push * \param last node after the last one to push */ void list_push_back_range (list_t *to, list_t *from, list_node_t *first, list_node_t *last); /** * Push a range [first, last) to the front of a list. * \param to list to push to * \param from list to remove from * \param first first node to push * \param last node after the last one to push */ void list_push_front_range (list_t *to, list_t *from, list_node_t *first, list_node_t *last); /** * Insert a range [first, last) to a list * \param to list to insert to * \param from list to remove from * \param before node before which to insert * \param first first node to insert * \param last node after the last one to insert */ void list_insert_range (list_t *to, list_t *from, list_node_t *before, list_node_t *first, list_node_t *last); END_DECLS #endif /* lib_list_h */