English translation
[cacao.git] / src / toolbox / chain.h
1 /************************* toolbox/chain.h *************************************
2
3         Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
4
5         See file COPYRIGHT for information on usage and disclaimer of warranties
6
7         Management of doubly linked lists with external linking
8
9         Authors: Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
10
11         Last Change: 1996/10/03
12
13 *******************************************************************************/
14
15 #ifndef CHAIN_H
16 #define CHAIN_H
17
18 typedef struct chainlink {          /* structure for list element */
19         struct chainlink *next,*prev;
20         void *element;
21         } chainlink;
22
23 typedef struct chain {              /* structure for list */
24         int  usedump;   
25
26         chainlink *first,*last;
27         chainlink *active;
28         } chain;
29
30
31 chain *chain_new ();
32 chain *chain_dnew ();
33 void chain_free(chain *c);
34
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);
39
40 void chain_remove(chain *c);
41 void *chain_remove_go_prev(chain *c);
42 void chain_removespecific(chain *c, void *element);
43
44 void *chain_next(chain *c);
45 void *chain_prev(chain *c);
46 void *chain_this(chain *c);
47
48 void *chain_first(chain *c);
49 void *chain_last(chain *c);
50
51
52 /*
53 --------------------------- interface description ------------------------
54
55 Usage of these functions for list management is possible without additional preparation in the element structures, as opposed to the module 'list'.
56
57 Consequently, the functions are a little slower and need more memory.
58
59 A new list is created with
60         chain_new
61 or  chain_dnew.
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.
66
67 After usage, a list can be freed with
68         chain_free.
69 (use only if the list was created with 'chain_new')
70
71
72 Adding elements is easy with:
73         chain_addafter, chain_addlast, chain_addbefore, chain_addfirst          
74         
75 Search the list with:
76         chain_first, chain_last, chain_prev, chain_next, chain_this
77         
78 Delete elements from the list:
79         chain_remove, chain_remove_go_prev, chain_removespecific
80         
81         
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.
86
87 */
88
89 #endif