00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _GAN_LINKED_LIST_H
00030 #define _GAN_LINKED_LIST_H
00031
00032 #include <gandalf/common/misc_defs.h>
00033 #include <gandalf/common/allocate.h>
00034
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038
00052 typedef struct Gan_List_Node
00053 {
00054 void *p_data;
00055 struct Gan_List_Node *p_next;
00056 struct Gan_List_Node *p_prev;
00057 } Gan_List_Node;
00058
00059
00060
00064 typedef struct Gan_List
00065 {
00066
00067 Gan_List_Node *p_first;
00068 Gan_List_Node *p_current;
00069 Gan_List_Node *p_last;
00070 Gan_List_Node *p_stack_current;
00072 int node_count;
00073 int current_position;
00074 int current_position_stack;
00075 Gan_Bool is_straight;
00077
00078 Gan_Bool alloc;
00079 } Gan_List;
00080
00081
00082
00083 Gan_List* gan_list_new ( void );
00084 Gan_List* gan_list_form(Gan_List *List);
00085 Gan_List* gan_list_new_from_array( void **array, unsigned n );
00086 void gan_list_free ( Gan_List *List, Gan_FreeFunc free_func);
00087 Gan_Bool gan_list_insert_first ( Gan_List *List, void *data );
00088 Gan_Bool gan_list_insert_next ( Gan_List *List, void *data );
00089 Gan_Bool gan_list_insert_prev ( Gan_List *List, void *data );
00090 Gan_Bool gan_list_insert_last ( Gan_List *List, void *data );
00091 Gan_Bool gan_list_insert_at ( Gan_List *List, void *data, int pos );
00092 Gan_Bool gan_list_delete_first ( Gan_List *List, Gan_FreeFunc free_func );
00093 Gan_Bool gan_list_delete_next ( Gan_List *List, Gan_FreeFunc free_func );
00094 Gan_Bool gan_list_delete_current ( Gan_List *List, Gan_FreeFunc free_func );
00095 Gan_Bool gan_list_delete_prev ( Gan_List *List, Gan_FreeFunc free_func );
00096 Gan_Bool gan_list_delete_last ( Gan_List *List, Gan_FreeFunc free_func );
00097 Gan_Bool gan_list_delete_at( Gan_List *List, Gan_FreeFunc free_func,
00098 int pos );
00099 void gan_list_delete_all ( Gan_List *List, Gan_FreeFunc free_func );
00100 void gan_list_goto_head ( Gan_List *List);
00101 void gan_list_goto_tail ( Gan_List *List);
00102 Gan_Bool gan_list_goto_pos ( Gan_List *List, int pos );
00103 void *gan_list_set_prev ( Gan_List *List, void *new_data );
00104 void *gan_list_set_current (Gan_List *List, void *new_data);
00105 void *gan_list_set_next ( Gan_List *List, void *new_data );
00106 void gan_list_push_current ( Gan_List *List );
00107 void gan_list_pop_current ( Gan_List *List );
00108 int gan_list_get_pos ( Gan_List *List );
00109 int gan_list_get_size ( Gan_List *List );
00110 void gan_list_process_data( Gan_List *List,
00111 void (*process_func)(void *, void *), void *data );
00112 Gan_List* gan_list_concat( Gan_List *List1, Gan_List *List2 );
00113 void gan_list_reverse( Gan_List *List );
00114 int gan_list_to_array ( Gan_List *List, void ***array_ptr );
00115 Gan_List* gan_list_copy( Gan_List *List );
00116 Gan_List* gan_list_copy_with_data( Gan_List *list, Gan_CopyFunc copy_func );
00117 void gan_list_sort_asc ( Gan_List *List,
00118 int (*compare)(const void *, const void *) );
00119 void gan_list_make_straight ( Gan_List *List );
00120 void gan_list_make_circular ( Gan_List *List );
00121 Gan_Bool gan_list_is_circular ( Gan_List *List );
00122
00123 Gan_Bool gan_list_contains ( Gan_List *List, void *data );
00124
00125 #define TYPE int
00126
00139 TYPE *gan_list_get_prev ( Gan_List *list, TYPE node_type );
00140
00150 TYPE *gan_list_get_current ( Gan_List *list, TYPE node_type );
00151
00164 TYPE *gan_list_get_next ( Gan_List *list, TYPE node_type );
00165
00166 #undef TYPE
00167
00168
00169 void *gan_list_get_prev_node ( Gan_List *List );
00170 void *gan_list_get_next_node ( Gan_List *List );
00171 void *gan_list_get_current_node ( Gan_List *List );
00172
00181 #ifdef __cplusplus
00182 }
00183 #endif
00184
00185 #endif