]> git.donarmstrong.com Git - biopieces.git/blob - code_c/Maasha/src/inc/list.h
fixed rename bug
[biopieces.git] / code_c / Maasha / src / inc / list.h
1 /* Martin Asser Hansen (mail@maasha.dk) Copyright (C) 2008 - All right reserved */
2
3 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> STRUCTURE DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
4
5
6 /* Singly linked list node. */
7 struct _node_sl
8 {
9     struct _node_sl *next;   /* Pointer to next node - NULL if last. */
10     void            *val;    /* Pointer to data value. */
11 };
12
13 typedef struct _node_sl node_sl;
14
15 /* Singly linked list. */
16 struct _list_sl
17 {
18     node_sl *first;   /* Pointer to first node - NULL for empty list. */
19 };
20
21 typedef struct _list_sl list_sl;
22
23 /* Doubly linked list node. */
24 struct _node_dl
25 {
26     struct _node_dl *next;  /* Pointer to next node     - NULL if last. */
27     struct _node_dl *prev;  /* Pointer to previous node - NULL if last. */
28     void            *val;   /* Pointer to data value. */
29 };
30
31 typedef struct _node_dl node_dl;
32
33 /* Doubly linked list. */
34 struct _list_dl
35 {
36     node_dl *first;  /* Pointer to first node - NULL for empty list. */
37     node_dl *last;   /* Pointer to last node  - NULL for empty list. */
38 };
39
40 typedef struct _list_dl list_dl;
41
42
43 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCTION DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
44
45
46 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SINGLY LINLED LIST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
47
48
49 /* Initialize a new singly linked list. */
50 list_sl *list_sl_new();
51
52 /* Initialize a new singly linked list node. */
53 node_sl *node_sl_new();
54
55 /* Add a new node to the beginning of a singly linked list. */
56 void     list_sl_add_beg( list_sl **list_ppt, node_sl **node_ppt );
57
58 /* Add a new node after a given node of a singly linked list. */
59 void     list_sl_add_after( node_sl **node_ppt, node_sl **new_node_ppt );
60
61 /* Remove the first node of a singly linked list. */
62 void     list_sl_remove_beg( list_sl **list_ppt );
63
64 /* Remove the node next to this one in a singly linked list. */
65 void     list_sl_remove_after( node_sl **node_ppt );
66
67 /* Debug function to print all elements from a singly linked list. */
68 void     list_sl_print( list_sl *list_pt );
69
70 /* Debug funtion to print a singly linked list node. */
71 void     node_sl_print( node_sl *node_pt );
72
73 /* Sort a singly linked list according to the compare function. */
74 void     list_sl_sort( list_sl **list_ppt, int ( *compare )( const void *a, const void *b ) );
75
76 /* Free memory for all nodes in and including the singly linked list. */
77 void     list_sl_destroy( list_sl **list_ppt );
78
79 /* Free memory for singly linked list node and value. */
80 void     node_sl_destroy( node_sl **node_ppt );
81
82
83 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DOUBLY LINKED LIST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
84
85
86 /* Initialize a new doubly linked list. */
87 list_dl *list_dl_new();
88
89 /* Initialize a new doubly linked list node. */
90 node_dl *node_dl_new();
91
92 /* Add a new node to the beginning of a doubly linked list. */
93 void     list_dl_add_beg( list_dl **list_ppt, node_dl **node_ppt );
94
95 /* Add a new node to the end of a doubly linked list. */
96 void     list_dl_add_end( list_dl **list_ppt, node_dl **node_ppt );
97
98 /* Add a new node before a given node of a doubly linked list. */
99 void     list_dl_add_before( list_dl **list_ppt, node_dl **node_ppt, node_dl **new_node_ppt );
100
101 /* Add a new node after a given node of a doubly linked list. */
102 void     list_dl_add_after( list_dl **list_ppt, node_dl **node_ppt, node_dl **new_node_ppt );
103
104 /* Remove a node from a doubly linked list. */
105 void     list_dl_remove( list_dl **list_ppt, node_dl **node_ppt );
106
107 /* Debug function to print all elements from a doubly linked list. */
108 void     list_dl_print( list_dl *list_pt );
109
110 /* Debug funtion to print a doubly linked list node. */
111 void     node_dl_print( node_dl *node_pt );
112
113 /* Free memory for all nodes in and including the doubly linked list. */
114 void     list_dl_destroy( list_dl **list_ppt );
115
116 /* Free memory for doubly linked list node and value. */
117 void     node_dl_destroy( node_dl **node_ppt );
118
119 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GENERIC LINKED LIST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
120
121
122 /* Returns the number of nodes in a linked list. */
123 size_t list_count( void *list_pt );
124
125
126 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ASSORTED SORTING FUNCTIOS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
127
128
129 /* Sort in ascending order according to char node values. */
130 int cmp_list_sl_char_asc( const void *a, const void *b );
131
132 /* Sort in descending order according to char node values. */
133 int cmp_list_sl_char_desc( const void *a, const void *b );
134
135
136 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
137
138