1 /************************* toolbox/chain.h *************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Management of doubly linked lists with external linking
9 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
11 Last Change: 1996/10/03
13 *******************************************************************************/
18 typedef struct chainlink { /* structure for list element */
19 struct chainlink *next,*prev;
23 typedef struct chain { /* structure for list */
26 chainlink *first,*last;
33 void chain_free(chain *c);
35 void chain_addafter(chain *c, void *element);
36 void chain_addbefore(chain *c, void *element);
37 void chain_addlast (chain *c, void *element);
38 void chain_addfirst (chain *c, void *element);
40 void chain_remove(chain *c);
41 void *chain_remove_go_prev(chain *c);
42 void chain_removespecific(chain *c, void *element);
44 void *chain_next(chain *c);
45 void *chain_prev(chain *c);
46 void *chain_this(chain *c);
48 void *chain_first(chain *c);
49 void *chain_last(chain *c);
53 --------------------------- interface description ------------------------
55 Usage of these functions for list management is possible without additional preparation in the element structures, as opposed to the module 'list'.
57 Consequently, the functions are a little slower and need more memory.
59 A new list is created with
62 The latter allocates all additional data structures on the dump memory (faster)
63 for which no explicit freeing is necessary after the processing. Care needs to
64 be taken to not accidentally free parts of these structures by calling
65 'dump_release' too early.
67 After usage, a list can be freed with
69 (use only if the list was created with 'chain_new')
72 Adding elements is easy with:
73 chain_addafter, chain_addlast, chain_addbefore, chain_addfirst
76 chain_first, chain_last, chain_prev, chain_next, chain_this
78 Delete elements from the list:
79 chain_remove, chain_remove_go_prev, chain_removespecific
82 ATTENTION: As mentioned earlier, there are no pointers to the list or to other
83 nodes inside the list elements, so list elements cannot be used as pointers
84 into the list. Therefore a 'cursor' is used to make one element current. Every
85 insertion/deletion occurs at a position relative to this cursor.