Generic linked list by using sys queue.h - Geono/generic-linked-List-in-c GitHub Wiki

A generic linked list using "sys/queue.h" macros. We often use the macro of sys/queue.h, but it is not convenient to be used as itself. There are some useful macros implemented here:

Generic singly linked list macro functions using sys/queue.h

LIST_DEL ( listelm, elem, field )

- delete an element of the list         
    @ listelm           :  list
    @ elem              :  a target element to be deleted
    @ field             :  the name of the list entry

LIST_CLEAR ( listelm, entry_type, field )

- clear out the whole list elements
    @ listelm           :  list
    @ entry_type        :  the type of the entry structure
    @ field             :  the name of the list entry

LIST_SORT ( listelm, entry_type, field, cmp_func )

- list heap sort by 'data_name'
    @ listelm           :  list
    @ entry_type        :  the type of the entry structure
    @ field             :  the name of the list entry
    @ cmp_func          :  the name of the compare function to be used in sort
                        :       
                        :  int cmp_func( entry_type *a, entry_type *b )
                        :  The comparison function must return a negative value if
                        :  @a should sort before @b, and a positive value if @a should sort
                        :  after @b. If @a and @b are equivalent, and their original
                        :  relative ordering is to be preserved, @cmp_func must return 0.

LIST_EXISTS( listelm, entry_type, field, data_name, search_for, result_entry )

- find the list element with a certain data and put the element to 'result_entry'
    @ listelm           :  list
    @ entry_type        :  the type of the entry structure
    @ field             :  the name of the list entry
    @ data_name         :  the name of the data entry
    @ search_for        :  the data which is expected to be found
    @ result_entry      :  &entry structure to use as a result

LIST_PRINT ( listelm, entry_type, field, print_func )

- find the list element with a certain data and put the element to 'result_entry'
    @ listelm           :  list
    @ entry_type        :  the type of the entry structure
    @ field             :  the name of the list entry
    @ print_func        :  the name of the print function to be used 
                        :       
                        :  void print_func( entry_type *a )
                        :  The print function should print the notable element in the list entry.