Project
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1
22#ifndef __LIST__
23
24#define __LIST__
25
26#ifndef TRUE
27 #define TRUE 1
28 #define FALSE 0
29#endif
30
31struct list_node {
32 //pointer to the content of the node
33 void *data;
34 //pointer to previous node
36 //pointer to next node
37 struct list_node *next;
38};
39
40struct list {
41 //first node
43 //last node
44 struct list_node *last;
45 //size of the search key in bytes
47 //element count
48 int count;
49};
50
51/*
52 * Initialize a list, with a specified key size
53 */
54void init_list(struct list *l,int keysize);
55
56/*
57 * Add a new element at the end of the list
58 * return the pointer to the new node
59 */
60struct list_node *add_elem(struct list *l,void *elem);
61
62/*
63 * Delete a node
64 */
65void delete_node(struct list *l,struct list_node *node);
66
67/*
68 * Delete a node from the list, even the content pointed by it
69 * Use only when the content is a dynamically allocated pointer
70 */
71void destroy_node(struct list *l,struct list_node *node);
72
73/*
74 * Check whether a list is empty or not
75 */
76int is_empty_list(struct list *l);
77
78/*
79 * Return the element count of the list
80 */
81int get_list_count(struct list *l);
82
83/*
84 * Return the first element (content of the node) from the list
85 */
86void *first_elem(struct list *l);
87
88/*
89 * Return the first node from the list
90 */
91struct list_node *first_node(struct list *l);
92
93/*
94 * Return the last element (content of the node) from the list
95 */
96void *last_elem(struct list *l);
97
98/*
99 * Return the last node from the list
100 */
101struct list_node *last_node(struct list *l);
102
103/*
104 * Search an element of the list by content
105 * the comparison is done from the specified offset and for a specified length
106 * if offset=0, the comparison starts from the address pointed by data
107 * if length=0, default keysize is used for length
108 * if the element is found, return the node address
109 * else return NULL
110 */
111struct list_node *xlocate_node(struct list *l,void *elem,int offset,int length);
112
113/*
114 * The same of xlocate_node(), but return the content of the node
115 */
116void *xlocate_elem(struct list *l,void *elem,int offset,int length);
117
118/*
119 * The same of calling xlocate_node() with offset=0 and length=0
120 */
121struct list_node *locate_node(struct list *l,void *elem);
122
123/*
124 * The same of locate_node, but return the content of the node
125 */
126void *locate_elem(struct list *l,void *elem);
127
128/*
129 * Delete all the elements in the list
130 */
131void clear_list(struct list *l);
132
133/*
134 * Delete every element in the list, and free the memory pointed by all the node data
135 */
136void destroy_list(struct list *l);
137
138#endif
GLintptr offset
Definition glcorearb.h:660
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
void * first_elem(struct list *l)
struct list_node * last_node(struct list *l)
int get_list_count(struct list *l)
void * locate_elem(struct list *l, void *elem)
struct list_node * locate_node(struct list *l, void *elem)
struct list_node * first_node(struct list *l)
void delete_node(struct list *l, struct list_node *node)
struct list_node * xlocate_node(struct list *l, void *elem, int offset, int length)
void * xlocate_elem(struct list *l, void *elem, int offset, int length)
void destroy_node(struct list *l, struct list_node *node)
void destroy_list(struct list *l)
void init_list(struct list *l, int keysize)
void * last_elem(struct list *l)
int is_empty_list(struct list *l)
void clear_list(struct list *l)
struct list_node * add_elem(struct list *l, void *elem)
struct list_node * previous
Definition list.h:35
struct list_node * next
Definition list.h:37
void * data
Definition list.h:33
Definition list.h:40
int count
Definition list.h:48
struct list_node * first
Definition list.h:42
int keysize
Definition list.h:46
struct list_node * last
Definition list.h:44