]> hackdaworld.org Git - my-code/api.git/commitdiff
added fast(er) list to be included (just in header) + small bug fix master origin
authorhackbard <hackbard>
Fri, 15 Dec 2006 01:16:37 +0000 (01:16 +0000)
committerhackbard <hackbard>
Fri, 15 Dec 2006 01:16:37 +0000 (01:16 +0000)
list/list.c
list/list.h

index 79d53f7a5f0088a8a4ef8abdf240ac4095ccda21..79b41d2ff9cf4288c03c6e6feb48b04f62a8bde2 100644 (file)
@@ -28,7 +28,8 @@ int list_shutdown(t_list *list) {
 
 int list_next(t_list *list) {
 
 
 int list_next(t_list *list) {
 
-  if(list->current->next==NULL) return L_NO_NEXT_ELEMENT;
+  if(list->current->next==NULL)
+       return L_NO_NEXT_ELEMENT;
 
   list->current=list->current->next;
 
 
   list->current=list->current->next;
 
@@ -75,6 +76,7 @@ int list_destroy(t_list *list) {
   list_reset(list);
 
   while(list->current!=NULL) list_del_element(list,list->current);
   list_reset(list);
 
   while(list->current!=NULL) list_del_element(list,list->current);
+  list->start=NULL;
 
   return L_SUCCESS;
 }
 
   return L_SUCCESS;
 }
index 4302d3222883af299038e10dc9943613e6703b1c..8f5328a4f04ef45bf85a08f9ce9f5e930c7ae76e 100644 (file)
@@ -44,4 +44,84 @@ int list_add_immediate(t_list *list,void *data,int data_len);
 int list_add_element(t_list *list,void *data,int data_len);
 int list_count(t_list *list);
 
 int list_add_element(t_list *list,void *data,int data_len);
 int list_count(t_list *list);
 
+/*
+ * fast linked list routines to be inlined
+ */
+
+/* prototypes */
+
+static inline int list_init_f(t_list *list) __attribute__((always_inline));
+static inline int list_reset_f(t_list *list) __attribute__((always_inline));
+static inline int list_destroy_f(t_list *list) __attribute__((always_inline));
+static inline int list_add_immediate_f(t_list *list,void *ptr) __attribute__((always_inline));
+static inline int list_next_f(t_list *list) __attribute__((always_inline));
+
+/* definitions */
+
+static inline int list_init_f(t_list *list) {
+
+       list->start=NULL;
+       list->current=list->start;
+
+       return L_SUCCESS;
+}
+
+static inline int list_reset_f(t_list *list) {
+
+       list->current=list->start;
+
+       return L_SUCCESS;
+}
+
+static inline int list_destroy_f(t_list *list) {
+
+       t_list_element *this;
+
+       /* destroying the list from the very beginning */
+       list->current=list->start;
+
+       while(list->current!=NULL) {
+               this=list->current;
+               list->current=this->next;
+               free(this);
+       }
+
+       list->start=NULL;
+
+       return L_SUCCESS;
+}
+
+static inline int list_add_immediate_f(t_list *list,void *ptr) {
+
+       /* first element? */
+       if(list->start==NULL) {
+               list->start=malloc(sizeof(t_list_element));
+               list->start->data=ptr;
+               list->start->next=NULL;
+               list->start->prev=NULL;
+               list->current=list->start;
+               
+               return L_SUCCESS;
+       }
+
+       list->current->next=malloc(sizeof(t_list_element));
+       list->current->next->prev=list->current;
+       list->current->next->next=NULL;
+       list->current->next->data=ptr;
+       list->current=list->current->next;
+
+       return L_SUCCESS;
+}
+
+static inline int list_next_f(t_list *list) {
+
+       if(list->current->next==NULL)
+               return L_NO_NEXT_ELEMENT;
+
+       list->current=list->current->next;
+
+       return L_SUCCESS;
+}
+
+
 #endif
 #endif