Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of libdom.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
  6.  *
  7.  * This file contains the list structure used to compose lists.
  8.  *
  9.  * Note: This is a implementation of a doubld-linked cyclar list.
  10.  */
  11.  
  12. #ifndef dom_utils_list_h_
  13. #define dom_utils_list_h_
  14.  
  15. #include <stddef.h>
  16.  
  17. struct list_entry {
  18.         struct list_entry *prev;
  19.         struct list_entry *next;
  20. };
  21.  
  22. /**
  23.  * Initialise a list_entry structure
  24.  *
  25.  * \param ent  The entry to initialise
  26.  */
  27. static inline void list_init(struct list_entry *ent)
  28. {
  29.         ent->prev = ent;
  30.         ent->next = ent;
  31. }
  32.  
  33. /**
  34.  * Append a new list_entry after the list
  35.  *
  36.  * \param head  The list header
  37.  * \param new   The new entry
  38.  */
  39. static inline void list_append(struct list_entry *head, struct list_entry *new)
  40. {
  41.         new->next = head;
  42.         new->prev = head->prev;
  43.         head->prev->next = new;
  44.         head->prev = new;
  45. }
  46.  
  47. /**
  48.  * Delete a list_entry from the list
  49.  *
  50.  * \param entry  The entry need to be deleted from the list
  51.  */
  52. static inline void list_del(struct list_entry *ent)
  53. {
  54.         ent->prev->next = ent->next;
  55.         ent->next->prev = ent->prev;
  56.  
  57.         ent->prev = ent;
  58.         ent->next = ent;
  59. }
  60.  
  61. #endif
  62.