File: lists.h

package info (click to toggle)
evms 2.5.2-1.sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 14,248 kB
  • ctags: 15,488
  • sloc: ansic: 201,340; perl: 12,421; sh: 4,262; makefile: 1,516; yacc: 316; sed: 16
file content (133 lines) | stat: -rw-r--r-- 3,738 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 *
 *   (C) Copyright IBM Corp. 2002, 2003
 *
 *   This program is free software;  you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program;  if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Module: list.h
 *
 */

#ifndef EVMS_LISTS_H_INCLUDED
#define EVMS_LISTS_H_INCLUDED 1

typedef struct links_s {
	struct links_s * next;
	struct links_s * prev;
} links_t;

typedef struct anchor_s {
	links_t links;
	uint    count;
} anchor_t;

typedef struct element_s {
	links_t    links;
	void     * thing;
	anchor_t * anchor;
} element_t;


/* For declaring and initializing static lists. */
#define STATIC_LIST_DECL(list_name) anchor_t list_name = {links: {next: &list_name.links,	\
								  prev: &list_name.links},	\
							  count: 0}

/* For initializing dynamic allocations of lists. */
#define LIST_INIT(list) {		\
	list.links.next = &list.links;	\
        list.links.prev = &list.links;	\
	list.count = 0;			\
}


/*
 * Since anchors and elements start with links, pointers to anchors, pointers
 * to elements and pointers to links are all pointing to the same thing.
 * Sometimes the code needs to cast from one to the other.  These macros
 * assist in doing that and make the code more readable.
 */
#define LINK_PTR(thing)    ((links_t *) (thing))
#define ANCHOR_PTR(thing)  ((anchor_t *) (thing))
#define ELEMENT_PTR(thing) ((element_t *) (thing))


extern anchor_t * allocate_list(void);

extern uint list_count(anchor_t * anchor);

extern boolean list_empty(anchor_t * anchor);

extern element_t * find_in_list(anchor_t         * anchor,
				void             * thing,
				compare_function_t compare,
				void             * user_data);

extern void delete_all_elements(anchor_t * anchor);

extern void destroy_list(anchor_t * anchor);

extern void * get_thing(element_t * element);

extern element_t * next_element(element_t * element);

extern void * next_thing(element_t * * element);

extern element_t * previous_element(element_t * element);

extern void * previous_thing(element_t * * element);

extern void * first_thing(anchor_t    * anchor,
			  element_t * * element);

extern void * last_thing(anchor_t    * anchor,
			 element_t * * element);

extern element_t * insert_element(anchor_t     * anchor,
				  element_t    * element,
				  insert_flags_t flags,
				  element_t    * ref_element);

extern element_t * insert_thing(anchor_t     * anchor,
				void         * thing,
				insert_flags_t flags,
				element_t    * ref_element);

extern void remove_element(element_t * element);

extern void delete_element(element_t * element);

extern void remove_thing(anchor_t * anchor,
			 void     * thing);

extern int replace_thing(anchor_t * anchor,
			 void     * thing,
			 void     * new_thing);

extern anchor_t * copy_list(anchor_t * anchor);

extern int concatenate_lists(anchor_t * anchor1,
			     anchor_t * anchor2);

extern int merge_lists(anchor_t         * anchor1,
		       anchor_t         * anchor2,
		       compare_function_t compare,
		       void             * user_data);

extern int sort_list(anchor_t         * anchor,
		     compare_function_t compare,
		     void             * user_data);

#endif