home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / include / list.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-06  |  1.2 KB  |  51 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1986, 1988 Regents of the University of California
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /* list.h -- definitions for lists  */
  9.  
  10. #ifndef list_h
  11. #define list_h
  12.  
  13. #include "set.h"
  14. #include "digraph.h"
  15.  
  16. typedef struct item ITEM, LIST;
  17. struct item
  18. {
  19.    int key;    /* key for this item */
  20.    SET *set;   /* set of keys */
  21.    ITEM *prev; /* previous item */
  22.    ITEM *next; /* next item */
  23. };
  24.  
  25.  
  26. #define    init_list(list)        list = NULL
  27.  
  28. #define    add_item(list, _key, _set)    \
  29.    { LIST *l;\
  30.       new(l, LIST); l->next = list; list = l;\
  31.       if (l->next != NULL) l->next->prev = l;\
  32.       l->key = _key; init_set(l->set); copy_set(l->set, _set);\
  33.    }
  34.  
  35. #define    remove_item(list, item)    \
  36.    { if(item == list) list = item->next;\
  37.      else item->prev->next = item->next;\
  38.      if (item->next != NULL) item->next->prev = item->prev;\
  39.      dispose(item); item = NULL;\
  40.    }
  41.  
  42. #define each_item(list, item)    \
  43.    { ITEM *_next; for (item = list; item != NULL; item = _next) {\
  44.       _next = item->next;   /* in case of remove_item */
  45.  
  46. #define    empty_list(list)    (list == NULL)
  47. #define Key(item)    item->key
  48. #define    Set(item)    item->set
  49.  
  50. #endif
  51.